|
About ::
TODO ::
Blog ::
RSS ::
Old blog ::
Projects ::
GIT ::
Gallery ::
Notes
Sun, 20 May 2007
First Bezier curve. /devel/math/bezier :: Link / Comments (0) #includeResult: 0.000000 0.100000 0.200000 0.300000 0.400000 0.500000 0.600000 0.700000 0.800000 0.900000But if step is 0.2 everything is correct and I can reach 1.0: 0.000000 0.200000 0.400000 0.600000 0.800000 1.000000Using this loop:
for (u=0.0; u <= 1.0;) {
u += 0.1;
printf("%f <= %f : %d\n", u, 1.0, u<=1.0);
}
I got following output:0.100000 <= 1.000000 : 1 0.200000 <= 1.000000 : 1 0.300000 <= 1.000000 : 1 0.400000 <= 1.000000 : 1 0.500000 <= 1.000000 : 1 0.600000 <= 1.000000 : 1 0.700000 <= 1.000000 : 1 0.800000 <= 1.000000 : 1 0.900000 <= 1.000000 : 1 1.000000 <= 1.000000 : 0Result is always the same on different compilers (3.2.3, 3.3.2, 4.1.1, 4.1.2) and different arches (x86, x86_64, ppc32), so I expect it is not a bug, but a feature... Further analysis shown, that using -Wfloat-equal, which is not in -W -Wall
warning sets, compiler prints a warning for u == 1.0 comparison, but not for the example above.I'm stumbled quite a bit... More fun if I use smaller step like 0.0001, above loop resulted in following output:
...
0.063200 <= 1.000000 : 1
0.063300 <= 1.000000 : 1
0.063400 <= 1.000000 : 1
0.063501 <= 1.000000 : 1
^
Floating point math is very strange even for things which are supposed to be simple.Above computations should be corect, since sum does not produce neither overflow, nor uncertain result, but nevertheless some error appeared. /devel/other :: Link / Comments (0) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||