36 lines · cpp
1//===-- Unittests for sinf float-only -------------------------------------===//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 "src/__support/FPUtil/FPBits.h"10#include "src/__support/math/sincosf_float_eval.h"11#include "test/UnitTest/FPMatcher.h"12#include "test/UnitTest/Test.h"13#include "utils/MPFRWrapper/MPFRUtils.h"14 15#include "hdr/stdint_proxy.h"16 17using LlvmLibcSinfFloatTest = LIBC_NAMESPACE::testing::FPTest<float>;18 19float sinf_fast(float x) {20 return LIBC_NAMESPACE::math::sincosf_float_eval::sincosf_eval<21 /*IS_SIN*/ true>(x);22}23 24namespace mpfr = LIBC_NAMESPACE::testing::mpfr;25 26TEST_F(LlvmLibcSinfFloatTest, InFloatRange) {27 constexpr uint32_t COUNT = 100'000;28 constexpr uint32_t STEP = UINT32_MAX / COUNT;29 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {30 float x = FPBits(v).get_val();31 if (FPBits(v).is_nan() || FPBits(v).is_inf())32 continue;33 ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, sinf_fast(x), 3.5);34 }35}36