实数的最小和最大浮点指数
The minimum and maximum floating point exponent of a real number
如何获得 32 位和 64 位实数的最小和最大指数?我正在做一些工作来避免下溢和上溢,并且需要知道这些数字。
我还需要浮点数的基数。
是否有可能在 fortran 中得到 ilmach
的等价物?
函数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()
.
gfortran 和其他普通编译器的基础是 2,但您可以使用 radix()
对其进行测试。以后可能会是一些base 10种。
在我链接的同一手册中,您会发现其他有用的内在函数,例如 tiny(), precision(), epsilon(), spacing()
,您可以点击 "See also:" 中的链接。
对于非零实数,数值模型看起来像 s*b^e*\sum_{k=1}^{p}f_k*b^{-k}
。
要获取基数 b
的值,请使用 radix()
。指数 e
的最小值和最大值可以通过 exponent
结合 tiny
和 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
如何获得 32 位和 64 位实数的最小和最大指数?我正在做一些工作来避免下溢和上溢,并且需要知道这些数字。
我还需要浮点数的基数。
是否有可能在 fortran 中得到 ilmach
的等价物?
函数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()
.
gfortran 和其他普通编译器的基础是 2,但您可以使用 radix()
对其进行测试。以后可能会是一些base 10种。
在我链接的同一手册中,您会发现其他有用的内在函数,例如 tiny(), precision(), epsilon(), spacing()
,您可以点击 "See also:" 中的链接。
对于非零实数,数值模型看起来像 s*b^e*\sum_{k=1}^{p}f_k*b^{-k}
。
要获取基数 b
的值,请使用 radix()
。指数 e
的最小值和最大值可以通过 exponent
结合 tiny
和 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