[Gambas-user] Possible bug in round() function

Tobias Boege taboege at ...626...
Thu Jan 30 15:33:00 CET 2014


On Thu, 30 Jan 2014, Bruce wrote:
> On Thu, 2014-01-30 at 10:33 +0000, Ricardo D??az Mart??n wrote:
> > ? round (283.5 * 0.21, -2)
> 
> very interesting. The miracles we call floats.
> try
> ? round (283.4999999999999999999996 * 0.209999999999999999996, -2)
> 59.54
> 
> Strange and magical, we'd better wait on Benoit's call on this one.
> 
> ?
> Bruce 

I wouldn't say magical. Disillusioning maybe :-)

0.21 is not exactly representable with a finite number of bits. That's
why you should expect errors when computing with it. When you multiply,
the absolute error can get relatively large, obviously.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list