Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Floating point number comparison

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.



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Floating point number comparison

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
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Edward Ulle" wrote in message
...
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.



*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Floating point number comparison

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 ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Floating point number comparison

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?
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Edward Ulle" wrote in message
...
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 ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Floating point number comparison

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.



*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unacceptable floating point errors Jeff in GA Excel Discussion (Misc queries) 32 September 25th 09 11:26 AM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Excel Discussion (Misc queries) 3 March 18th 06 06:20 PM
Floating point problem?? Frederick Chow Excel Programming 6 January 3rd 06 03:39 AM
setting a floating decimel point Rose New Users to Excel 2 April 29th 05 06:10 PM
Floating Point Functions Joel Excel Programming 6 March 30th 05 10:29 PM


All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"