Floating point precision lost: NEED HELP!
-
I've got HUGE problems with floating point precision lost in the following code: - s*(a.y-c.y) - h*(b.y-c.y) where s = h = 0.333.... c.y = 0.675 a.y = b.y = 0 The result is about 5.e-17 (as I understand, NAN). How to overcome the problem, forex find out that precision lost occured. Thank you for help, A. M. gp123456
-
I've got HUGE problems with floating point precision lost in the following code: - s*(a.y-c.y) - h*(b.y-c.y) where s = h = 0.333.... c.y = 0.675 a.y = b.y = 0 The result is about 5.e-17 (as I understand, NAN). How to overcome the problem, forex find out that precision lost occured. Thank you for help, A. M. gp123456
-
:confused: toxcct wrote: try a.y = b.y = 0.0; Of cource, a.y & b.y are doubles too! So read a.y = 0.0, b.y = 0.0 Suppose you haven't understood my question: precision lost is a result of existing in my program double values with infinite part after floating point, e.g. that s = 0.3333... (infinite 3's after floating point) & h = 0.3333... (infinite 3's after floating point).
-
:confused: toxcct wrote: try a.y = b.y = 0.0; Of cource, a.y & b.y are doubles too! So read a.y = 0.0, b.y = 0.0 Suppose you haven't understood my question: precision lost is a result of existing in my program double values with infinite part after floating point, e.g. that s = 0.3333... (infinite 3's after floating point) & h = 0.3333... (infinite 3's after floating point).
-
I've got HUGE problems with floating point precision lost in the following code: - s*(a.y-c.y) - h*(b.y-c.y) where s = h = 0.333.... c.y = 0.675 a.y = b.y = 0 The result is about 5.e-17 (as I understand, NAN). How to overcome the problem, forex find out that precision lost occured. Thank you for help, A. M. gp123456
Loss of precision is an inherent problem with floating-point numbers (
float
anddouble
). You should never test for equality between twofloat
s/double
s because of this, but instead test that the difference is less than some threshhold. To get around this, you'll need to use some alternate means of manipulating floating-point numbers. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!" -- Rico Mariani, CLR perf guy -
I've got HUGE problems with floating point precision lost in the following code: - s*(a.y-c.y) - h*(b.y-c.y) where s = h = 0.333.... c.y = 0.675 a.y = b.y = 0 The result is about 5.e-17 (as I understand, NAN). How to overcome the problem, forex find out that precision lost occured. Thank you for help, A. M. gp123456
It would be wise to compare the result from above formula with result from -s*ay - h*by + cy*(s+h) and if results dont compare have some kind of error recovery. if calculations are not too many and time bound most wise programmers(not me) calculate with 2 formulae and compare results.
-
I've got HUGE problems with floating point precision lost in the following code: - s*(a.y-c.y) - h*(b.y-c.y) where s = h = 0.333.... c.y = 0.675 a.y = b.y = 0 The result is about 5.e-17 (as I understand, NAN). How to overcome the problem, forex find out that precision lost occured. Thank you for help, A. M. gp123456
Mike is correct. However, there is something more going on. Are you sure that "s == h"? Even with floating point imprecision, I don't see how the two parts of the expression won't cancel each other out. I tried this with initializing h and s to 1.0/3.0 and it worked properly. However, generally speaking, checking for "== 0" with floating point numbers is a VERY bad idea. Usually you need to check if "- epsilon < x < epsilon" where epsilon is your tolerance for imprecision. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
Mike is correct. However, there is something more going on. Are you sure that "s == h"? Even with floating point imprecision, I don't see how the two parts of the expression won't cancel each other out. I tried this with initializing h and s to 1.0/3.0 and it worked properly. However, generally speaking, checking for "== 0" with floating point numbers is a VERY bad idea. Usually you need to check if "- epsilon < x < epsilon" where epsilon is your tolerance for imprecision. Tim Smith I'm going to patent thought. I have yet to see any prior art.
You know, I'm not checking if h==s, I just execute the code. I found out that h==s using debugger. I'm interested in way to find out that precision lost occured in MS VisualC++ 7.0.
-
Loss of precision is an inherent problem with floating-point numbers (
float
anddouble
). You should never test for equality between twofloat
s/double
s because of this, but instead test that the difference is less than some threshhold. To get around this, you'll need to use some alternate means of manipulating floating-point numbers. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!" -- Rico Mariani, CLR perf guyMichael Dunn wrote: you'll need to use some alternate means of manipulating floating-point numbers. You right! But I'd like to know which one exactly. Some useful links are welcomed.
-
I've got HUGE problems with floating point precision lost in the following code: - s*(a.y-c.y) - h*(b.y-c.y) where s = h = 0.333.... c.y = 0.675 a.y = b.y = 0 The result is about 5.e-17 (as I understand, NAN). How to overcome the problem, forex find out that precision lost occured. Thank you for help, A. M. gp123456
Follow the link below, you will know why there is loss in precision: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/\_core\_why\_floating\_point\_numbers\_may\_lose\_precision.asp To solve the problem, there is a free library called MAPM which can help you to calculate precisly: http://www.tc.umn.edu/~ringx004/mapm-main.html Hope that it can help.
-
Follow the link below, you will know why there is loss in precision: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/\_core\_why\_floating\_point\_numbers\_may\_lose\_precision.asp To solve the problem, there is a free library called MAPM which can help you to calculate precisly: http://www.tc.umn.edu/~ringx004/mapm-main.html Hope that it can help.
The problem solved itself! I've changed computer (from Celeron 800 MHz to Celeron 2GHz), and the equation doesn't affects the results! Anybody knows the reason? I heard something about bugs in FPU of P300-1000... Anyway, thank you very much for links, Hing. They are very useful for me.