The minimum and maximum floating point exponent of a real number

后端 未结 2 1458
一整个雨季
一整个雨季 2021-01-17 05:03

How can I get the minimum and maximum exponent for 32- and 64-bit real numbers? I am doing some work to avoid underflows and overflows and would need to know those numbers.

相关标签:
2条回答
  • 2021-01-17 05:43

    For non-zero reals, the numeric model looks like s*b^e*\sum_{k=1}^{p}f_k*b^{-k}.

    To get the value of the base b use radix(). The minimum and maximum values of the exponent e can be found with exponent combined with tiny and huge.

    use, intrinsic :: iso_fortran_env, only : real32, real64
    
    print 1, "real32", RADIX(1._real32), EXPONENT(TINY(1._real32)), EXPONENT(HUGE(1._real32))
    print 1, "real64", RADIX(1._real64), EXPONENT(TINY(1._real64)), EXPONENT(HUGE(1._real64))
    
    1 FORMAT (A," has radix ", I0, " with exponent range ", I0, " to ", I0, ".")
    end
    
    0 讨论(0)
  • 2021-01-17 05:48

    The function range() returns the range of exponents. The intrinsic function huge() returns the maximum allowable number for a given numeric kind. From that you can see the exponent too by employing a logarithm. See also selected_real_kind().

    The base for gfortran and other normal compilers is 2, but you can test it using radix(). They may be some base 10 kinds in the future.

    In the same manual I linked you will find other useful intrinsics like tiny(), precision(), epsilon(), spacing(), you can follow the links in "See also:".

    0 讨论(0)
提交回复
热议问题