forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Comparing real quantities for 'equality'

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
eric_carwardine



Joined: 13 Jun 2009
Posts: 63
Location: Perth, Western Australia

PostPosted: Fri Apr 17, 2015 2:04 am    Post subject: Comparing real quantities for 'equality' Reply with quote

G'day, folks Very Happy

The compiler tells me I'm using an unreliable method of comparing two real quantities for equality.

I believe there is a 'safe' method of comparison, based on the inequality:
Code:

(1.0 - d) .lt. 1.0


Which suggests a supplementary question of getting the machine constant 'd'

Eric
Back to top
View user's profile Send private message Send e-mail Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2135
Location: Sydney

PostPosted: Fri Apr 17, 2015 3:28 am    Post subject: Reply with quote

Eric,

You should not get a warning with .lt.
You would if you wrote "if ( d .eq. 1.0 )", where the more "robust" method is to write: if ( abs(d-1.0) < error ).

For an estimate of error, there are a few considerations:
1) the intrinsic epsilon() gives an indication of the smallest possible value for error, although
2) you want to choose a larger value if near enough is close enough.
3) note that error varies with value, so something like:
if ( abs(d-x) < epsilon()*x*safety_factor ) would be an estimate of error
or error = max ( epsilon()*x*safety_factor, 1.e-10 )

Often it is easier to just use " if ( d .eq. 1.0 ) " and ignore the error, although if there is any round-off error in calculating d, the test could fail.

John
Back to top
View user's profile Send private message
eric_carwardine



Joined: 13 Jun 2009
Posts: 63
Location: Perth, Western Australia

PostPosted: Fri Apr 17, 2015 4:11 am    Post subject: Re: Reply with quote

JohnCampbell wrote:
Eric,

You should not get a warning with .lt.


Many thanks, John. That certainly is useful.

My mistake; it wasn't .lt. after all. The warning was actually generated from:

Code:

   0690         if( amod(uv,si) .eq. 0.0 ) return
   0691   C
WARNING - Comparing floating point quantities for equality may give misleading results


Eric
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group