GAMMA的结果下溢了 [英] Result of GAMMA underflows its kind

查看:144
本文介绍了GAMMA的结果下溢了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的程序来计算gamma(-170.1):

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $!程序做一个计算
real(8):: x
x = GAMMA(-170.1)
print *,x
结束程序

但我得到错误:


test.f95 :4.10:

x = GAMMA(-170.1)
1
错误:GAMMA的结果下溢(1)


当我用gfortran编译时。根据Maple gamma(-170.1)= 5.191963205 * 10 ^( - 172),我认为应该在变量x的指数范围内,因为我已经定义了它。

解决方案

你的程序的下面的修改应该工作。请记住,在Fortran中,在分配给LHS之前对RHS进行评估,并且浮点文字是默认类型,即单精度。因此,使用GAMMA双精度的参数,编译器选择双精度GAMMA。

 

程序算术
!程序做一个计算
integer,parameter :: dp = kind(1.0d0)
real(dp):: x
x = GAMMA(-170.1_dp)
print *, x
结束程序


I would like to calculate gamma(-170.1) using the program below:

program arithmetic  
! program to do a calculation  
real(8) :: x  
x = GAMMA(-170.1)  
print *, x  
end program  

but I get the error:

test.f95:4.10:

x = GAMMA(-170.1) 1 Error: Result of GAMMA underflows its kind at (1)

when I compile with gfortran. According to Maple gamma(-170.1) = 5.191963205*10^(-172) which I think should be within the range of the exponent of the variable x as I've defined it.

解决方案

The below modification of your program should work. Remember that in Fortran the RHS is evaluated before assigning to the LHS, and that floating point literals are of default kind, that is single precision. Thus, making the argument to GAMMA double precision the compiler chooses the double precision GAMMA.


program arithmetic  
! program to do a calculation  
integer, parameter :: dp = kind(1.0d0)
real(dp) :: x  
x = GAMMA(-170.1_dp)  
print *, x  
end program

这篇关于GAMMA的结果下溢了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆