1 //===-- Unittests mod_2pi, mod_pi_over_4 and mod_pi_over_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
7 //===----------------------------------------------------------------------===//
9 #include "src/math/generic/dp_trig.h"
10 #include "test/UnitTest/FPMatcher.h"
11 #include "test/UnitTest/Test.h"
12 #include "utils/MPFRWrapper/MPFRUtils.h"
16 namespace mpfr
= __llvm_libc::testing::mpfr
;
17 using FPBits
= __llvm_libc::fputil::FPBits
<double>;
18 using UIntType
= FPBits::UIntType
;
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)
28 ASSERT_MPFR_MATCH(mpfr::Operation::Mod2PI
, x
, __llvm_libc::mod_2pi(x
), 0);
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)
40 ASSERT_MPFR_MATCH(mpfr::Operation::ModPIOver2
, x
,
41 __llvm_libc::mod_pi_over_2(x
), 0);
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)
53 ASSERT_MPFR_MATCH(mpfr::Operation::ModPIOver4
, x
,
54 __llvm_libc::mod_pi_over_4(x
), 0);