this function replaces exp()
to avoid underflow and overflow.
note that the maximum and minimum values of exprep are such that they has no effect on the algorithm.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x |
pure function exprep(x) result(f) use, intrinsic :: ieee_exceptions implicit none logical,dimension(2) :: flags type(ieee_flag_type),parameter,dimension(2) :: out_of_range = & [ieee_overflow,ieee_underflow] real(wp), intent(in) :: x real(wp) :: f call ieee_set_halting_mode(out_of_range,.false.) f = exp(x) call ieee_get_flag(out_of_range,flags) if (any(flags)) then call ieee_set_flag(out_of_range,.false.) if (flags(1)) then f = huge(1.0_wp) else f = 0.0_wp end if end if end function exprep