This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: g++/gcc : Floating point issue


This is not a GCC issue.

The 'double' type has a finite precision. Your number is almost certainly
being approximated to the nearest representable value.

The only ways to deal with this are to:
(1) arrange your calculations so that finite precision is not an issue, or
(2) use a different data format.

If you're interested in option (2), GMP might meet your needs:

http://www.swox.com/gmp/

Neil.

abuzer.salik@tcs.com wrote:
Hi,

I have an application which uses double values a lot. If I try to put say
401.74 in a double variable it is getting stored as 401.74000000000001
which creates problem in the calculations down the line. ( I am checking
these values using gdb debugger).

So, I am wondering if there is a way by which I can store the correct
values (i.e. 401.74) in the double.

We are using g++ compiler on Linux box.

Do we need to look for another compiler/hardware or current setup can
handle this?

Any suggestion/solution is highly appreciated.

Regards,
Abuzer Salik


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]