Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Floating point number comparison

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edward Ulle - 22 Mar 2006 23:43 GMT
I know this is the subject of many prior threads, but, I'm having
trouble comparing floatinp point numbers.  Values in registers and
values in memory are not exactly equal, even though they were calculated
identically.

I was wondering if there is a library of functions to compare floating
point numbers, equal, less than, greater than, positive numbers and
negative numbers.

So far I only have one that I have confidence in.

x=y is  Abs(x-y)<EPSILON.

Any leads would be appreciated.
Bernard Liengme - 22 Mar 2006 23:51 GMT
One should never compare two real numbers (aka floating point) for EXACT
equality.
Your approach =ABS(x-y)<=EPSILON is the way to go.
best wishes
Signature

Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

>I know this is the subject of many prior threads, but, I'm having
> trouble comparing floatinp point numbers.  Values in registers and
[quoted text clipped - 12 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Edward Ulle - 23 Mar 2006 15:53 GMT
Yes, but what about other operations <>, <, >, <= and >=?  Has anyone
developed efficient routines to do this?  Any floating point number can
be x +/- EPSILON.
Bernard Liengme - 25 Mar 2006 16:34 GMT
Not sure what you mean.
Case 1, I want to know if x=y
=IF(ABS(x-y)<=1E-6, "equal", "unequal")
Of course, by "equal" I mean that x is within y +- epsilon, and "unequal"
means  x is at least epsilon larger/smaller than y

Case 2 I want to know if x is 10 units larger than y
Without worrying about IEEE precision =IF(x-y>=10, "true", "false")
Would I  have need to worry about IEEE here?
Suppose x=20 and y = 10.000000000009
Would I want the test to pas or fail?
If I think this should pass: =IF(ROUND(x-y,5)>=10, "true", "false")
I have decided that any difference that round to 10 at 5 place precision is
OK.

Any help?
Signature

Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

> Yes, but what about other operations <>, <, >, <= and >=?  Has anyone
> developed efficient routines to do this?  Any floating point number can
> be x +/- EPSILON.
>
> *** Sent via Developersdex http://www.developersdex.com ***
Edward Ulle - 27 Mar 2006 16:13 GMT
Basically what I mean is are there any efficient replacements for =, <>,
<, >, <= and >= for floating point number comparison that take into
account EPSILON.

I have developed 6 functions FPEqual, FPNotEqual, etc. that do this but
they may not be the most efficient.

FYI, the macro I've developed is used for an engineering application in
which floating point numbers are the norm and there are thousands of
floating point number comparison performed.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.