|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sun May 06, 2007 12:09 pm Post subject: warning about tests for floating point equality |
|
|
I find the warnings and comments issued by FTN95 very informative and helpful, with one exception, and that is the message about comparing floating point quantities for equality (and, of course, the complementary message about inequality). Is there any way of turning this (these?) messages off selectively? I get a string of warnings against all of my IFs, and this obscures the more relevant and helpful warnings.
I usually check the denominator of any division for being zero before I do it, especially as this usually means that there is some bad data, which I can trap and deal with.
Not only that, but if, for example, I set both A and B to zero, then I expect that a test of either against zero should be .TRUE. or their difference to be zero, or the result of multiplying anything by A or B to be zero (perhaps I would accept the latter to be less reliable, although I don’t know why I would need to be less confident about this). So, for example, if I had:
A=0.0 (and this could come from a pair of READ statements)
B=0.0
IF (A .EQ. B) THEN or
IF (A .EQ. 0.0) THEN
… both IFs would be .TRUE.
Indeed, if I had written
A=0.1234
B=0.1234
I should expect
A .EQ. B to be .TRUE. and also A .EQ. 0.1234 to be .TRUE. – although admittedly, I should not expect that if I wrote:
C=0.2468/2.0
… then would A .EQ. C ? I should be prepared for this not to be assured because of the representation of numbers in the PC. Similarly, if I had READ the value for A, and specified the value for B, I might be prepared for some difference.
It did occur to me to write two LOGICAL FUNCTIONs, named EXACTLY_EQUAL (A, B) and APPROX_EQUAL (A, B, TOLERANCE), although I then need to add a declaration of type for EXACTLY_EQUAL and APPROX_EQUAL in the routines that call them. Both are a few lines long, and in the course of writing them, I did find that an arithmetic IF does not generate the annoying warning! Similarly, if I convolute the process and write:
IF (A .LT. B .OR. A .GT. B) THEN
EXACTLY_EQUAL = .FALSE.
ELSE
EXACTLY_EQUAL = .TRUE.
ENDIF
Then I don’t get the warning.
Can anyone help me to give these symbolic names a global scope - or even to produce a new operator – some of the finer points of Fortran-90 and Fortran-95 seem to have passed me by!
Eddie |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Sun May 06, 2007 3:10 pm Post subject: |
|
|
You can use /IGNORE <n> where <n> is the warning number that you get by using /ERROR_NUMBERS.
You will find a sample program on Fortran 90 user defined operators in the Fortran 90 tutorial and Program N. The tutorial is shipped with the latest version of FTN95 can can be accessed via the Plato Help menu. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon May 07, 2007 10:11 am Post subject: |
|
|
Thanks Paul, that's very helpful. Now I understand what is in the help file - I was confused by errors, warnings and comments all having an "error number" - I thought I could only /ignore errors, not warnings, which I thought was topsy-turvy, but didn't like to say so!
Helpfully, the warning number on the test for equality AND the test for inequality is the same: No. 179
Eddie |
|
Back to top |
|
|
|
|
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
|