Price fraction: Difference between revisions

compiler bug
(compiler bug)
Line 2,163:
function price_fix(atom p)
for i=1 to length(limits) do
-- if p<limits[i] then -- see note below
if p-limits[i]<-0.005 then
return prices[i]
end if
Line 2,174 ⟶ 2,173:
printf(1, "%5.2f %5.2f\n", {i/100,price_fix(i/100)})
end for</lang>
Comparing standard IEEE floats is always dodgy. I suspect that several other examples on this page exhibit the same bug that this change fixed.
In my case I was getting three bugs (0.21->0.32, 0.41->0.54, 0.86->0.90), but it probably depends on how floats are parsed and then stored.
 
The output, with most lines manually removed, is:
<pre>
-0.01 -1.00
0.00 0.10
0.01 0.10
0.05 0.10
0.06 0.18
0.10 0.18
0.11 0.26
0.20 0.32
0.21 0.38
0.41 0.58
0.86 0.94
0.95 0.98
0.96 1.00
1.00 1.00
1.01 -1.00
</pre>
 
=={{header|PicoLisp}}==
7,820

edits