GAMMA 的结果低于同类
我想使用下面的程序计算 gamma(-170.1):
program arithmetic
! program to do a calculation
real(8) :: x
x = GAMMA(-170.1)
print *, x
end program
但出现错误:
测试.f95:4.10:
x = 伽马(-170.1) 1 错误:GAMMA 的结果在 (1) 处下溢
错误:当我使用 gfortran 进行编译时, 。根据 Maple gamma(-170.1) = 5.191963205*10^(-172) ,我认为应该在我定义的变量 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对您的程序进行以下修改应该可以工作。请记住,在 Fortran 中,在分配给 LHS 之前先计算 RHS,并且浮点文字是默认类型,即单精度。因此,使 GAMMA 的参数成为双精度,编译器会选择双精度 GAMMA。
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.
-170.0 可以被视为浮点数。如果是这样,将其更改为双精度应该可以解决问题。
-170.0 may be treated as a float. If so, changing it to a double should resolve the issue.