[mlir] More fixes for 9fddaf6b14102963f12dbb9730f101fc52e662c1
[llvm-project.git] / libc / test / src / math / exhaustive / sincosf_test.cpp
blob4d53d24f05328e11fef04e45bd8c6f3092ee0977
1 //===-- Exhaustive test for sincosf ---------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "exhaustive_test.h"
10 #include "src/math/sincosf.h"
11 #include "utils/MPFRWrapper/MPFRUtils.h"
13 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
15 struct SincosfChecker : public virtual LIBC_NAMESPACE::testing::Test {
16 using FloatType = float;
17 using FPBits = LIBC_NAMESPACE::fputil::FPBits<float>;
18 using StorageType = uint32_t;
20 uint64_t check(StorageType start, StorageType stop,
21 mpfr::RoundingMode rounding) {
22 mpfr::ForceRoundingMode r(rounding);
23 if (!r.success)
24 return (stop > start);
25 StorageType bits = start;
26 uint64_t failed = 0;
27 do {
28 FPBits xbits(bits);
29 FloatType x = xbits.get_val();
30 FloatType sinx, cosx;
31 LIBC_NAMESPACE::sincosf(x, &sinx, &cosx);
33 bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Sin, x,
34 sinx, 0.5, rounding);
35 correct = correct && TEST_MPFR_MATCH_ROUNDING_SILENTLY(
36 mpfr::Operation::Cos, x, cosx, 0.5, rounding);
37 failed += (!correct);
38 // Uncomment to print out failed values.
39 // if (!correct) {
40 // TEST_MPFR_MATCH(mpfr::Operation::Sin, x, sinx, 0.5, rounding);
41 // TEST_MPFR_MATCH(mpfr::Operation::Cos, x, cosx, 0.5, rounding);
42 // }
43 } while (bits++ < stop);
44 return failed;
48 using LlvmLibcSincosfExhaustiveTest =
49 LlvmLibcExhaustiveMathTest<SincosfChecker>;
51 // Range: [0, Inf];
52 static constexpr uint32_t POS_START = 0x0000'0000U;
53 static constexpr uint32_t POS_STOP = 0x7f80'0000U;
55 TEST_F(LlvmLibcSincosfExhaustiveTest, PostiveRange) {
56 test_full_range_all_roundings(POS_START, POS_STOP);
59 // Range: [-1, 0];
60 static constexpr uint32_t NEG_START = 0xb000'0000U;
61 static constexpr uint32_t NEG_STOP = 0xbf7f'ffffU;
63 TEST_F(LlvmLibcSincosfExhaustiveTest, NegativeRange) {
64 test_full_range_all_roundings(NEG_START, NEG_STOP);