Re: Converting decimal number to carpenter's fractions

new topic     » goto parent     » topic index » view thread      » older message » newer message
K_D_R said...

But as far as exactness and accuracy... 1/3 may be an exact expression, but that exactness gives an illusion of accuracy and does not appear to me to be more accurate than a rounded decimal, at least for the purpose at hand:

The effects of this can be more easily seen when we scale up the calculations.

atom a 
 
a = 0 
for i = 1 to 300 do 
	a += 2/3 
end for 
 
printf(1, "%15.15f\n", a) --> 199.999999999999318 
? a = 200 --> 0 
 
a = ((2 / 3) * 300) 
printf(1, "%15.15f\n", a) --> 200.000000000000000 
? a = 200 --> 1 
 
a = 0 
for i = 1 to 300 do 
	a += 0.666666666666667 
end for 
 
printf(1, "%15.15f\n", a) --> 199.999999999999346 
? a = 200 --> 0 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu