gfortran IEEE 异常不准确 [英] gfortran IEEE exception inexact

查看:32
本文介绍了gfortran IEEE 异常不准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在一台新的 64 b 机器上使用 gfortran (5.3.1)、Fedora 23.使用简单的 gfortran -o 进行编译(我们没有使用 -ffpe-trap 选项!),会引发classical-trivial"警告:

We are using gfortran (5.3.1), Fedora 23, in a new 64 b machine. Compiling with simple gfortran -o (we are not using -ffpe-trap options !), excites the "classical- trivial" warning:

Note: The following floating-point exceptions are signalling: IEEE_INVALID_FLAG 

这是由于 INEXACT 异常(类型 2.0/3.0).DDD 调试器指向一个实常数 (180d0/pi; pi = 3.141518...).我们不明白为什么会出现这个标志,用这个基本的编译,因为这些异常一直都在发生......

Its due to INEXACT exception (type 2.0/3.0). The DDD debugger points towards a real constant (180d0/pi; pi = 3.141518...). We don't understand why this flag appears, with this basic compilation, because these exceptions are reached all the time...

这里有一些代码:

    Implicit none !real*8(a-h,o-z)   
    real*8 pi,dpi,radgra,TSI,TOL,xlsol,fi,W      
    Integer year, T1, k,m

      open(10,file='stof-elem.sol') 

          pi = 4.d0 * datan(1.d0)
         dpi = 2.d0 * pi
       radgra = 360.d0 / dpi !!!!!!!! HERE POINTS THE EXCEPTION!!!!!!!!!!

         T1 = -9998 !800d0 !1450d0 !

        TSI = 1360.d0 !1364.5d0 !1367d0 

        TOL = 0.7d0 / radgra ! dont' use smaller 

C...Name of the output file
      open(12,file='midmonth-2000.sal')

C-----------------------------------------------------------------------
            k = 0 ! outputs counter

            write(12,*)T1            

      DO m = 1, 12  ! select month
           IF(T1.lt.0) then
             xlsol = (270.d0 - dble(m-1) * 30.d0) / radgra !from Dec
               if(xlsol.lt.0d0) xlsol = xlsol + dpi
           ELSE
              xlsol = dble(m-3) * 30.d0 / radgra !from Jan
               if(xlsol.lt.0d0) xlsol = xlsol + dpi
           ENDIF 

            CALL MEANINSOLA(pi,dpi,radgra,TOL,T1,TSI,xlsol,fi,k,W)

            rewind(10) ! better rewind...
      ENDDO

       write(*,*) 'Outputs:', k,'lines'

异常出现在 RADGRA ... 的定义中,如图所示.如果重新定义常量(即,RADGRA = 57.2d0),异常会迁移到使用 RADGRA 的其他部分……以此类推……

The EXCEPTION appears at the definition of RADGRA ... as indicated. If redefine the constant (i.e.,, RADGRA = 57.2d0), the exception migrates to another parts using RADGRA... and so on...

推荐答案

根据 https://gcc.gnu.org/ml/fortran/2013-06/msg00072.html Fortran 标准要求在执行 STOP 语句后打印这些注释.

As per https://gcc.gnu.org/ml/fortran/2013-06/msg00072.html the Fortran standard requires printing of these notes after executing the STOP statement.

"如果有任何异常 (14) 在该图像上发出信号,处理器应发出警告,指示哪些异常正在发出信号;这警告应在由命名常量 ERROR 标识的单元上单位 (13.8.2.8)."

"If any exception (14) is signaling on that image, the processor shall issue a warning indicating which exceptions are signaling; this warning shall be on the unit identified by the named constant ERROR UNIT (13.8.2.8)."

请注意,即使您通过 -std=f95 请求 Fortran 95 标准,该注释仍会显示.

Note that even if you request the Fortran 95 standard by -std=f95 the note is still displayed.

您可以通过 -ffpe-summary= 控制此行为,请参阅编译器的 手册.默认情况下,会显示除不准确"之外的所有异常的摘要.您是否在某处启用了不精确自己?

You can control this behaviour by -ffpe-summary=, consult you compiler's manual. By default, a summary for all exceptions but ‘inexact’ is shown. Have you enabled inexact yourself somewhere?

为什么异常信号是另一回事,你必须检查你的代码是否是你应该担心的事情.也许你不应该,不精确的浮点运算非常普遍.

Why is that exception signalling is a different matter, you must examine your code whether it is something you should be worried about or not. Probably you should not, inexact floating point operations are very common.

因为消息是由 STOP 语句调用的,摆脱这些消息的一个简单方法是不要通过 STOP 语句终止您的程序,而是让它到达END PROGRAM.

Because the message is invoked by the STOP statement, a simple way to get rid of these messages is to not terminate your program by a STOP statement, but let it reach the END PROGRAM.

这篇关于gfortran IEEE 异常不准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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