1861dc759SSiva Chandra Reddy //===-- Unittests for cos -------------------------------------------------===// 2861dc759SSiva Chandra Reddy // 3861dc759SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4861dc759SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information. 5861dc759SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6861dc759SSiva Chandra Reddy // 7861dc759SSiva Chandra Reddy //===----------------------------------------------------------------------===// 8861dc759SSiva Chandra Reddy 9861dc759SSiva Chandra Reddy #include "src/math/cos.h" 10861dc759SSiva Chandra Reddy #include "utils/MPFRWrapper/MPFRUtils.h" 116c3f53c7SSiva Chandra Reddy #include "utils/UnitTest/FPMatcher.h" 12861dc759SSiva Chandra Reddy #include "utils/UnitTest/Test.h" 13861dc759SSiva Chandra Reddy 14861dc759SSiva Chandra Reddy #include <math.h> 15861dc759SSiva Chandra Reddy 16861dc759SSiva Chandra Reddy namespace mpfr = __llvm_libc::testing::mpfr; 17861dc759SSiva Chandra Reddy 18861dc759SSiva Chandra Reddy DECLARE_SPECIAL_CONSTANTS(double) 19861dc759SSiva Chandra Reddy TEST(LlvmLibccosTest,Range)20861dc759SSiva Chandra ReddyTEST(LlvmLibccosTest, Range) { 21861dc759SSiva Chandra Reddy static constexpr double _2pi = 6.283185307179586; 22*25226f3eSMichael Jones constexpr UIntType COUNT = 10000000; 23*25226f3eSMichael Jones constexpr UIntType STEP = UIntType(-1) / COUNT; 24*25226f3eSMichael Jones for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) { 25861dc759SSiva Chandra Reddy double x = double(FPBits(v)); 26861dc759SSiva Chandra Reddy // TODO: Expand the range of testing after range reduction is implemented. 27861dc759SSiva Chandra Reddy if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi) 28861dc759SSiva Chandra Reddy continue; 29861dc759SSiva Chandra Reddy 30861dc759SSiva Chandra Reddy ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cos(x), 1.0); 31861dc759SSiva Chandra Reddy } 32861dc759SSiva Chandra Reddy } 33