FE_DOWNWARD, FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD

Header: <cfenv>

Each of these macro constants expands to a nonnegative integer constant expression, which can be used with std::fesetround and std::fegetround to indicate one of the supported floating-point rounding modes. The implementation may define additional rounding mode constants in , which should all begin with FE_ followed by at least one uppercase letter. Each macro is only defined if it is supported.

# Declarations

#define FE_DOWNWARD /*implementation defined*/

(since C++11)

#define FE_TONEAREST /*implementation defined*/

(since C++11)

#define FE_TOWARDZERO /*implementation defined*/

(since C++11)

#define FE_UPWARD /*implementation defined*/

(since C++11)

# Example

#include <cfenv>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
// #pragma STDC FENV_ACCESS ON
 
int main()
{
    std::fesetround(FE_DOWNWARD);
    std::cout << "rounding down: \n" << std::setprecision(50)
              << "         pi = " << std::acos(-1.f) << '\n'
              << "stof(\"1.1\") = " << std::stof("1.1") << '\n'
              << "  rint(2.1) = " << std::rint(2.1) << "\n\n";
    std::fesetround(FE_UPWARD);
    std::cout << "rounding up: \n"
              << "         pi = " << std::acos(-1.f) << '\n'
              << "stof(\"1.1\") = " << std::stof("1.1") << '\n'
              << "  rint(2.1) = " << std::rint(2.1) << '\n';
}

# See also