1 //===-- Unittests for fegetround and fesetround ---------------------------===//
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 "src/fenv/fegetround.h"
10 #include "src/fenv/fesetround.h"
12 #include "test/UnitTest/FEnvSafeTest.h"
13 #include "test/UnitTest/Test.h"
15 #include "hdr/fenv_macros.h"
17 using LlvmLibcRoundingModeTest
= LIBC_NAMESPACE::testing::FEnvSafeTest
;
19 TEST_F(LlvmLibcRoundingModeTest
, SetAndGet
) {
20 struct ResetDefaultRoundingMode
{
21 int original
= LIBC_NAMESPACE::fegetround();
22 ~ResetDefaultRoundingMode() { LIBC_NAMESPACE::fesetround(original
); }
25 int s
= LIBC_NAMESPACE::fesetround(FE_TONEAREST
);
27 int rm
= LIBC_NAMESPACE::fegetround();
28 EXPECT_EQ(rm
, FE_TONEAREST
);
30 s
= LIBC_NAMESPACE::fesetround(FE_UPWARD
);
32 rm
= LIBC_NAMESPACE::fegetround();
33 EXPECT_EQ(rm
, FE_UPWARD
);
35 s
= LIBC_NAMESPACE::fesetround(FE_DOWNWARD
);
37 rm
= LIBC_NAMESPACE::fegetround();
38 EXPECT_EQ(rm
, FE_DOWNWARD
);
40 s
= LIBC_NAMESPACE::fesetround(FE_TOWARDZERO
);
42 rm
= LIBC_NAMESPACE::fegetround();
43 EXPECT_EQ(rm
, FE_TOWARDZERO
);