1 //===-- Unittests for sin -------------------------------------------------===// 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 //===----------------------------------------------------------------------===// 8 9 #include "src/__support/FPUtil/FPBits.h" 10 #include "src/math/sin.h" 11 #include "utils/MPFRWrapper/MPFRUtils.h" 12 #include "utils/UnitTest/FPMatcher.h" 13 #include "utils/UnitTest/Test.h" 14 15 #include <math.h> 16 17 namespace mpfr = __llvm_libc::testing::mpfr; 18 19 DECLARE_SPECIAL_CONSTANTS(double) 20 21 TEST(LlvmLibcSinTest, Range) { 22 static constexpr double _2pi = 6.283185307179586; 23 constexpr UIntType count = 10000000; 24 constexpr UIntType step = UIntType(-1) / count; 25 for (UIntType i = 0, v = 0; i <= count; ++i, v += step) { 26 double x = double(FPBits(v)); 27 // TODO: Expand the range of testing after range reduction is implemented. 28 if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi) 29 continue; 30 31 ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sin(x), 1.0); 32 } 33 } 34