GAMMA的结果下溢了

编程入门 行业动态 更新时间:2024-10-11 07:27:53
本文介绍了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的结果下溢了

本文发布于:2023-10-24 20:49:18,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GAMMA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!