简体   繁体   English

实数的最小和最大浮点指数

[英]The minimum and maximum floating point exponent of a real number

How can I get the minimum and maximum exponent for 32- and 64-bit real numbers? 如何获得32位和64位实数的最小和最大指数? I am doing some work to avoid underflows and overflows and would need to know those numbers. 我正在做一些工作来避免下溢和溢出,并且需要知道这些数字。

I would also need the base for floating point numbers. 我还需要浮点数的基础。

Is it possible in fortran to get the equivalent of ilmach ? 在fortran中是否有可能获得ilmach的等效ilmach

The function range() returns the range of exponents. 函数range()返回指数范围。 The intrinsic function huge() returns the maximum allowable number for a given numeric kind. 内在函数huge()返回给定数值类型的最大允许数。 From that you can see the exponent too by employing a logarithm. 由此,您也可以通过使用对数来查看指数。 See also selected_real_kind() . 另请参见selected_real_kind()

The base for gfortran and other normal compilers is 2, but you can test it using radix() . gfortran和其他普通编译器的基础是2,但是您可以使用radix()对其进行测试。 They may be some base 10 kinds in the future. 他们将来可能会以10为基数。

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:". 在我链接的同一本手册中,您会发现其他有用的内在函数,例如tiny(), precision(), epsilon(), spacing() ,您可以按照“另请参见:”中的链接进行操作。

For non-zero reals, the numeric model looks like s*b^e*\\sum_{k=1}^{p}f_k*b^{-k} . 对于非零实数,数字模型看起来像s*b^e*\\sum_{k=1}^{p}f_k*b^{-k}

To get the value of the base b use radix() . 要获取基数b的值,请使用radix() The minimum and maximum values of the exponent e can be found with exponent combined with tiny and huge . 指数e的最小和最大值可以通过将exponenttinyhuge相结合来找到。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM