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 //===----------------------------------------------------------------------===// 8 9 #include "src/fenv/fegetround.h" 10 #include "src/fenv/fesetround.h" 11 12 #include "utils/UnitTest/Test.h" 13 14 #include <fenv.h> 15 16 TEST(LlvmLibcRoundingModeTest, SetAndGet) { 17 struct ResetDefaultRoundingMode { 18 int original; 19 ~ResetDefaultRoundingMode() { 20 __llvm_libc::fesetround(original); 21 } 22 } reset{__llvm_libc::fegetround()}; 23 24 int s = __llvm_libc::fesetround(FE_TONEAREST); 25 EXPECT_EQ(s, 0); 26 int rm = __llvm_libc::fegetround(); 27 EXPECT_EQ(rm, FE_TONEAREST); 28 29 s = __llvm_libc::fesetround(FE_UPWARD); 30 EXPECT_EQ(s, 0); 31 rm = __llvm_libc::fegetround(); 32 EXPECT_EQ(rm, FE_UPWARD); 33 34 s = __llvm_libc::fesetround(FE_DOWNWARD); 35 EXPECT_EQ(s, 0); 36 rm = __llvm_libc::fegetround(); 37 EXPECT_EQ(rm, FE_DOWNWARD); 38 39 s = __llvm_libc::fesetround(FE_TOWARDZERO); 40 EXPECT_EQ(s, 0); 41 rm = __llvm_libc::fegetround(); 42 EXPECT_EQ(rm, FE_TOWARDZERO); 43 } 44