1 msgSuggestion required for appropriate implementation
11 msgAn article I alluded to
3 msgStrange floating point problems on SH4 with gcc...

g++/gcc : Floating point issue
\ abuzer.salik (26 Jul 2006)
. \ Daniel Llorens del Río (26 Jul 2006)
. \ Neil Ferguson (26 Jul 2006)
. \ Bill McEnaney (26 Jul 2006)
. \ miridian (28 Jul 2006)

1 msgCreating a Windows dll in Linux?
2 msgoutput to a directory which doesn't exit yet
1 msgGCC 3.4.4 compilation error for arm-linux target
1 msgproblems with precompiled header - vector and a...
1 msgbuiltin bounds checking how-to
1 msghelp installing gcc 4.0.3
2 msghelp spawning/executing a command line utility
1 msggcc symbols
3 msgstatic variables, the stack, the heap, and speed
1 msgg++ -- can unused constructors affect generated...
2 msgsending structure containing a pointer to anoth...
4 msgARM Assembler
9 msgCygWin - GCC compiler error
1 msgGCC: Linking problem
1 msgFully qualified lib name.
2 msggcc -print-search-dirs
Subject:Re: g++/gcc : Floating point issue
Group:Gcc-help
From:miridian
Date:28 Jul 2006


abuzer.salik wrote:

> 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.

No.

Only dyadic rationals (a rational number of the form a/(2^b) where a is
an integer and b is a natural number) have a finite binary expansion.

40174/100 = 200087/50 (and 50 is not 2^b for a natural number b)

See the links:
http://en.wikipedia.org/wiki/Binary_numeral_system#Representing_real_numbers
http://en.wikipedia.org/wiki/Dyadic_fraction


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

You can use an arbitrary precision numeric library, for ex. GMP
http://www.swox.com/gmp/

Regars,
Luca.




© 2004-2008 readlist.com