replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Floating point exception - using equivalence
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 

Floating point exception - using equivalence

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



Joined: 02 Aug 2005
Posts: 318

PostPosted: Thu May 31, 2012 9:04 am    Post subject: Floating point exception - using equivalence Reply with quote

Hi,

We get datafiles from external sources, supposedly in a standard format. Occasionally, these files contain some small amounts of "rubbish". What we do to try and decode them is to read the data into an INTEGER buffer, equivalence that to a REAL buffer, and read the values from whichever buffer is appropriate for the expected data type:

INTEGER IBUFF(NVALS), ITYPES(NVALS)
REAL RBUFF(NVALS)

EQUIVALENCE (IBUFF, RBUFF)

READ(LU) (IBUFF(I),I=1,NVALS)

DO I=1,NVALS
IF(ITYPES(I).EQ.1 ) THEN !data value is integer
RVAL = IBUFF(I)
ELSE IF( ITYPES(I).EQ.2) THEN !data value is real
RVAL = RBUFF(I)
END IF
..
..
END DO

The problem is that, when the data is corrupted, the value for RBUFF(I) can be an illegal floating point value and the assignment to RVAL causes a crash.

What I would like to do is to be able to test the value of IBUFF(I) to see if it would be an invalid real when equivalenced to RBUFF(I) and to report accordingly, rather than "fall over".

So, is there a "simple" range of integer values that correlate to "valid" reals or an internal function that can do this test? (Presumably, the debugger knows, so it can print "Illegal floating value")

TIA

K
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8211
Location: Salford, UK

PostPosted: Thu May 31, 2012 10:58 am    Post subject: Reply with quote

For single precision...

Code:
program test
C_EXTERNAL INVALID_FLOAT@ 'invalid_float'(VAL):LOGICAL
real val
if(INVALID_FLOAT@(val)) print*, "Bad number"
end
Back to top
View user's profile Send private message AIM Address
KennyT



Joined: 02 Aug 2005
Posts: 318

PostPosted: Thu May 31, 2012 11:16 am    Post subject: Reply with quote

Excellent! Thanks!

K
Back to top
View user's profile Send private message Visit poster's website
KennyT



Joined: 02 Aug 2005
Posts: 318

PostPosted: Wed Aug 01, 2012 12:51 pm    Post subject: Reply with quote

Hi Paul,

is there an equivalent call for real*8? (invalid_double??)

K
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8211
Location: Salford, UK

PostPosted: Wed Aug 01, 2012 3:03 pm    Post subject: Reply with quote

Yes, and it is called invalid_double. Just change the name.
Back to top
View user's profile Send private message AIM Address
KennyT



Joined: 02 Aug 2005
Posts: 318

PostPosted: Wed Aug 01, 2012 3:28 pm    Post subject: Reply with quote

Tks. Is there a list of all these useful functions? I've tried googling for "invalid_double" with Windows API but nothing obvious comes up!

K
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8211
Location: Salford, UK

PostPosted: Thu Aug 02, 2012 8:02 am    Post subject: Reply with quote

The only other one in this class is invalid_long_double.
Back to top
View user's profile Send private message AIM Address
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