efp_t -> real64. Regularises a LOCAL COPY of a (never mutates
the argument) – pure with intent(in), per
FORTRAN_STYLE.md’s “default new procedures to pure” (MOM6’s
EFP_to_real instead mutates its intent(inout) argument).
a%poison /= 0 short-circuits to a quiet NaN – see efp_t’s
docstring for why: this is what turns a non-finite input anywhere
in the accumulation into a NaN OUTPUT, instead of the fixed-point
bins (zeroed by a NaN decompose, or saturated by an overflow one)
silently reconstructing a plausible finite value.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(efp_t), | intent(in) | :: | a |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int64), | private | :: | e(EFP_DIGITS) |
pure function efp_to_real(a) result(r) !! `efp_t -> real64`. Regularises a LOCAL COPY of `a` (never mutates !! the argument) -- `pure` with `intent(in)`, per !! `FORTRAN_STYLE.md`'s "default new procedures to pure" (MOM6's !! `EFP_to_real` instead mutates its `intent(inout)` argument). !! !! `a%poison /= 0` short-circuits to a quiet NaN -- see `efp_t`'s !! docstring for why: this is what turns a non-finite input anywhere !! in the accumulation into a NaN OUTPUT, instead of the fixed-point !! bins (zeroed by a NaN decompose, or saturated by an overflow one) !! silently reconstructing a plausible finite value. type(efp_t), intent(in) :: a real(real64) :: r integer(int64) :: e(EFP_DIGITS) if (a%poison /= 0_int64) then r = ieee_value(r, ieee_quiet_nan) return end if e = a%v call efp_regularize(e) r = real(e(1), real64)*EFP_PR1 + real(e(2), real64)*EFP_PR2 & + real(e(3), real64)*EFP_PR3 + real(e(4), real64)*EFP_PR4 & + real(e(5), real64)*EFP_PR5 + real(e(6), real64)*EFP_PR6 end function efp_to_real