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 "test/UnitTest/FPMatcher.h"
11#include "test/UnitTest/Test.h"
12#include "utils/MPFRWrapper/MPFRUtils.h"
13
14#include "hdr/math_macros.h"
15
16using LlvmLibcTanTest = LIBC_NAMESPACE::testing::FPTest<double>;
17
18namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
19
20TEST_F(LlvmLibcTanTest, Range) {
21 static constexpr double _2pi = 6.283185307179586;
22 constexpr StorageType COUNT = 100'000;
23 constexpr StorageType STEP = STORAGE_MAX / COUNT;
24 for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
25 double x = FPBits(v).get_val();
26 // TODO: Expand the range of testing after range reduction is implemented.
27 if (isnan(x: x) || isinf(x: x) || x > _2pi || x < -_2pi)
28 continue;
29
30 ASSERT_MPFR_MATCH(mpfr::Operation::Tan, x, LIBC_NAMESPACE::tan(x), 1.0);
31 }
32}
33

source code of libc/test/src/math/tan_test.cpp