Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

fortran - Result of GAMMA underflows its kind

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...