Silverfrost Forums

Welcome to our forums

Invalid floating point number

25 Mar 2019 9:44 #23390

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?

25 Mar 2019 11:14 #23391

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

25 Mar 2019 2:09 #23393

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.

25 Mar 2019 7:14 #23397

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...

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
26 Mar 2019 8:44 #23398

Thank you for the feedback.

Pauls function works great =)

Yesterday we did a buffer compare to exclude the problem.

Please login to reply.