1 //===-- Exhaustive test for sinf ------------------------------------------===//
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 "exhaustive_test.h"
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/math/sinf.h"
12 #include "utils/MPFRWrapper/MPFRUtils.h"
13 #include "utils/UnitTest/FPMatcher.h"
14
15 #include <thread>
16
17 using FPBits = __llvm_libc::fputil::FPBits<float>;
18
19 namespace mpfr = __llvm_libc::testing::mpfr;
20
21 struct LlvmLibcSinfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
checkLlvmLibcSinfExhaustiveTest22 bool check(uint32_t start, uint32_t stop,
23 mpfr::RoundingMode rounding) override {
24 mpfr::ForceRoundingMode r(rounding);
25 uint32_t bits = start;
26 bool result = true;
27 do {
28 FPBits xbits(bits);
29 float x = float(xbits);
30 bool r = EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x),
31 0.5, rounding);
32 result &= r;
33 } while (++bits < stop);
34 return result;
35 }
36 };
37
38 // Range: [0, +Inf);
39 static constexpr uint32_t POS_START = 0x0000'0000U;
40 static constexpr uint32_t POS_STOP = 0x7f80'0000U;
41
TEST_F(LlvmLibcSinfExhaustiveTest,PostiveRangeRoundNearestTieToEven)42 TEST_F(LlvmLibcSinfExhaustiveTest, PostiveRangeRoundNearestTieToEven) {
43 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Nearest);
44 }
45
TEST_F(LlvmLibcSinfExhaustiveTest,PostiveRangeRoundUp)46 TEST_F(LlvmLibcSinfExhaustiveTest, PostiveRangeRoundUp) {
47 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Upward);
48 }
49
TEST_F(LlvmLibcSinfExhaustiveTest,PostiveRangeRoundDown)50 TEST_F(LlvmLibcSinfExhaustiveTest, PostiveRangeRoundDown) {
51 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Downward);
52 }
53
TEST_F(LlvmLibcSinfExhaustiveTest,PostiveRangeRoundTowardZero)54 TEST_F(LlvmLibcSinfExhaustiveTest, PostiveRangeRoundTowardZero) {
55 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::TowardZero);
56 }
57
58 // Range: (-Inf, 0];
59 static constexpr uint32_t NEG_START = 0x8000'0000U;
60 static constexpr uint32_t NEG_STOP = 0xff80'0000U;
61
TEST_F(LlvmLibcSinfExhaustiveTest,NegativeRangeRoundNearestTieToEven)62 TEST_F(LlvmLibcSinfExhaustiveTest, NegativeRangeRoundNearestTieToEven) {
63 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Nearest);
64 }
65
TEST_F(LlvmLibcSinfExhaustiveTest,NegativeRangeRoundUp)66 TEST_F(LlvmLibcSinfExhaustiveTest, NegativeRangeRoundUp) {
67 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Upward);
68 }
69
TEST_F(LlvmLibcSinfExhaustiveTest,NegativeRangeRoundDown)70 TEST_F(LlvmLibcSinfExhaustiveTest, NegativeRangeRoundDown) {
71 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Downward);
72 }
73
TEST_F(LlvmLibcSinfExhaustiveTest,NegativeRangeRoundTowardZero)74 TEST_F(LlvmLibcSinfExhaustiveTest, NegativeRangeRoundTowardZero) {
75 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::TowardZero);
76 }
77