1 //===-- Unittests mod_2pi, mod_pi_over_4 and mod_pi_over_2 ----------------===//
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/math/generic/dp_trig.h"
10 #include "utils/MPFRWrapper/MPFRUtils.h"
11 #include "utils/UnitTest/FPMatcher.h"
12 #include "utils/UnitTest/Test.h"
13 
14 #include <math.h>
15 
16 namespace mpfr = __llvm_libc::testing::mpfr;
17 using FPBits = __llvm_libc::fputil::FPBits<double>;
18 using UIntType = FPBits::UIntType;
19 
TEST(LlvmLibcMod2PITest,Range)20 TEST(LlvmLibcMod2PITest, Range) {
21   constexpr UIntType count = 1000000000;
22   constexpr UIntType step = UIntType(-1) / count;
23   for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
24     double x = double(FPBits(v));
25     if (isnan(x) || isinf(x) || x <= 0.0)
26       continue;
27 
28     ASSERT_MPFR_MATCH(mpfr::Operation::Mod2PI, x, __llvm_libc::mod_2pi(x), 0);
29   }
30 }
31 
TEST(LlvmLibcModPIOver2Test,Range)32 TEST(LlvmLibcModPIOver2Test, Range) {
33   constexpr UIntType count = 1000000000;
34   constexpr UIntType step = UIntType(-1) / count;
35   for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
36     double x = double(FPBits(v));
37     if (isnan(x) || isinf(x) || x <= 0.0)
38       continue;
39 
40     ASSERT_MPFR_MATCH(mpfr::Operation::ModPIOver2, x,
41                       __llvm_libc::mod_pi_over_2(x), 0);
42   }
43 }
44 
TEST(LlvmLibcModPIOver4Test,Range)45 TEST(LlvmLibcModPIOver4Test, Range) {
46   constexpr UIntType count = 1000000000;
47   constexpr UIntType step = UIntType(-1) / count;
48   for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
49     double x = double(FPBits(v));
50     if (isnan(x) || isinf(x) || x <= 0.0)
51       continue;
52 
53     ASSERT_MPFR_MATCH(mpfr::Operation::ModPIOver4, x,
54                       __llvm_libc::mod_pi_over_4(x), 0);
55   }
56 }
57