[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / fenv / rounding_mode_test.cpp
blobf242ed9aaffe5bc03b339689a1c7d91e877850e0
1 //===-- Unittests for fegetround and fesetround ---------------------------===//
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 "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); }
23 } reset;
25 int s = LIBC_NAMESPACE::fesetround(FE_TONEAREST);
26 EXPECT_EQ(s, 0);
27 int rm = LIBC_NAMESPACE::fegetround();
28 EXPECT_EQ(rm, FE_TONEAREST);
30 s = LIBC_NAMESPACE::fesetround(FE_UPWARD);
31 EXPECT_EQ(s, 0);
32 rm = LIBC_NAMESPACE::fegetround();
33 EXPECT_EQ(rm, FE_UPWARD);
35 s = LIBC_NAMESPACE::fesetround(FE_DOWNWARD);
36 EXPECT_EQ(s, 0);
37 rm = LIBC_NAMESPACE::fegetround();
38 EXPECT_EQ(rm, FE_DOWNWARD);
40 s = LIBC_NAMESPACE::fesetround(FE_TOWARDZERO);
41 EXPECT_EQ(s, 0);
42 rm = LIBC_NAMESPACE::fegetround();
43 EXPECT_EQ(rm, FE_TOWARDZERO);