Re: g++/gcc : Floating point issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, friend, I wish I knew how to solve your problem.  Sadly, I doubt
that it's solvable.  From what I've read, it seems that floating point
numbers are seldom exact.  One book, Michael Covington's "Prolog in
Depth," I think, I read that since floating point numbers are often not
equal to each other, it's a good idea not to test them for equality.  It
seems better to test them using >=, <=, or !=.

Some author, perhaps Covington. wrote that some Prolog programs consider
two floating point numbers equal when the difference between them is
less than some tolerance.

I suspect your problem arises because word lengths limit the the
precision of floating point numbers that a computer can represent. 
There are other problems, too, I'm sure.

I've heard of some programming languages that allow floating point
numbers that can have almost unlimited precision because those languages
represent floating point numbers as lists of integers or as integers in
binary coded decimal form.  Hope this helps.

Bill
Abuzer Salik writes:

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.
 
"Pro-choice?"  Then click here.
http://cathinsight.com/morality/saying.htm

"Men must look for the peace of Christ in the Kingdom of Christ... When
once men recognize, both in private and in public life, that Christ is
King, society will at last receive the great blessings of real liberty,
well-ordered discipline, peace and harmony."  Pope Pius XI

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux