Comments (2)
为了验证各种环境下编译器是否支持errno和浮点数异常,在workflow中增加debug步骤,打印出程序的实际输出结果。
程序在Ubuntu+GCC和Windows+MinGW环境下输出符合预期:
10
1.41421
1
0
no square root
46341
no square root
在macOS+Clang环境下输出为:
10
1.41421
1
0
nan
46341
nan
在Windows+Visual Studio环境下输出为:
10
1.41421
1
0
-nan(ind)
46341
-nan(ind)
由此可见,在macOS+Clang和Windows+Visual Studio环境下,代码中的测试条件errno == EDOM || fetestexcept(FE_INVALID)
均不满足。由此推断,这两种环境下编译器既不支持errno也不支持浮点数异常。
from ppp-code.
C++标准规定,浮点数环境(包括浮点数异常)只有通过#pragma开启后才有意义:
The floating-point environment access and modification is only meaningful when #pragma STDC FENV_ACCESS is set to ON. Otherwise the implementation is free to assume that floating-point control modes are always the default ones and that floating-point status flags are never tested or modified.
对于GCC和Clang编译器,开启浮点数环境的指令为#pragma STDC FENV_ACCESS ON
;对于MSVC编译器,指令为#pragma fenv_access (on)
。另外,编译器提供了与该#pragma指令等价的命令行选项:
- GCC: -fno-trapping-math和-ftrapping-math(默认),另见Semantics of Floating Point Math in GCC
- Clang: -ffp-exception-behavior=strict或-ffp-model=strict
- MSVC: /fp:strict
另外,GCC和Clang编译器提供了开启或关闭errno的命令行选项:
- GCC: -fno-math-errno和-fmath-errno
- Clang: -f[no-]math-errno
from ppp-code.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ppp-code.