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 floating-point 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
[EMAIL PROTECTED]
--
You think that it is a secret, but it never has been one.
- fortune cookie
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user