ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
host_rounding_mode.h
Go to the documentation of this file.
1#pragma once
2
3#include <cfenv>
4
5/* RAII guard that runs a scope under one host FPU rounding mode and restores
6 * the previous mode on every exit path.
7 *
8 * ESBMC's process-wide default is FE_TONEAREST (see main()). The one library
9 * that needs something else is gaol, which ibex uses for interval arithmetic
10 * and which requires FE_UPWARD; code that calls into it takes a guard for the
11 * duration instead of leaving the whole process rounding upward. */
13{
14 int saved;
15
16public:
17 explicit host_rounding_mode(int mode) : saved(std::fegetround())
18 {
19 if (saved == mode)
20 saved = -1;
21 else
22 std::fesetround(mode);
23 }
24
26 {
27 if (saved >= 0)
28 std::fesetround(saved);
29 }
30
33};
host_rounding_mode(int mode)
Definition host_rounding_mode.h:17
host_rounding_mode & operator=(const host_rounding_mode &)=delete
host_rounding_mode(const host_rounding_mode &)=delete
~host_rounding_mode()
Definition host_rounding_mode.h:25
int fegetround(void)
Definition fenv.c:5
Definition exception.cpp:51