[NetBehaviour] The trouble with rounding floating point numbers.
rob at robmyers.org
rob at robmyers.org
Tue Aug 15 14:35:35 CEST 2006
Quoting marc <marc.garrett at furtherfield.org>:
> That's right, one of the most basic operations in math, a thing that
> we learn to do before we can ride a bike, eludes the combined efforts
> of the finest engineers over the last 30 years. Of course, this is
> something that is intuitively nonsensical - why should it be
> impossible to round a floating-point number reliably?
Real mathematics programmers use bignums. ;-)
http://en.wikipedia.org/wiki/Bignum
I remember the first time I saw a floating point rounding error. A
student I was
teaching was rotating a vector shape on the screen by multiplying the
angle by a
fraction in a loop. The numbers were stored as C floats. As the shape
rotated it
started to drift off-centre. I had difficulty believing that floats were the
problem given the low ranges being used, but after asking the maths lecturer's
advice we switched the code from using floats to using doubles. The shape then
rotated without drifting.
- Rob.
More information about the NetBehaviour
mailing list