----- Original Message ----- From: "Bruce Partridge" To: "Microcontroller discussion list - Public." Sent: Thursday, November 04, 2004 9:02 AM Subject: RE: [PIC]fwd: Floating Point Underflows and Overflows > The application doesn't nornally deal with this kind of dynamic range. I > will never have any numbers that have exponents outside the range of +4 > to -7. Anything above +4 is an error, and anything below -7 is just zero. > > But the +35 value occurs very occasionally. Its a decay equation, so the > results stay around for a day or so. In searching for possible reasons, I > discovered that I could produce the result with that particular > multiplication. There are probably others. > > So my next question is whether I am actually creating those numbers. The > only way that I can imagine them being created is if I am doing > calculations > on values that would just be zero in integer calculation. > > For example 7.520001 - 7.520000 could easily appear in my calculations. > Maybe doing the subraction on the internal values produces very small > numbers. But I'm just guessing on this part. Yes, this is a common problem with using floating point. You lose precision very quickly when subtracting to numbers that are very close to one another. Perhaps all you need is something like this: diff = a - b; if ( diff < 1E-10 ) diff = 0; (note that the same thing can happen when adding number of similar absolute value and opposite signs) Bob Ammerman RAm Systems _______________________________________________ http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist