blob: 0f03b5f50cf915aece59a7069f28eecef48963f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//===-- Unittests for fegetround and fesetround ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "src/fenv/fegetround.h"
#include "src/fenv/fesetround.h"
#include "test/UnitTest/Test.h"
#include <fenv.h>
TEST(LlvmLibcRoundingModeTest, SetAndGet) {
struct ResetDefaultRoundingMode {
int original;
~ResetDefaultRoundingMode() {
__llvm_libc::fesetround(original);
}
} reset{__llvm_libc::fegetround()};
int s = __llvm_libc::fesetround(FE_TONEAREST);
EXPECT_EQ(s, 0);
int rm = __llvm_libc::fegetround();
EXPECT_EQ(rm, FE_TONEAREST);
s = __llvm_libc::fesetround(FE_UPWARD);
EXPECT_EQ(s, 0);
rm = __llvm_libc::fegetround();
EXPECT_EQ(rm, FE_UPWARD);
s = __llvm_libc::fesetround(FE_DOWNWARD);
EXPECT_EQ(s, 0);
rm = __llvm_libc::fegetround();
EXPECT_EQ(rm, FE_DOWNWARD);
s = __llvm_libc::fesetround(FE_TOWARDZERO);
EXPECT_EQ(s, 0);
rm = __llvm_libc::fegetround();
EXPECT_EQ(rm, FE_TOWARDZERO);
}
|