From: Mark Rages <markrages@gm...>  20060714 01:03:50

I posted a bug about this, but I want to bring it up here for other SDCC users to know about. The floating point routine in fsmul.c does not handle denormalized numbers well. I discovered this by doing: float f=1.0; while (1) { f*=0.25; } I expected f to decay to zero, but instead it wrapped around to a huge number! From looking at the source (device/lib/pic16/libsdcc/float/fsmul.c, but similar code for other architectures) I see there is no attemp at bounds checking when the exponents are being added together. So multiplying two numbers with very negative exponents can wrap to a very large positive exponent. It is also possible to get an infinite result, since the IEEE standard dedicates an exponent value to this. I found the source code's ancestor in GCC (3.3 or earlier). This code has the same problem in the multiply routine. Most GCC platforms have hardware floatingpoint support, so the code isn't used. In my code, I can work around this: #define SMALL_NUMBER 0.000001 float f=1.0; while (1) { if (f<SMALL_NUMBER) f=0.0; // see http://thedailywtf.com/forums/71684/showpost.aspx else f*=0.25; } I post this as a warning to others: Beware the floating point routines when you have numbers that may be close to zero! Regards, Mark markrages@...  You think that it is a secret, but it never has been one.  fortune cookie 