如何在gfortran中使用和验证四精度? [英] How to use and verify quad precision in gfortran?

查看:189
本文介绍了如何在gfortran中使用和验证四精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在gfortran中使用四元精度,但它看起来像 real * 16 不起作用。经过一番捕鱼后,我发现它可能被实现为 real * 10 real * 10 实际 quad precision?

I am trying to use quad precision in gfortran, but it seems like the real*16 does not work. After some fishing around, I have found that it may be implemented as real*10. Is real*10 actually quad precision?

如何测试精度我的代码?是否有一个标准的简单算法来测试精度?例如,当我想知道计算机零点是什么时,我会继续除以2.0,直到达到0.0。跟踪这些值可以让我知道计算机何时认为我的非零数字为零 - 给我电脑零。

How can I test the precision of my code? Is there a standard simple algorithm for testing precision? For example, when I want to figure out what computer zero is, I continue to divide by 2.0 until I reach 0.0. Keeping track of the values lets me know when the computer 'thinks' that my non-zero number is zero - giving me computer zero.

有没有一种很好的方法来计算使用类似我所描述的算法来计算精度?

Is there a good way of figuring out the precision with a type of algorithm like I described?

推荐答案

添加到现有答案中... real * N是对语言的扩展,最好不要使用。真实* 10不是四倍精度。被称为扩展 - 它是由英特尔处理器提供的10字节类型。 real * 16可能或不可用于gfortran,具体取决于编译器版本,硬件和libquadmath的可用性。如果在软件中提供,它将会很慢。

Adding to the existing answers... real*N is an extension to the language and is best not used. real*10 is not quad precision. Is is called "extended" -- it is a 10 byte type provided by Intel processors. real*16 may or may not be available on gfortran, depending on compiler version, hardware and availability of libquadmath. If provided in software, it will be slow.

Fortran询问所需精度的方法是使用selected_real_kind函数为精度定义一种类型值你要的那个。

The Fortran way of asking for the precision that you want is to use the selected_real_kind function to define a kind value for the precision that you want.

integer, parameter :: QR_K = selected_real_kind (32)
real (kind=QR_K) :: MyReal

如果可用,将获得四个实数。或者,使用Fortran 2008或更高版本,您可以使用ISO_FORTRAN_ENV,然后访问REAL128。如果精度不可用,种类值将为-1。

Will obtain a quad real number, if it is available. Alternatively, with Fortran 2008 or later you can "use ISO_FORTRAN_ENV" and then have access to the kind value REAL128. The kind values will be -1 if the precision is unavailable.

相关问题:real * 8是什么意思?

这篇关于如何在gfortran中使用和验证四精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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