std::numeric_limits<T>::round_style
Min standard notice:
The value of std::numeric_limits
# Declarations
static const std::float_round_style round_style;
(until C++11)
static constexpr std::float_round_style round_style;
(since C++11)
# Notes
These values are constants, and do not reflect the changes to the rounding made by std::fesetround. The changed values may be obtained from FLT_ROUNDS or std::fegetround.
# Example
#include <iostream>
#include <limits>
auto print(std::float_round_style frs)
{
switch (frs)
{
case std::round_indeterminate:
return "Rounding style cannot be determined";
case std::round_toward_zero:
return "Rounding toward zero";
case std::round_to_nearest:
return "Rounding toward nearest representable value";
case std::round_toward_infinity:
return "Rounding toward positive infinity";
case std::round_toward_neg_infinity:
return "Rounding toward negative infinity";
}
return "unknown round style";
}
int main()
{
std::cout << std::hexfloat
<< "The decimal 0.1 is stored in a double as "
<< 0.1 << '\n'
<< "The decimal 0.3 is stored in a double as "
<< 0.3 << '\n'
<< print(std::numeric_limits<double>::round_style) << '\n';
}