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 

Invalid floating point number

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



Joined: 26 May 2011
Posts: 66

PostPosted: Mon Mar 25, 2019 10:44 am    Post subject: Invalid floating point number Reply with quote

Hello,

I try to read out a value from a binary data set which results in invalid floating point number. This is correct because the value is stored as null or NaN or something like that. I can't do any operations with my value because it results in invalid floating point operation.

Can I use some try catch mechanisms to recognize the problem so that I can fix the value? Perhaps something else?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Mar 25, 2019 12:14 pm    Post subject: Reply with quote

There is no "try/catch" mechanism.

There is a way to trap exceptions (at least for Win32) but I doubt if you can recover (i.e. proceed) after the trap in this context.

Maybe you could read in the value as a character variable and do some initial processing before using an internal READ to convert the string to a REAL.

So something like...

CHARACTER(256) str
REAL x
READ(....) str
!Preprocess str
READ(str, ...) x
Back to top
View user's profile Send private message AIM Address
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Mon Mar 25, 2019 3:09 pm    Post subject: Reply with quote

Here is a slight variation on Paul's suggestion.

You may read the bytes that make up the floating point number in the file into an integer or a pair of integers. You can then check those one or two integers against a list of known values that, when considered as integer representations of floating point values, are invalid, NaN, etc. If the integer(s) does not (do not) match any of those, you can use TRANSFER to obtain the corresponding floating point values, and be confident that no exceptions will be generated.

The performance of either of the schemes will not be good, but that is the price to pay for checking every value instead of relying on interrupts being caused by invalid values.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Mar 25, 2019 8:14 pm    Post subject: Reply with quote

This subject is worth exploring and I will make a note to investigate.

In the meantime there is a relevant FTN95 library function illustrated here...

Code:
C_EXTERNAL invalid_double 'invalid_double'(VAL):LOGICAL*4
real(2) x
!Get the value of x
if(.NOT.invalid_double(x)) print*,x
end
Back to top
View user's profile Send private message AIM Address
dgurok



Joined: 26 May 2011
Posts: 66

PostPosted: Tue Mar 26, 2019 9:44 am    Post subject: Reply with quote

Thank you for the feedback.

Pauls function works great =)

Yesterday we did a buffer compare to exclude the problem.
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Tue Mar 26, 2019 9:48 pm    Post subject: Reply with quote

where's the documentation for the function invalid_double ?
_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
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