1 //===-- Unittests for tan -------------------------------------------------===//
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/tan.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 
18 DECLARE_SPECIAL_CONSTANTS(double)
19 
TEST(LlvmLibctanTest,Range)20 TEST(LlvmLibctanTest, Range) {
21   static constexpr double _2pi = 6.283185307179586;
22   constexpr UIntType COUNT = 10000000;
23   constexpr UIntType STEP = UIntType(-1) / COUNT;
24   for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
25     double x = double(FPBits(v));
26     // TODO: Expand the range of testing after range reduction is implemented.
27     if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)
28       continue;
29 
30     ASSERT_MPFR_MATCH(mpfr::Operation::Tan, x, __llvm_libc::tan(x), 1.0);
31   }
32 }
33