Different printed output with floating point numbers

From: Bob Carragher (bobthedancer_at_yahoo.com)
Date: Wed Mar 07 2001 - 08:22:36 GMT


I've recently noticed an interesting behavior with UPS (version
3.35) regarding the printing of floats in the display area.  Try
compiling the following piece of code (I used gcc version 2.95.2,
compiled on a pentium running Redhat Linux 2.2.14-5.0):

     int main() {
         float foo = 1.3;
         foo = foo;

Put a breakpoint somewhere in the code and start the debugger
(by clicking "Start").  Now click on "foo" to put that variable
into the display area.  Click on "main" in the display area,
and click the "Add expr" button.  Type "foo" and hit return.
You should see something like the following in the display area:

           float <foo>                1.3
           foo                        1.29999995232

This will happen under either gcc or g++ compilation.

Can someone explain to me why this should be?  It makes debugging
code containing floating point numbers a little tricky.



This archive was generated by hypermail 2.1.4 : Wed Feb 13 2002 - 21:51:33 GMT