1 //===-- Exhaustive test for sincosf ---------------------------------------===//
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
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
);
24 return (stop
> start
);
25 StorageType bits
= start
;
29 FloatType x
= xbits
.get_val();
31 LIBC_NAMESPACE::sincosf(x
, &sinx
, &cosx
);
33 bool correct
= TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Sin
, x
,
35 correct
= correct
&& TEST_MPFR_MATCH_ROUNDING_SILENTLY(
36 mpfr::Operation::Cos
, x
, cosx
, 0.5, rounding
);
38 // Uncomment to print out failed values.
40 // TEST_MPFR_MATCH(mpfr::Operation::Sin, x, sinx, 0.5, rounding);
41 // TEST_MPFR_MATCH(mpfr::Operation::Cos, x, cosx, 0.5, rounding);
43 } while (bits
++ < stop
);
48 using LlvmLibcSincosfExhaustiveTest
=
49 LlvmLibcExhaustiveMathTest
<SincosfChecker
>;
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
);
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
);