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