` Comment on an Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Add a comment to an Icetips Article

Please add your comments to this article. Please note that you must provide both a name and a valid email address in order for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!

Your Name:  
Email:  
Header text/Subject:  

Please enter your comment in the box below:

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Par2: Comparing REALs
2002-04-24 -- Randy Goodhew
 
What I use for REAL comparisons: Returns: -1 = a is less than b 1 = a is greater than b 0 = a is equal to b ! RealCompare(REAL a,REAL b,REAL order=0.0001),LONG RealCompare PROCEDURE(REAL a,REAL b,REAL order) e:LessThan EQUATE(-1) e:Equal EQUATE(0) e:GreaterThan EQUATE(1) Result LONG,AUTO CODE a = ROUND(a,order) b = ROUND(b,order) IF a < b ; Result = e:LessThan ELSIF a > b ; Result = e:GreaterThan ELSIF a = b ; Result = e:Equal END ! if RETURN Result John Davidson notes: The "scientific" way of cpmparing reals is to check whether they differ by less than a small value: ie IF ABS( A - B ) > 0.0001 THEN ! they are unequal ELSE ! they are equal The small value is chosen to be significantly smaller than the typical values being compared. Richard Taylor adds: If you're going to ROUND anyway, why not just change to DECIMAL instead and eliminate all the problems. That way the rounding is automatic, math is done as BCD, and equivalence comaprisons work correctly.


Today is November 21, 2024, 6:47 am
This article has been viewed 35212 times.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: