1 //===-- RoundingModeUtils.cpp ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "RoundingModeUtils.h"
13 namespace __llvm_libc
{
16 int get_fe_rounding(RoundingMode mode
) {
18 case RoundingMode::Upward
:
21 case RoundingMode::Downward
:
24 case RoundingMode::TowardZero
:
27 case RoundingMode::Nearest
:
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