[J3] Question on overflow and run-time detection of infinity?
Van Snyder
van.snyder at jpl.nasa.gov
Mon Nov 26 00:30:45 EST 2018
On Fri, 2018-11-23 at 14:09 +0000, Clune, Thomas L. (GSFC-6101) via J3
wrote:
> 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
A similar question came up a very long time ago. How does one assign a
signaling NaN using intrinsic assignment?
> 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/20181125/9fd90908/attachment.html>
More information about the J3
mailing list