[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / exhaustive / sincosf_test.cpp
blob2072fa90c3b1d7879a32ab79b9a6a4f81534119d
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/__support/FPUtil/FPBits.h"
11 #include "src/math/sincosf.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "utils/MPFRWrapper/MPFRUtils.h"
15 #include <thread>
17 using FPBits = __llvm_libc::fputil::FPBits<float>;
19 namespace mpfr = __llvm_libc::testing::mpfr;
21 struct LlvmLibcSinCosfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
22 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 float sinx, cosx;
31 __llvm_libc::sincosf(x, &sinx, &cosx);
32 result &= EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, sinx, 0.5, rounding);
33 result &= EXPECT_MPFR_MATCH(mpfr::Operation::Cos, x, cosx, 0.5, rounding);
34 } while (++bits < stop);
35 return result;
39 // Range: [0, +Inf);
40 static constexpr uint32_t POS_START = 0x0000'0000U;
41 static constexpr uint32_t POS_STOP = 0x7f80'0000U;
43 TEST_F(LlvmLibcSinCosfExhaustiveTest, PostiveRangeRoundNearestTieToEven) {
44 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Nearest);
47 TEST_F(LlvmLibcSinCosfExhaustiveTest, PostiveRangeRoundUp) {
48 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Upward);
51 TEST_F(LlvmLibcSinCosfExhaustiveTest, PostiveRangeRoundDown) {
52 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::Downward);
55 TEST_F(LlvmLibcSinCosfExhaustiveTest, PostiveRangeRoundTowardZero) {
56 test_full_range(POS_START, POS_STOP, mpfr::RoundingMode::TowardZero);
59 // Range: (-Inf, 0];
60 static constexpr uint32_t NEG_START = 0x8000'0000U;
61 static constexpr uint32_t NEG_STOP = 0xff80'0000U;
63 TEST_F(LlvmLibcSinCosfExhaustiveTest, NegativeRangeRoundNearestTieToEven) {
64 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Nearest);
67 TEST_F(LlvmLibcSinCosfExhaustiveTest, NegativeRangeRoundUp) {
68 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Upward);
71 TEST_F(LlvmLibcSinCosfExhaustiveTest, NegativeRangeRoundDown) {
72 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::Downward);
75 TEST_F(LlvmLibcSinCosfExhaustiveTest, NegativeRangeRoundTowardZero) {
76 test_full_range(NEG_START, NEG_STOP, mpfr::RoundingMode::TowardZero);