Giter Site home page Giter Site logo

Comments (2)

ZZy979 avatar ZZy979 commented on September 26, 2024

为了验证各种环境下编译器是否支持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.

ZZy979 avatar ZZy979 commented on September 26, 2024

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和Clang编译器提供了开启或关闭errno的命令行选项:

from ppp-code.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.