int fesetround( int round )
(1) (since C++11)int fegetround()
(2) (since C++11)Manages the floating-point rounding direction.
1)Attempts to establish the floating-point rounding direction equal to the argument
round
, which is expected to be one of the
floating point rounding macros.
[edit] Parameters [edit] Return value1) â0â on success, non-zero otherwise.
2) The floating point rounding macro describing the current rounding direction or a negative value if the direction cannot be determined.
[edit] NotesThe current rounding mode, reflecting the effects of the most recent fesetround
, can also be queried with FLT_ROUNDS.
See floating-point rounding macros for the effects of rounding.
[edit] Example#include <cfenv> #include <cmath> #include <iomanip> #include <iostream> #include <utility> // #pragma STDC FENV_ACCESS ON int main() { static constexpr std::pair<const char*, const double> samples[] { {" 12.0", 12.0}, {" 12.1", 12.1}, {"-12.1", -12.1}, {" 12.5", 12.5}, {"-12.5", -12.5}, {" 12.9", 12.9}, {"-12.9", -12.9}, {" 13.0", 13.0} }; std::cout << "â sample â FE_DOWNWARD â FE_UPWARD â FE_TONEAREST â FE_TOWARDZERO â\n"; for (const auto& [str, fp] : samples) { std::cout << "â " << std::setw(6) << str << " â "; for (const int dir : {FE_DOWNWARD, FE_UPWARD, FE_TONEAREST, FE_TOWARDZERO}) { std::fesetround(dir); std::cout << std::setw(10) << std::fixed << std::nearbyint(fp) << " â "; } std::cout << '\n'; } }
Output:
â sample â FE_DOWNWARD â FE_UPWARD â FE_TONEAREST â FE_TOWARDZERO â â 12.0 â 12.000000 â 12.000000 â 12.000000 â 12.000000 â â 12.1 â 12.000000 â 13.000000 â 12.000000 â 12.000000 â â -12.1 â -13.000000 â -12.000000 â -12.000000 â -12.000000 â â 12.5 â 12.000000 â 13.000000 â 12.000000 â 12.000000 â â -12.5 â -13.000000 â -12.000000 â -12.000000 â -12.000000 â â 12.9 â 12.000000 â 13.000000 â 13.000000 â 12.000000 â â -12.9 â -13.000000 â -12.000000 â -13.000000 â -12.000000 â â 13.0 â 13.000000 â 13.000000 â 13.000000 â 13.000000 â[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4