66 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "exhaustive_test.h"10#include "src/math/sincosf.h"11#include "utils/MPFRWrapper/MPFRUtils.h"12 13namespace mpfr = LIBC_NAMESPACE::testing::mpfr;14 15struct SincosfChecker : public virtual LIBC_NAMESPACE::testing::Test {16 using FloatType = float;17 using FPBits = LIBC_NAMESPACE::fputil::FPBits<float>;18 using StorageType = uint32_t;19 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);32 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;45 }46};47 48using LlvmLibcSincosfExhaustiveTest =49 LlvmLibcExhaustiveMathTest<SincosfChecker>;50 51// Range: [0, Inf];52static constexpr uint32_t POS_START = 0x0000'0000U;53static constexpr uint32_t POS_STOP = 0x7f80'0000U;54 55TEST_F(LlvmLibcSincosfExhaustiveTest, PostiveRange) {56 test_full_range_all_roundings(POS_START, POS_STOP);57}58 59// Range: [-1, 0];60static constexpr uint32_t NEG_START = 0xb000'0000U;61static constexpr uint32_t NEG_STOP = 0xbf7f'ffffU;62 63TEST_F(LlvmLibcSincosfExhaustiveTest, NegativeRange) {64 test_full_range_all_roundings(NEG_START, NEG_STOP);65}66