Click to See Complete Forum and Search --> : fpu problem


crou
May 30th, 2002, 03:35 AM
To my mind, the problem is that the fpu works in binary

In the most cases, there are problems of accuracy with float. It occurs when the number can't be represented by a sum of 1/(2^n)

Some float numbers can be exactly represented such as 0.5 (1/2^2) or 0.3125 (1/2^3 + 1/2^5) for instance.

That is not the case with 0.1, and the number will be between two possibles representations
Unfortunately, the fpu have never been able to choose the closer value : they always whoose the upper value. That's why you have a 1 at the end of your 0.1000000000000000000000001

It is shocking because with integer numbers, the problem does not exists, but everybody knows that the computer are bad calculators.

Hope this help

crou
May 30th, 2002, 04:17 AM
oops!

this issue was suppose to be a reply. If anybody knows how i can remove it, tell me!

Plastelin
May 30th, 2002, 05:04 AM
Really, this is not a FPU problem, it just C++ klolage problem.
when you work with float never compare 2 floats like 'a == b' use ABS(a-b)< MIN_FLOAT. Never compare float with Zero compare with MIN_FLOAT like: ABS(a) < MIN_FLOAT

#define MIN_FLOAT 0.000001