我想用下面的程序来计算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 programbut 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的结果下溢了
发布评论