[英]Why Floating Point Exception (FPE) is not raised?
我試圖在 Fortran 代碼中捕獲一些 FPE,但它似乎並不適用於所有環境。
我寫了下面的代碼作為例子:
program test
implicit none
doubleprecision, dimension(1) :: x ! used to lure the compiler
x(1) = 1d0
print *, 'start'
print *, 1d0 / (1d0 - x(1))
print *, 'end'
end program test
我的一台機器 (1) 使用 CentOS 7.6.1810、gfortran 4.8.5,並有一個 Intel Xenon 作為 CPU。 另一個 (2) 使用 Debian 10 Buster(實際上這個是在 Windows 10 上,但我使用 WSL 的 debian 應用程序),gfortran 9.2.0 並且有一個 Intel Core i5 作為 CPU。
當我使用編譯上面的代碼時
gfortran -o test -ffpe-trap=zero -fbacktrace -g -Og test.f90
在機器 1 上執行代碼,我得到了我所期望的,即
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7F2374BEC697
#1 0x7F2374BECCDE
#2 0x7F23740E827F
#3 0x400858 in MAIN__ at test.f90:9
然而,當我在機器 2 上做同樣的事情時,我只得到:
$ ./test
start
為什么? 我應該怎么做才能在機器 2 上獲得 SIGFPE(和其他信號)錯誤消息?
安裝WSL 2解決了這個問題。
$ ./test
start
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#0 0x7feab2aee8b0 in ???
#1 0x7feab2aedae3 in ???
#2 0x7feab276883f in ???
at /build/glibc-vjB4T1/glibc-2.28/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3 0x4011fb in test
at /home/user/test/test.f90:9
#4 0x401299 in main
at /home/user/test/test.f90:11
Floating point exception
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.