Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / test / src / __support / FPUtil / rounding_mode_test.cpp
blob8077a5aab7afdec529082c00e2856f49ae10c787
1 //===-- Unittests for the quick rounding mode checks ----------------------===//
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/__support/FPUtil/rounding_mode.h"
10 #include "test/UnitTest/Test.h"
11 #include "utils/MPFRWrapper/MPFRUtils.h"
13 #include <fenv.h>
15 using LIBC_NAMESPACE::testing::mpfr::ForceRoundingMode;
16 using LIBC_NAMESPACE::testing::mpfr::RoundingMode;
18 TEST(LlvmLibcFEnvImplTest, QuickRoundingUpTest) {
19 using LIBC_NAMESPACE::fputil::fenv_is_round_up;
21 ForceRoundingMode __r(RoundingMode::Upward);
22 if (__r.success) {
23 ASSERT_TRUE(fenv_is_round_up());
27 ForceRoundingMode __r(RoundingMode::Downward);
28 if (__r.success) {
29 ASSERT_FALSE(fenv_is_round_up());
33 ForceRoundingMode __r(RoundingMode::Nearest);
34 if (__r.success) {
35 ASSERT_FALSE(fenv_is_round_up());
39 ForceRoundingMode __r(RoundingMode::TowardZero);
40 if (__r.success) {
41 ASSERT_FALSE(fenv_is_round_up());
46 TEST(LlvmLibcFEnvImplTest, QuickRoundingDownTest) {
47 using LIBC_NAMESPACE::fputil::fenv_is_round_down;
49 ForceRoundingMode __r(RoundingMode::Upward);
50 if (__r.success) {
51 ASSERT_FALSE(fenv_is_round_down());
55 ForceRoundingMode __r(RoundingMode::Downward);
56 if (__r.success) {
57 ASSERT_TRUE(fenv_is_round_down());
61 ForceRoundingMode __r(RoundingMode::Nearest);
62 if (__r.success) {
63 ASSERT_FALSE(fenv_is_round_down());
67 ForceRoundingMode __r(RoundingMode::TowardZero);
68 if (__r.success) {
69 ASSERT_FALSE(fenv_is_round_down());
74 TEST(LlvmLibcFEnvImplTest, QuickRoundingNearestTest) {
75 using LIBC_NAMESPACE::fputil::fenv_is_round_to_nearest;
77 ForceRoundingMode __r(RoundingMode::Upward);
78 if (__r.success) {
79 ASSERT_FALSE(fenv_is_round_to_nearest());
83 ForceRoundingMode __r(RoundingMode::Downward);
84 if (__r.success) {
85 ASSERT_FALSE(fenv_is_round_to_nearest());
89 ForceRoundingMode __r(RoundingMode::Nearest);
90 if (__r.success) {
91 ASSERT_TRUE(fenv_is_round_to_nearest());
95 ForceRoundingMode __r(RoundingMode::TowardZero);
96 if (__r.success) {
97 ASSERT_FALSE(fenv_is_round_to_nearest());
102 TEST(LlvmLibcFEnvImplTest, QuickRoundingTowardZeroTest) {
103 using LIBC_NAMESPACE::fputil::fenv_is_round_to_zero;
105 ForceRoundingMode __r(RoundingMode::Upward);
106 if (__r.success) {
107 ASSERT_FALSE(fenv_is_round_to_zero());
111 ForceRoundingMode __r(RoundingMode::Downward);
112 if (__r.success) {
113 ASSERT_FALSE(fenv_is_round_to_zero());
117 ForceRoundingMode __r(RoundingMode::Nearest);
118 if (__r.success) {
119 ASSERT_FALSE(fenv_is_round_to_zero());
123 ForceRoundingMode __r(RoundingMode::TowardZero);
124 if (__r.success) {
125 ASSERT_TRUE(fenv_is_round_to_zero());
130 TEST(LlvmLibcFEnvImplTest, QuickGetRoundTest) {
131 using LIBC_NAMESPACE::fputil::quick_get_round;
133 ForceRoundingMode __r(RoundingMode::Upward);
134 if (__r.success) {
135 ASSERT_EQ(quick_get_round(), FE_UPWARD);
139 ForceRoundingMode __r(RoundingMode::Downward);
140 if (__r.success) {
141 ASSERT_EQ(quick_get_round(), FE_DOWNWARD);
145 ForceRoundingMode __r(RoundingMode::Nearest);
146 if (__r.success) {
147 ASSERT_EQ(quick_get_round(), FE_TONEAREST);
151 ForceRoundingMode __r(RoundingMode::TowardZero);
152 if (__r.success) {
153 ASSERT_EQ(quick_get_round(), FE_TOWARDZERO);