[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / utils / testutils / RoundingModeUtils.cpp
blobaff338097197679ef771a94270da5e62f241cfb2
1 //===-- RoundingModeUtils.cpp ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "RoundingModeUtils.h"
11 #include <fenv.h>
13 namespace __llvm_libc {
14 namespace testutils {
16 int get_fe_rounding(RoundingMode mode) {
17 switch (mode) {
18 case RoundingMode::Upward:
19 return FE_UPWARD;
20 break;
21 case RoundingMode::Downward:
22 return FE_DOWNWARD;
23 break;
24 case RoundingMode::TowardZero:
25 return FE_TOWARDZERO;
26 break;
27 case RoundingMode::Nearest:
28 return FE_TONEAREST;
29 break;
30 default:
31 __builtin_unreachable();
35 ForceRoundingMode::ForceRoundingMode(RoundingMode mode) {
36 old_rounding_mode = fegetround();
37 rounding_mode = get_fe_rounding(mode);
38 if (old_rounding_mode != rounding_mode)
39 fesetround(rounding_mode);
42 ForceRoundingMode::~ForceRoundingMode() {
43 if (old_rounding_mode != rounding_mode)
44 fesetround(old_rounding_mode);
47 } // namespace testutils
48 } // namespace __llvm_libc