[J3] Question on overflow and run-time detection of infinity?
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Fri Nov 23 09:09:51 EST 2018
My knowledge of the details of the IEEE specs is at best charitably described as marginal, esp. with regard to signaling. And this question my well be in the quality of implementation realm rather than what the standard intends. With those provisos …
I have encountered a situation where a denominator for an expression for a diagnostic can be 0 on semi-rare occasions. In this case both numerator and denominator will be 0. Both are otherwise non-negative, so +Infinity seemed a sensible value to return to the client code. So I inserted the following:
USE, INTRINSIC :: IEEE_ARITHMETIC, only: IEEE_POSITIVE_INF, IEEE_VALUE
REAL(KIND=REAL64) :: relative_deviation
…
REAL(KIND=REAL64) :: abs_mean
abs_mean = ABS(this%get_mean_cycle_time())
IF (abs_mean > 0) then ! non-zero denominator !
relative_deviation = 100*(this%get_standard_deviation()/abs_mean)
ELSE ! zero denominator
relative_deviation = IEEE_VALUE(1.0_REAL64, IEEE_POSITIVE_INF)
END IF
No further calculations are ever done with relative_deviation except a subsequent formatted output. Two compilers print “Infinity” as expected even when using aggressive runtime checking (e.g., with NAG I am using -C=all and -ieee=stop). The 3rd compiler (gfortran 8.2.0) halts at the above assignment to IEEE_POSITIVE_INF with the useful, albeit undesired run-time message:
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
The flag that toggles is -ffpe-trap=overflow. I can turn that option off, but I would like the compile to helpfully identify other bad denominators (and similar things) elsewhere in the application.
The question: Is not the intent of the standard to allow using the IEEE functionality to return values such as Infinity without halting the run while still enabling run-time checking of calculations that incidentally compute erroneous operations?
Thanks,
- Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20181123/3909e2a5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 7903 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20181123/3909e2a5/attachment.bin>
More information about the J3
mailing list