diff options
Diffstat (limited to 'libc')
69 files changed, 653 insertions, 202 deletions
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt index 09f169b..a277690 100644 --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -776,6 +776,7 @@ add_header_macro( ../libc/include/nl_types.yaml nl_types.h DEPENDS + .llvm-libc-macros.nl_types_macros .llvm-libc-types.nl_catd ) diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt index 76c03d9..b16337c 100644 --- a/libc/include/llvm-libc-macros/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/CMakeLists.txt @@ -32,6 +32,12 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) endif() add_macro_header( + annex_k_macros + HDR + annex-k-macros.h +) + +add_macro_header( assert_macros HDR assert-macros.h @@ -346,6 +352,12 @@ add_macro_header( ) add_macro_header( + nl_types_macros + HDR + nl-types-macros.h +) + +add_macro_header( pthread_macros HDR pthread-macros.h diff --git a/libc/include/llvm-libc-macros/annex-k-macros.h b/libc/include/llvm-libc-macros/annex-k-macros.h new file mode 100644 index 0000000..7cfb5c1 --- /dev/null +++ b/libc/include/llvm-libc-macros/annex-k-macros.h @@ -0,0 +1,27 @@ +//===-- Definition of macros to be used with Annex K functions ------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H +#define LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H + +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ + (defined(__cplusplus) && __cplusplus >= 201703L) + +// TODO(bassiounix): Who should def this macro (clang vs libc)? Where? +// TODO(bassiounix): uncomment/move when Annex K is fully implemented. +// #define __STDC_LIB_EXT1__ 201112L + +#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1 + +#define LIBC_HAS_ANNEX_K + +#endif // defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1 + +#endif // (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || + // (defined(__cplusplus) && __cplusplus >= 201703L) +#endif // LLVM_LIBC_INCLUDE_LLVM_LIBC_MACROS_ANNEX_K_MACROS_H diff --git a/libc/include/llvm-libc-macros/nl-types-macros.h b/libc/include/llvm-libc-macros/nl-types-macros.h new file mode 100644 index 0000000..b6d0d35 --- /dev/null +++ b/libc/include/llvm-libc-macros/nl-types-macros.h @@ -0,0 +1,15 @@ +//===-- Definition of macros from nl_types.h ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_MACROS_NL_TYPES_MACROS_H +#define LLVM_LIBC_MACROS_NL_TYPES_MACROS_H + +#define NL_SETD 1 +#define NL_CAT_LOCALE 1 + +#endif // LLVM_LIBC_MACROS_NL_TYPES_MACROS_H diff --git a/libc/include/nl_types.yaml b/libc/include/nl_types.yaml index aecbb44..bdb59a8 100644 --- a/libc/include/nl_types.yaml +++ b/libc/include/nl_types.yaml @@ -1,7 +1,11 @@ header: nl_types.h standards: - posix -macros: [] +macros: + - macro_name: NL_SETD + macro_header: nl-types-macros.h + - macro_name: NL_CAT_LOCALE + macro_header: nl-types-macros.h types: - type_name: nl_catd enums: [] diff --git a/libc/include/wchar.yaml b/libc/include/wchar.yaml index 8178091..b8a0a74 100644 --- a/libc/include/wchar.yaml +++ b/libc/include/wchar.yaml @@ -4,6 +4,7 @@ macros: - macro_name: NULL macro_header: null-macro.h types: + - type_name: FILE - type_name: size_t - type_name: wint_t - type_name: wchar_t @@ -104,9 +105,9 @@ functions: - name: wmemset standards: - stdc - return_type: wchar_t* + return_type: wchar_t * arguments: - - type: wchar_t* + - type: wchar_t * - type: wchar_t - type: size_t - name: wcschr @@ -246,7 +247,7 @@ functions: - type: const wchar_t **__restrict - type: size_t - type: size_t - - type: mbstate_t + - type: mbstate_t *__restrict - name: wcsrtombs standards: - stdc @@ -255,7 +256,7 @@ functions: - type: char *__restrict - type: const wchar_t **__restrict - type: size_t - - type: mbstate_t + - type: mbstate_t *__restrict - name: wcrtomb standards: - stdc @@ -299,7 +300,7 @@ functions: arguments: - type: wchar_t *__restrict - type: const wchar_t *__restrict - - type: wchar_t** __restrict + - type: wchar_t **__restrict - name: wcpcpy standards: - stdc diff --git a/libc/src/__support/math/atan2f.h b/libc/src/__support/math/atan2f.h index e3b1932..0133d12 100644 --- a/libc/src/__support/math/atan2f.h +++ b/libc/src/__support/math/atan2f.h @@ -18,9 +18,11 @@ #include "src/__support/FPUtil/nearest_integer.h" #include "src/__support/macros/config.h" #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY +#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA #if defined(LIBC_MATH_HAS_SKIP_ACCURATE_PASS) && \ - defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT) + defined(LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT) && \ + defined(LIBC_TARGET_CPU_HAS_FMA_FLOAT) // We use float-float implementation to reduce size. #include "atan2f_float.h" diff --git a/libc/src/wchar/wcsnrtombs.cpp b/libc/src/wchar/wcsnrtombs.cpp index 7f25b24..a344c23 100644 --- a/libc/src/wchar/wcsnrtombs.cpp +++ b/libc/src/wchar/wcsnrtombs.cpp @@ -22,7 +22,7 @@ namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(size_t, wcsnrtombs, (char *__restrict s, const wchar_t **__restrict pwcs, - size_t nwc, size_t len, mbstate_t *ps)) { + size_t nwc, size_t len, mbstate_t *__restrict ps)) { LIBC_CRASH_ON_NULLPTR(pwcs); static internal::mbstate internal_mbstate; auto result = internal::wcsnrtombs( diff --git a/libc/src/wchar/wcsnrtombs.h b/libc/src/wchar/wcsnrtombs.h index bf8add7..2ca42c7 100644 --- a/libc/src/wchar/wcsnrtombs.h +++ b/libc/src/wchar/wcsnrtombs.h @@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL { size_t wcsnrtombs(char *__restrict s, const wchar_t **__restrict pwcs, - size_t nwc, size_t len, mbstate_t *ps); + size_t nwc, size_t len, mbstate_t *__restrict ps); } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/wchar/wcsrtombs.cpp b/libc/src/wchar/wcsrtombs.cpp index 9d2508c..0167e85 100644 --- a/libc/src/wchar/wcsrtombs.cpp +++ b/libc/src/wchar/wcsrtombs.cpp @@ -22,7 +22,7 @@ namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(size_t, wcsrtombs, (char *__restrict s, const wchar_t **__restrict pwcs, - size_t n, mbstate_t *ps)) { + size_t n, mbstate_t *__restrict ps)) { LIBC_CRASH_ON_NULLPTR(pwcs); static internal::mbstate internal_mbstate; auto result = internal::wcsnrtombs( diff --git a/libc/src/wchar/wcsrtombs.h b/libc/src/wchar/wcsrtombs.h index d23573f..b85e2c6 100644 --- a/libc/src/wchar/wcsrtombs.h +++ b/libc/src/wchar/wcsrtombs.h @@ -17,7 +17,7 @@ namespace LIBC_NAMESPACE_DECL { size_t wcsrtombs(char *__restrict s, const wchar_t **__restrict pwcs, size_t n, - mbstate_t *ps); + mbstate_t *__restrict ps); } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h index f74276f..430727e 100644 --- a/libc/test/UnitTest/FPMatcher.h +++ b/libc/test/UnitTest/FPMatcher.h @@ -16,6 +16,7 @@ #include "src/__support/FPUtil/fpbits_str.h" #include "src/__support/libc_errno.h" #include "src/__support/macros/config.h" +#include "src/__support/macros/optimization.h" #include "src/__support/macros/properties/architectures.h" #include "test/UnitTest/ErrnoCheckingTest.h" #include "test/UnitTest/RoundingModeUtils.h" @@ -294,42 +295,46 @@ private: #define EXPECT_MATH_ERRNO(expected) \ do { \ - if (math_errhandling & MATH_ERRNO) { \ - int actual = libc_errno; \ - libc_errno = 0; \ - EXPECT_EQ(actual, expected); \ - } \ + if ((LIBC_MATH & LIBC_MATH_NO_ERRNO) == 0) \ + if (math_errhandling & MATH_ERRNO) { \ + int actual = libc_errno; \ + libc_errno = 0; \ + EXPECT_EQ(actual, expected); \ + } \ } while (0) #define ASSERT_MATH_ERRNO(expected) \ do { \ - if (math_errhandling & MATH_ERRNO) { \ - int actual = libc_errno; \ - libc_errno = 0; \ - ASSERT_EQ(actual, expected); \ - } \ + if ((LIBC_MATH & LIBC_MATH_NO_ERRNO) == 0) \ + if (math_errhandling & MATH_ERRNO) { \ + int actual = libc_errno; \ + libc_errno = 0; \ + ASSERT_EQ(actual, expected); \ + } \ } while (0) #define EXPECT_FP_EXCEPTION(expected) \ do { \ - if (math_errhandling & MATH_ERREXCEPT) { \ - EXPECT_EQ( \ - LIBC_NAMESPACE::fputil::test_except( \ - static_cast<int>(FE_ALL_EXCEPT)) & \ - ((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \ - (expected)); \ - } \ + if ((LIBC_MATH & LIBC_MATH_NO_EXCEPT) == 0) \ + if (math_errhandling & MATH_ERREXCEPT) { \ + EXPECT_EQ( \ + LIBC_NAMESPACE::fputil::test_except( \ + static_cast<int>(FE_ALL_EXCEPT)) & \ + ((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \ + (expected)); \ + } \ } while (0) #define ASSERT_FP_EXCEPTION(expected) \ do { \ - if (math_errhandling & MATH_ERREXCEPT) { \ - ASSERT_EQ( \ - LIBC_NAMESPACE::fputil::test_except( \ - static_cast<int>(FE_ALL_EXCEPT)) & \ - ((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \ - (expected)); \ - } \ + if ((LIBC_MATH & LIBC_MATH_NO_EXCEPT) == 0) \ + if (math_errhandling & MATH_ERREXCEPT) { \ + ASSERT_EQ( \ + LIBC_NAMESPACE::fputil::test_except( \ + static_cast<int>(FE_ALL_EXCEPT)) & \ + ((expected) ? (expected) : static_cast<int>(FE_ALL_EXCEPT)), \ + (expected)); \ + } \ } while (0) #define EXPECT_FP_EQ_WITH_EXCEPTION(expected_val, actual_val, expected_except) \ diff --git a/libc/test/src/math/acos_test.cpp b/libc/test/src/math/acos_test.cpp index 1404887..8678fe6 100644 --- a/libc/test/src/math/acos_test.cpp +++ b/libc/test/src/math/acos_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/acos.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 8 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAcosTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -46,7 +53,7 @@ TEST_F(LlvmLibcAcosTest, InDoubleRange) { ++count; if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Acos, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Acos, x, result, tol, rounding_mode)) { diff --git a/libc/test/src/math/acosf16_test.cpp b/libc/test/src/math/acosf16_test.cpp index f4890c81..ca33550 100644 --- a/libc/test/src/math/acosf16_test.cpp +++ b/libc/test/src/math/acosf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/acosf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -28,7 +35,7 @@ TEST_F(LlvmLibcAcosf16Test, PositiveRange) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x, - LIBC_NAMESPACE::acosf16(x), 0.5); + LIBC_NAMESPACE::acosf16(x), TOLERANCE + 0.5); } } @@ -37,6 +44,6 @@ TEST_F(LlvmLibcAcosf16Test, NegativeRange) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x, - LIBC_NAMESPACE::acosf16(x), 0.5); + LIBC_NAMESPACE::acosf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/acosf_test.cpp b/libc/test/src/math/acosf_test.cpp index 3b45749..40b8702 100644 --- a/libc/test/src/math/acosf_test.cpp +++ b/libc/test/src/math/acosf_test.cpp @@ -10,11 +10,18 @@ #include "hdr/math_macros.h" #include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/acosf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + namespace mpfr = LIBC_NAMESPACE::testing::mpfr; using LlvmLibcAcosfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -72,8 +79,8 @@ TEST_F(LlvmLibcAcosfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x, - LIBC_NAMESPACE::acosf(x), 0.5); + LIBC_NAMESPACE::acosf(x), TOLERANCE + 0.5); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, -x, - LIBC_NAMESPACE::acosf(-x), 0.5); + LIBC_NAMESPACE::acosf(-x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/acoshf_test.cpp b/libc/test/src/math/acoshf_test.cpp index 506f176..a0e9b39 100644 --- a/libc/test/src/math/acoshf_test.cpp +++ b/libc/test/src/math/acoshf_test.cpp @@ -10,11 +10,18 @@ #include "hdr/math_macros.h" #include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/acoshf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -68,6 +75,6 @@ TEST_F(LlvmLibcAcoshfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acosh, x, - LIBC_NAMESPACE::acoshf(x), 0.5); + LIBC_NAMESPACE::acoshf(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/asin_test.cpp b/libc/test/src/math/asin_test.cpp index 03ae963..4e36384 100644 --- a/libc/test/src/math/asin_test.cpp +++ b/libc/test/src/math/asin_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/asin.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 6 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAsinTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -47,7 +54,7 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) { ++count; if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Asin, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Asin, x, result, tol, rounding_mode)) { @@ -72,6 +79,7 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) { tlog << " Test Rounding To Nearest...\n"; test(mpfr::RoundingMode::Nearest); +#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS tlog << " Test Rounding Downward...\n"; test(mpfr::RoundingMode::Downward); @@ -80,4 +88,5 @@ TEST_F(LlvmLibcAsinTest, InDoubleRange) { tlog << " Test Rounding Toward Zero...\n"; test(mpfr::RoundingMode::TowardZero); +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS } diff --git a/libc/test/src/math/asinf_test.cpp b/libc/test/src/math/asinf_test.cpp index 824bc1e..20702c5 100644 --- a/libc/test/src/math/asinf_test.cpp +++ b/libc/test/src/math/asinf_test.cpp @@ -11,11 +11,18 @@ #include "hdr/math_macros.h" #include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/asinf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -68,8 +75,8 @@ TEST_F(LlvmLibcAsinfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x, - LIBC_NAMESPACE::asinf(x), 0.5); + LIBC_NAMESPACE::asinf(x), TOLERANCE + 0.5); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, -x, - LIBC_NAMESPACE::asinf(-x), 0.5); + LIBC_NAMESPACE::asinf(-x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/asinhf16_test.cpp b/libc/test/src/math/asinhf16_test.cpp index 929d137..8d0f754 100644 --- a/libc/test/src/math/asinhf16_test.cpp +++ b/libc/test/src/math/asinhf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/asinhf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAsinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -28,7 +35,8 @@ TEST_F(LlvmLibcAsinhf16Test, PositiveRange) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x, - LIBC_NAMESPACE::asinhf16(x), 0.5); + LIBC_NAMESPACE::asinhf16(x), + TOLERANCE + 0.5); } } @@ -37,6 +45,7 @@ TEST_F(LlvmLibcAsinhf16Test, NegativeRange) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x, - LIBC_NAMESPACE::asinhf16(x), 0.5); + LIBC_NAMESPACE::asinhf16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/asinhf_test.cpp b/libc/test/src/math/asinhf_test.cpp index 4681aad..9d9c042 100644 --- a/libc/test/src/math/asinhf_test.cpp +++ b/libc/test/src/math/asinhf_test.cpp @@ -9,11 +9,18 @@ #include "hdr/math_macros.h" #include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/asinhf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAsinhfTest = LIBC_NAMESPACE::testing::FPTest<float>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -68,8 +75,8 @@ TEST_F(LlvmLibcAsinhfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, x, - LIBC_NAMESPACE::asinhf(x), 0.5); + LIBC_NAMESPACE::asinhf(x), TOLERANCE + 0.5); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh, -x, - LIBC_NAMESPACE::asinhf(-x), 0.5); + LIBC_NAMESPACE::asinhf(-x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/atan2f_test.cpp b/libc/test/src/math/atan2f_test.cpp index 50ab382..56b6967 100644 --- a/libc/test/src/math/atan2f_test.cpp +++ b/libc/test/src/math/atan2f_test.cpp @@ -8,11 +8,18 @@ #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/atan2f.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAtan2fTest = LIBC_NAMESPACE::testing::FPTest<float>; using LIBC_NAMESPACE::testing::tlog; @@ -36,16 +43,20 @@ TEST_F(LlvmLibcAtan2fTest, TrickyInputs) { float x = INPUTS[i].x; float y = INPUTS[i].y; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i], - LIBC_NAMESPACE::atan2f(x, y), 0.5); + LIBC_NAMESPACE::atan2f(x, y), + TOLERANCE + 0.5); INPUTS[i].x = -INPUTS[i].x; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i], - LIBC_NAMESPACE::atan2f(-x, y), 0.5); + LIBC_NAMESPACE::atan2f(-x, y), + TOLERANCE + 0.5); INPUTS[i].y = -INPUTS[i].y; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i], - LIBC_NAMESPACE::atan2f(-x, -y), 0.5); + LIBC_NAMESPACE::atan2f(-x, -y), + TOLERANCE + 0.5); INPUTS[i].x = -INPUTS[i].x; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan2, INPUTS[i], - LIBC_NAMESPACE::atan2f(x, -y), 0.5); + LIBC_NAMESPACE::atan2f(x, -y), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/atanf16_test.cpp b/libc/test/src/math/atanf16_test.cpp index fa383e7..e91133f 100644 --- a/libc/test/src/math/atanf16_test.cpp +++ b/libc/test/src/math/atanf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/atanf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcAtanf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcAtanf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x, - LIBC_NAMESPACE::atanf16(x), 0.5); + LIBC_NAMESPACE::atanf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcAtanf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x, - LIBC_NAMESPACE::atanf16(x), 0.5); + LIBC_NAMESPACE::atanf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/cbrt_test.cpp b/libc/test/src/math/cbrt_test.cpp index 2e2de16..61b8583 100644 --- a/libc/test/src/math/cbrt_test.cpp +++ b/libc/test/src/math/cbrt_test.cpp @@ -8,11 +8,18 @@ #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/cbrt.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcCbrtTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -49,7 +56,7 @@ TEST_F(LlvmLibcCbrtTest, InDoubleRange) { ++tested; if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Cbrt, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Cbrt, x, result, ulp, rounding_mode)) { @@ -98,8 +105,8 @@ TEST_F(LlvmLibcCbrtTest, SpecialValues) { for (double v : INPUTS) { double x = FPBits(v).get_val(); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cbrt, x, - LIBC_NAMESPACE::cbrt(x), 0.5); + LIBC_NAMESPACE::cbrt(x), TOLERANCE + 0.5); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cbrt, -x, - LIBC_NAMESPACE::cbrt(-x), 0.5); + LIBC_NAMESPACE::cbrt(-x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/cos_test.cpp b/libc/test/src/math/cos_test.cpp index e2d4791..40c43f9 100644 --- a/libc/test/src/math/cos_test.cpp +++ b/libc/test/src/math/cos_test.cpp @@ -7,11 +7,18 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/cos.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcCosTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -57,7 +64,7 @@ TEST_F(LlvmLibcCosTest, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = INPUTS[i]; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, - LIBC_NAMESPACE::cos(x), 0.5); + LIBC_NAMESPACE::cos(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/cosf16_test.cpp b/libc/test/src/math/cosf16_test.cpp index b744e78..fe6f4ab 100644 --- a/libc/test/src/math/cosf16_test.cpp +++ b/libc/test/src/math/cosf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/cosf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcCosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcCosf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, - LIBC_NAMESPACE::cosf16(x), 0.5); + LIBC_NAMESPACE::cosf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcCosf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, - LIBC_NAMESPACE::cosf16(x), 0.5); + LIBC_NAMESPACE::cosf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp index 6afaa42..d5d5dc3 100644 --- a/libc/test/src/math/cosf_test.cpp +++ b/libc/test/src/math/cosf_test.cpp @@ -10,12 +10,21 @@ #include "hdr/math_macros.h" #include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/cosf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/math/sdcomp26094.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 3 +#define FP_ASSERT ASSERT_MPFR_MATCH +#else +#define TOLERANCE 0 +#define FP_ASSERT ASSERT_MPFR_MATCH_ALL_ROUNDING +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LIBC_NAMESPACE::testing::SDCOMP26094_VALUES; using LlvmLibcCosfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -45,8 +54,8 @@ TEST_F(LlvmLibcCosfTest, InFloatRange) { float x = FPBits(v).get_val(); if (FPBits(v).is_nan() || FPBits(v).is_inf()) continue; - ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, - LIBC_NAMESPACE::cosf(x), 0.5); + FP_ASSERT(mpfr::Operation::Cos, x, LIBC_NAMESPACE::cosf(x), + TOLERANCE + 0.5); } } @@ -99,10 +108,10 @@ TEST_F(LlvmLibcCosfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, - LIBC_NAMESPACE::cosf(x), 0.5); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, -x, - LIBC_NAMESPACE::cosf(-x), 0.5); + FP_ASSERT(mpfr::Operation::Cos, x, LIBC_NAMESPACE::cosf(x), + TOLERANCE + 0.5); + FP_ASSERT(mpfr::Operation::Cos, -x, LIBC_NAMESPACE::cosf(-x), + TOLERANCE + 0.5); } } @@ -111,6 +120,7 @@ TEST_F(LlvmLibcCosfTest, SpecificBitPatterns) { TEST_F(LlvmLibcCosfTest, SDCOMP_26094) { for (uint32_t v : SDCOMP26094_VALUES) { float x = FPBits(v).get_val(); - ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, LIBC_NAMESPACE::cosf(x), 0.5); + FP_ASSERT(mpfr::Operation::Cos, x, LIBC_NAMESPACE::cosf(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/coshf16_test.cpp b/libc/test/src/math/coshf16_test.cpp index a0d1fd2..8e8f55e 100644 --- a/libc/test/src/math/coshf16_test.cpp +++ b/libc/test/src/math/coshf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/coshf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcCoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcCoshf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cosh, x, - LIBC_NAMESPACE::coshf16(x), 0.5); + LIBC_NAMESPACE::coshf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcCoshf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cosh, x, - LIBC_NAMESPACE::coshf16(x), 0.5); + LIBC_NAMESPACE::coshf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/erff_test.cpp b/libc/test/src/math/erff_test.cpp index c40aacf..17ff6c4 100644 --- a/libc/test/src/math/erff_test.cpp +++ b/libc/test/src/math/erff_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/erff.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcErffTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -37,9 +43,9 @@ TEST_F(LlvmLibcErffTest, TrickyInputs) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Erf, x, - LIBC_NAMESPACE::erff(x), 0.5); + LIBC_NAMESPACE::erff(x), TOLERANCE + 0.5); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Erf, -x, - LIBC_NAMESPACE::erff(-x), 0.5); + LIBC_NAMESPACE::erff(-x), TOLERANCE + 0.5); } } @@ -83,10 +89,10 @@ TEST_F(LlvmLibcErffTest, InFloatRange) { } } } - tlog << " Log failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Log failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Erf, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/exp10_test.cpp b/libc/test/src/math/exp10_test.cpp index 2ddcef0..4257dd0 100644 --- a/libc/test/src/math/exp10_test.cpp +++ b/libc/test/src/math/exp10_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/exp10.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExp10Test = LIBC_NAMESPACE::testing::FPTest<double>; @@ -79,7 +85,7 @@ TEST_F(LlvmLibcExp10Test, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x, - LIBC_NAMESPACE::exp10(x), 0.5); + LIBC_NAMESPACE::exp10(x), TOLERANCE + 0.5); } } @@ -112,7 +118,7 @@ TEST_F(LlvmLibcExp10Test, InDoubleRange) { ++count; if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp10, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp10, x, result, tol, rounding_mode)) { @@ -126,10 +132,10 @@ TEST_F(LlvmLibcExp10Test, InDoubleRange) { } } } - tlog << " Exp10 failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Exp10 failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Exp10, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/exp10f16_test.cpp b/libc/test/src/math/exp10f16_test.cpp index fc49331..7bd0850 100644 --- a/libc/test/src/math/exp10f16_test.cpp +++ b/libc/test/src/math/exp10f16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/exp10f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcExp10f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,8 @@ TEST_F(LlvmLibcExp10f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x, - LIBC_NAMESPACE::exp10f16(x), 0.5); + LIBC_NAMESPACE::exp10f16(x), + TOLERANCE + 0.5); } } @@ -35,6 +43,7 @@ TEST_F(LlvmLibcExp10f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x, - LIBC_NAMESPACE::exp10f16(x), 0.5); + LIBC_NAMESPACE::exp10f16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/exp10m1f16_test.cpp b/libc/test/src/math/exp10m1f16_test.cpp index 41bb12f..4ba16e0 100644 --- a/libc/test/src/math/exp10m1f16_test.cpp +++ b/libc/test/src/math/exp10m1f16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/exp10m1f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcExp10m1f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,8 @@ TEST_F(LlvmLibcExp10m1f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x, - LIBC_NAMESPACE::exp10m1f16(x), 0.5); + LIBC_NAMESPACE::exp10m1f16(x), + TOLERANCE + 0.5); } } @@ -35,6 +43,7 @@ TEST_F(LlvmLibcExp10m1f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x, - LIBC_NAMESPACE::exp10m1f16(x), 0.5); + LIBC_NAMESPACE::exp10m1f16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/exp10m1f_test.cpp b/libc/test/src/math/exp10m1f_test.cpp index 009c85d..b41a412 100644 --- a/libc/test/src/math/exp10m1f_test.cpp +++ b/libc/test/src/math/exp10m1f_test.cpp @@ -7,14 +7,20 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/CPP/array.h" #include "src/__support/libc_errno.h" +#include "src/__support/macros/optimization.h" #include "src/math/exp10m1f.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExp10m1fTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -70,7 +76,8 @@ TEST_F(LlvmLibcExp10m1fTest, TrickyInputs) { for (float x : INPUTS) { EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10m1, x, - LIBC_NAMESPACE::exp10m1f(x), 0.5); + LIBC_NAMESPACE::exp10m1f(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/exp2_test.cpp b/libc/test/src/math/exp2_test.cpp index a3dcb58..324cafd 100644 --- a/libc/test/src/math/exp2_test.cpp +++ b/libc/test/src/math/exp2_test.cpp @@ -101,10 +101,10 @@ TEST_F(LlvmLibcExp2Test, InDoubleRange) { } } } - tlog << " Exp2 failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Exp2 failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Exp2, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/exp2f16_test.cpp b/libc/test/src/math/exp2f16_test.cpp index 503d8c2..d28632a 100644 --- a/libc/test/src/math/exp2f16_test.cpp +++ b/libc/test/src/math/exp2f16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/exp2f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcExp2f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcExp2f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x, - LIBC_NAMESPACE::exp2f16(x), 0.5); + LIBC_NAMESPACE::exp2f16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcExp2f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x, - LIBC_NAMESPACE::exp2f16(x), 0.5); + LIBC_NAMESPACE::exp2f16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp index 94141dda..5e5fd69 100644 --- a/libc/test/src/math/exp2f_test.cpp +++ b/libc/test/src/math/exp2f_test.cpp @@ -7,14 +7,20 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/libc_errno.h" +#include "src/__support/macros/optimization.h" #include "src/math/exp2f.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExp2fTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -71,7 +77,7 @@ TEST_F(LlvmLibcExp2fTest, TrickyInputs) { libc_errno = 0; float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x, - LIBC_NAMESPACE::exp2f(x), 0.5); + LIBC_NAMESPACE::exp2f(x), TOLERANCE + 0.5); EXPECT_MATH_ERRNO(0); } } diff --git a/libc/test/src/math/exp2m1f16_test.cpp b/libc/test/src/math/exp2m1f16_test.cpp index bf29911..526484d8 100644 --- a/libc/test/src/math/exp2m1f16_test.cpp +++ b/libc/test/src/math/exp2m1f16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/exp2m1f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcExp2m1f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,8 @@ TEST_F(LlvmLibcExp2m1f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x, - LIBC_NAMESPACE::exp2m1f16(x), 0.5); + LIBC_NAMESPACE::exp2m1f16(x), + TOLERANCE + 0.5); } } @@ -35,6 +43,7 @@ TEST_F(LlvmLibcExp2m1f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x, - LIBC_NAMESPACE::exp2m1f16(x), 0.5); + LIBC_NAMESPACE::exp2m1f16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/exp2m1f_test.cpp b/libc/test/src/math/exp2m1f_test.cpp index 7e9f6b5..16b20d7 100644 --- a/libc/test/src/math/exp2m1f_test.cpp +++ b/libc/test/src/math/exp2m1f_test.cpp @@ -7,15 +7,21 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/libc_errno.h" +#include "src/__support/macros/optimization.h" #include "src/math/exp2m1f.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExp2m1fTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -39,7 +45,7 @@ TEST_F(LlvmLibcExp2m1fTest, TrickyInputs) { for (float x : INPUTS) { EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2m1, x, - LIBC_NAMESPACE::exp2m1f(x), 0.5); + LIBC_NAMESPACE::exp2m1f(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/exp_test.cpp b/libc/test/src/math/exp_test.cpp index 854bb51..5a785fb 100644 --- a/libc/test/src/math/exp_test.cpp +++ b/libc/test/src/math/exp_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/exp.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExpTest = LIBC_NAMESPACE::testing::FPTest<double>; @@ -52,7 +58,7 @@ TEST_F(LlvmLibcExpTest, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x, - LIBC_NAMESPACE::exp(x), 0.5); + LIBC_NAMESPACE::exp(x), TOLERANCE + 0.5); } } @@ -85,7 +91,7 @@ TEST_F(LlvmLibcExpTest, InDoubleRange) { ++count; // ASSERT_MPFR_MATCH(mpfr::Operation::Log, x, result, 0.5); if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Exp, x, result, tol, rounding_mode)) { @@ -99,10 +105,10 @@ TEST_F(LlvmLibcExpTest, InDoubleRange) { } } } - tlog << " Exp failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Exp failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Exp, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/expf16_test.cpp b/libc/test/src/math/expf16_test.cpp index ee89a9c..4ea10ea 100644 --- a/libc/test/src/math/expf16_test.cpp +++ b/libc/test/src/math/expf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/expf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcExpf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcExpf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x, - LIBC_NAMESPACE::expf16(x), 0.5); + LIBC_NAMESPACE::expf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcExpf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x, - LIBC_NAMESPACE::expf16(x), 0.5); + LIBC_NAMESPACE::expf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp index 1695a60..05167b8 100644 --- a/libc/test/src/math/expf_test.cpp +++ b/libc/test/src/math/expf_test.cpp @@ -7,14 +7,20 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/libc_errno.h" +#include "src/__support/macros/optimization.h" #include "src/math/expf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExpfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -94,7 +100,7 @@ TEST_F(LlvmLibcExpfTest, Borderline) { x = FPBits(0xc236bd8cU).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x, - LIBC_NAMESPACE::expf(x), 0.5); + LIBC_NAMESPACE::expf(x), TOLERANCE + 0.5); EXPECT_MATH_ERRNO(0); } diff --git a/libc/test/src/math/expm1_test.cpp b/libc/test/src/math/expm1_test.cpp index c185be9..8ca9b77 100644 --- a/libc/test/src/math/expm1_test.cpp +++ b/libc/test/src/math/expm1_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/expm1.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExpm1Test = LIBC_NAMESPACE::testing::FPTest<double>; @@ -36,9 +42,9 @@ TEST_F(LlvmLibcExpm1Test, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = INPUTS[i]; EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x, - LIBC_NAMESPACE::expm1(x), 0.5); + LIBC_NAMESPACE::expm1(x), TOLERANCE + 0.5); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, -x, - LIBC_NAMESPACE::expm1(-x), 0.5); + LIBC_NAMESPACE::expm1(-x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/expm1f16_test.cpp b/libc/test/src/math/expm1f16_test.cpp index a6a6fcf..952a879 100644 --- a/libc/test/src/math/expm1f16_test.cpp +++ b/libc/test/src/math/expm1f16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/expm1f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcExpm1f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,8 @@ TEST_F(LlvmLibcExpm1f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x, - LIBC_NAMESPACE::expm1f16(x), 0.5); + LIBC_NAMESPACE::expm1f16(x), + TOLERANCE + 0.5); } } @@ -35,6 +43,7 @@ TEST_F(LlvmLibcExpm1f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x, - LIBC_NAMESPACE::expm1f16(x), 0.5); + LIBC_NAMESPACE::expm1f16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp index 28d7106..2f7a9f2 100644 --- a/libc/test/src/math/expm1f_test.cpp +++ b/libc/test/src/math/expm1f_test.cpp @@ -7,14 +7,20 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/libc_errno.h" +#include "src/__support/macros/optimization.h" #include "src/math/expm1f.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcExpm1fTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -93,7 +99,7 @@ TEST_F(LlvmLibcExpm1fTest, Borderline) { x = FPBits(0x3e35bec5U).get_val(); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x, - LIBC_NAMESPACE::expm1f(x), 0.5); + LIBC_NAMESPACE::expm1f(x), TOLERANCE + 0.5); EXPECT_MATH_ERRNO(0); x = FPBits(0x942ed494U).get_val(); @@ -103,7 +109,7 @@ TEST_F(LlvmLibcExpm1fTest, Borderline) { x = FPBits(0xbdc1c6cbU).get_val(); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x, - LIBC_NAMESPACE::expm1f(x), 0.5); + LIBC_NAMESPACE::expm1f(x), TOLERANCE + 0.5); EXPECT_MATH_ERRNO(0); } diff --git a/libc/test/src/math/log10_test.cpp b/libc/test/src/math/log10_test.cpp index 62a19d02..3e48f74 100644 --- a/libc/test/src/math/log10_test.cpp +++ b/libc/test/src/math/log10_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/log10.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLog10Test = LIBC_NAMESPACE::testing::FPTest<double>; @@ -66,7 +72,7 @@ TEST_F(LlvmLibcLog10Test, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x, - LIBC_NAMESPACE::log10(x), 0.5); + LIBC_NAMESPACE::log10(x), TOLERANCE + 0.5); } } @@ -118,10 +124,10 @@ TEST_F(LlvmLibcLog10Test, InDoubleRange) { } } } - tlog << " Log10 failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Log10 failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Log10, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/log10f16_test.cpp b/libc/test/src/math/log10f16_test.cpp index a71e330..0e456dc 100644 --- a/libc/test/src/math/log10f16_test.cpp +++ b/libc/test/src/math/log10f16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/log10f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcLog10f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,8 @@ TEST_F(LlvmLibcLog10f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x, - LIBC_NAMESPACE::log10f16(x), 0.5); + LIBC_NAMESPACE::log10f16(x), + TOLERANCE + 0.5); } } @@ -35,6 +43,7 @@ TEST_F(LlvmLibcLog10f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x, - LIBC_NAMESPACE::log10f16(x), 0.5); + LIBC_NAMESPACE::log10f16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/log10f_test.cpp b/libc/test/src/math/log10f_test.cpp index c554948..1a1bd14 100644 --- a/libc/test/src/math/log10f_test.cpp +++ b/libc/test/src/math/log10f_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/log10f.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLog10fTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -60,7 +66,7 @@ TEST_F(LlvmLibcLog10fTest, TrickyInputs) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log10, x, - LIBC_NAMESPACE::log10f(x), 0.5); + LIBC_NAMESPACE::log10f(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/log1p_test.cpp b/libc/test/src/math/log1p_test.cpp index be83ce8..dd72073 100644 --- a/libc/test/src/math/log1p_test.cpp +++ b/libc/test/src/math/log1p_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/log1p.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLog1pTest = LIBC_NAMESPACE::testing::FPTest<double>; @@ -68,7 +74,7 @@ TEST_F(LlvmLibcLog1pTest, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x, - LIBC_NAMESPACE::log1p(x), 0.5); + LIBC_NAMESPACE::log1p(x), TOLERANCE + 0.5); } } @@ -107,9 +113,8 @@ TEST_F(LlvmLibcLog1pTest, InDoubleRange) { continue; ++count; - // ASSERT_MPFR_MATCH(mpfr::Operation::Log1p, x, result, 0.5); if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Log1p, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Log1p, x, result, tol, rounding_mode)) { @@ -119,10 +124,10 @@ TEST_F(LlvmLibcLog1pTest, InDoubleRange) { } } } - tlog << " Log1p failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Log1p failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Log1p, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/log1pf_test.cpp b/libc/test/src/math/log1pf_test.cpp index 2df4526..ef61f5a 100644 --- a/libc/test/src/math/log1pf_test.cpp +++ b/libc/test/src/math/log1pf_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/log1pf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLog1pfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -63,7 +69,7 @@ TEST_F(LlvmLibcLog1pfTest, TrickyInputs) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log1p, x, - LIBC_NAMESPACE::log1pf(x), 0.5); + LIBC_NAMESPACE::log1pf(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/log2_test.cpp b/libc/test/src/math/log2_test.cpp index 824a8a5..9eada85 100644 --- a/libc/test/src/math/log2_test.cpp +++ b/libc/test/src/math/log2_test.cpp @@ -117,10 +117,10 @@ TEST_F(LlvmLibcLog2Test, InDoubleRange) { } } } - tlog << " Log2 failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Log2 failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Log2, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/log2f16_test.cpp b/libc/test/src/math/log2f16_test.cpp index 6630ca8..d277b12 100644 --- a/libc/test/src/math/log2f16_test.cpp +++ b/libc/test/src/math/log2f16_test.cpp @@ -6,11 +6,17 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/log2f16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLog2f16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +33,7 @@ TEST_F(LlvmLibcLog2f16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x, - LIBC_NAMESPACE::log2f16(x), 0.5); + LIBC_NAMESPACE::log2f16(x), TOLERANCE + 0.5); } } @@ -35,6 +41,6 @@ TEST_F(LlvmLibcLog2f16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x, - LIBC_NAMESPACE::log2f16(x), 0.5); + LIBC_NAMESPACE::log2f16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/log_test.cpp b/libc/test/src/math/log_test.cpp index a68d1687..c9a030a 100644 --- a/libc/test/src/math/log_test.cpp +++ b/libc/test/src/math/log_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/log.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLogTest = LIBC_NAMESPACE::testing::FPTest<double>; @@ -106,7 +112,7 @@ TEST_F(LlvmLibcLogTest, InDoubleRange) { ++count; // ASSERT_MPFR_MATCH(mpfr::Operation::Log, x, result, 0.5); if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Log, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Log, x, result, tol, rounding_mode)) { @@ -116,10 +122,10 @@ TEST_F(LlvmLibcLogTest, InDoubleRange) { } } } - tlog << " Log failed: " << fails << "/" << count << "/" << cc - << " tests.\n"; - tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; if (fails) { + tlog << " Log failed: " << fails << "/" << count << "/" << cc + << " tests.\n"; + tlog << " Max ULPs is at most: " << static_cast<uint64_t>(tol) << ".\n"; EXPECT_MPFR_MATCH(mpfr::Operation::Log, mx, mr, 0.5, rounding_mode); } }; diff --git a/libc/test/src/math/logf16_test.cpp b/libc/test/src/math/logf16_test.cpp index 922918b..70d6304 100644 --- a/libc/test/src/math/logf16_test.cpp +++ b/libc/test/src/math/logf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/logf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcLogf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcLogf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x, - LIBC_NAMESPACE::logf16(x), 0.5); + LIBC_NAMESPACE::logf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcLogf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x, - LIBC_NAMESPACE::logf16(x), 0.5); + LIBC_NAMESPACE::logf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/logf_test.cpp b/libc/test/src/math/logf_test.cpp index 7658075..fb99080 100644 --- a/libc/test/src/math/logf_test.cpp +++ b/libc/test/src/math/logf_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/logf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcLogfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -28,7 +34,11 @@ TEST_F(LlvmLibcLogfTest, SpecialNumbers) { EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::logf(-0.0f), FE_DIVBYZERO); EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::logf(-1.0f), FE_INVALID); +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS + EXPECT_TRUE(0.0f == LIBC_NAMESPACE::logf(1.0f)); +#else EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::logf(1.0f)); +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS } TEST_F(LlvmLibcLogfTest, TrickyInputs) { @@ -73,7 +83,7 @@ TEST_F(LlvmLibcLogfTest, TrickyInputs) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log, x, - LIBC_NAMESPACE::logf(x), 0.5); + LIBC_NAMESPACE::logf(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/powf_test.cpp b/libc/test/src/math/powf_test.cpp index 1d70724..fe8ef4f 100644 --- a/libc/test/src/math/powf_test.cpp +++ b/libc/test/src/math/powf_test.cpp @@ -7,13 +7,19 @@ //===----------------------------------------------------------------------===// #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/powf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcPowfTest = LIBC_NAMESPACE::testing::FPTest<float>; using LIBC_NAMESPACE::testing::tlog; @@ -42,7 +48,7 @@ TEST_F(LlvmLibcPowfTest, TrickyInputs) { float x = INPUTS[i].x; float y = INPUTS[i].y; EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Pow, INPUTS[i], - LIBC_NAMESPACE::powf(x, y), 0.5); + LIBC_NAMESPACE::powf(x, y), TOLERANCE + 0.5); } } @@ -88,7 +94,8 @@ TEST_F(LlvmLibcPowfTest, InFloatRange) { mpfr::BinaryInput<float> inputs{x, y}; if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Pow, inputs, - result, 0.5, rounding_mode)) { + result, TOLERANCE + 0.5, + rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY( mpfr::Operation::Pow, inputs, result, tol, rounding_mode)) { diff --git a/libc/test/src/math/sin_test.cpp b/libc/test/src/math/sin_test.cpp index 4d5d9dd..7eac034 100644 --- a/libc/test/src/math/sin_test.cpp +++ b/libc/test/src/math/sin_test.cpp @@ -7,11 +7,18 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/sin.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcSinTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -46,7 +53,7 @@ TEST_F(LlvmLibcSinTest, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = INPUTS[i]; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sin(x), 0.5); + LIBC_NAMESPACE::sin(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/sincos_test.cpp b/libc/test/src/math/sincos_test.cpp index 09c8715..30bfec6 100644 --- a/libc/test/src/math/sincos_test.cpp +++ b/libc/test/src/math/sincos_test.cpp @@ -7,11 +7,18 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/sincos.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcSincosTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -26,36 +33,36 @@ using LIBC_NAMESPACE::testing::tlog; mpfr::ForceRoundingMode __r1(mpfr::RoundingMode::Nearest); \ if (__r1.success) { \ LIBC_NAMESPACE::sincos(input, &sin_x, &cos_x); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::Nearest); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::Nearest); \ } \ \ mpfr::ForceRoundingMode __r2(mpfr::RoundingMode::Upward); \ if (__r2.success) { \ LIBC_NAMESPACE::sincos(input, &sin_x, &cos_x); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::Upward); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::Upward); \ } \ \ mpfr::ForceRoundingMode __r3(mpfr::RoundingMode::Downward); \ if (__r3.success) { \ LIBC_NAMESPACE::sincos(input, &sin_x, &cos_x); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::Downward); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::Downward); \ } \ \ mpfr::ForceRoundingMode __r4(mpfr::RoundingMode::TowardZero); \ if (__r4.success) { \ LIBC_NAMESPACE::sincos(input, &sin_x, &cos_x); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Sin, input, sin_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::TowardZero); \ - ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, 0.5, \ + ASSERT_MPFR_MATCH(mpfr::Operation::Cos, input, cos_x, TOLERANCE + 0.5, \ mpfr::RoundingMode::TowardZero); \ } \ } while (0) diff --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp index 87e995d..9e6263b 100644 --- a/libc/test/src/math/sincosf_test.cpp +++ b/libc/test/src/math/sincosf_test.cpp @@ -8,14 +8,20 @@ #include "hdr/errno_macros.h" #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/sincosf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/math/sdcomp26094.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcSinCosfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -60,36 +66,36 @@ TEST_F(LlvmLibcSinCosfTest, SpecialNumbers) { mpfr::ForceRoundingMode __r1(mpfr::RoundingMode::Nearest); \ if (__r1.success) { \ LIBC_NAMESPACE::sincosf(input, &sin, &cos); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, TOLERANCE + 0.5, \ mpfr::RoundingMode::Nearest); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, TOLERANCE + 0.5, \ mpfr::RoundingMode::Nearest); \ } \ \ mpfr::ForceRoundingMode __r2(mpfr::RoundingMode::Upward); \ if (__r2.success) { \ LIBC_NAMESPACE::sincosf(input, &sin, &cos); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, TOLERANCE + 0.5, \ mpfr::RoundingMode::Upward); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, TOLERANCE + 0.5, \ mpfr::RoundingMode::Upward); \ } \ \ mpfr::ForceRoundingMode __r3(mpfr::RoundingMode::Downward); \ if (__r3.success) { \ LIBC_NAMESPACE::sincosf(input, &sin, &cos); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, TOLERANCE + 0.5, \ mpfr::RoundingMode::Downward); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, TOLERANCE + 0.5, \ mpfr::RoundingMode::Downward); \ } \ \ mpfr::ForceRoundingMode __r4(mpfr::RoundingMode::TowardZero); \ if (__r4.success) { \ LIBC_NAMESPACE::sincosf(input, &sin, &cos); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, TOLERANCE + 0.5, \ mpfr::RoundingMode::TowardZero); \ - EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5, \ + EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, TOLERANCE + 0.5, \ mpfr::RoundingMode::TowardZero); \ } \ } diff --git a/libc/test/src/math/sinf16_test.cpp b/libc/test/src/math/sinf16_test.cpp index b05501c..d8e9e02 100644 --- a/libc/test/src/math/sinf16_test.cpp +++ b/libc/test/src/math/sinf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/sinf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcSinf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcSinf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf16(x), 0.5); + LIBC_NAMESPACE::sinf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcSinf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf16(x), 0.5); + LIBC_NAMESPACE::sinf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp index 42de7af..516941b 100644 --- a/libc/test/src/math/sinf_test.cpp +++ b/libc/test/src/math/sinf_test.cpp @@ -8,6 +8,7 @@ #include "hdr/errno_macros.h" #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/sinf.h" #include "test/UnitTest/FPMatcher.h" @@ -15,7 +16,13 @@ #include "test/src/math/sdcomp26094.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 3 +#define FP_ASSERT ASSERT_MPFR_MATCH +#else +#define TOLERANCE 0 +#define FP_ASSERT ASSERT_MPFR_MATCH_ALL_ROUNDING +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcSinfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -30,8 +37,13 @@ TEST_F(LlvmLibcSinfTest, SpecialNumbers) { EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::sinf(0.0f)); EXPECT_MATH_ERRNO(0); +// When accuracy is not required, signed zeros might not be preserved. +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS + EXPECT_TRUE(0.0f == LIBC_NAMESPACE::sinf(-0.0f)); +#else EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::sinf(-0.0f)); EXPECT_MATH_ERRNO(0); +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::sinf(inf)); EXPECT_MATH_ERRNO(EDOM); @@ -47,8 +59,8 @@ TEST_F(LlvmLibcSinfTest, InFloatRange) { float x = FPBits(v).get_val(); if (FPBits(v).is_nan() || FPBits(v).is_inf()) continue; - ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf(x), 0.5); + FP_ASSERT(mpfr::Operation::Sin, x, LIBC_NAMESPACE::sinf(x), + TOLERANCE + 0.5); } } @@ -95,22 +107,20 @@ TEST_F(LlvmLibcSinfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf(x), 0.5); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, -x, - LIBC_NAMESPACE::sinf(-x), 0.5); + FP_ASSERT(mpfr::Operation::Sin, x, LIBC_NAMESPACE::sinf(x), + TOLERANCE + 0.5); + FP_ASSERT(mpfr::Operation::Sin, -x, LIBC_NAMESPACE::sinf(-x), + TOLERANCE + 0.5); } } // For small values, sin(x) is x. TEST_F(LlvmLibcSinfTest, SmallValues) { float x = FPBits(0x1780'0000U).get_val(); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf(x), 0.5); + FP_ASSERT(mpfr::Operation::Sin, x, LIBC_NAMESPACE::sinf(x), 0.5); x = FPBits(0x0040'0000U).get_val(); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf(x), 0.5); + FP_ASSERT(mpfr::Operation::Sin, x, LIBC_NAMESPACE::sinf(x), 0.5); } // SDCOMP-26094: check sinf in the cases for which the range reducer @@ -118,7 +128,7 @@ TEST_F(LlvmLibcSinfTest, SmallValues) { TEST_F(LlvmLibcSinfTest, SDCOMP_26094) { for (uint32_t v : SDCOMP26094_VALUES) { float x = FPBits((v)).get_val(); - EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sin, x, - LIBC_NAMESPACE::sinf(x), 0.5); + FP_ASSERT(mpfr::Operation::Sin, x, LIBC_NAMESPACE::sinf(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/sinhf16_test.cpp b/libc/test/src/math/sinhf16_test.cpp index a16ab92..04e0730 100644 --- a/libc/test/src/math/sinhf16_test.cpp +++ b/libc/test/src/math/sinhf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/sinhf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcSinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcSinhf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x, - LIBC_NAMESPACE::sinhf16(x), 0.5); + LIBC_NAMESPACE::sinhf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcSinhf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x, - LIBC_NAMESPACE::sinhf16(x), 0.5); + LIBC_NAMESPACE::sinhf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/sinhf_test.cpp b/libc/test/src/math/sinhf_test.cpp index 6f9ac2f..93a1eec 100644 --- a/libc/test/src/math/sinhf_test.cpp +++ b/libc/test/src/math/sinhf_test.cpp @@ -8,14 +8,20 @@ #include "hdr/errno_macros.h" #include "hdr/math_macros.h" +#include "hdr/stdint_proxy.h" #include "src/__support/CPP/array.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/sinhf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" -#include "hdr/stdint_proxy.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS using LlvmLibcSinhfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -79,9 +85,9 @@ TEST_F(LlvmLibcSinhfTest, Overflow) { TEST_F(LlvmLibcSinhfTest, ExceptionalValues) { float x = FPBits(uint32_t(0x3a12'85ffU)).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x, - LIBC_NAMESPACE::sinhf(x), 0.5); + LIBC_NAMESPACE::sinhf(x), TOLERANCE + 0.5); x = -FPBits(uint32_t(0x3a12'85ffU)).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sinh, x, - LIBC_NAMESPACE::sinhf(x), 0.5); + LIBC_NAMESPACE::sinhf(x), TOLERANCE + 0.5); } diff --git a/libc/test/src/math/smoke/sinf_test.cpp b/libc/test/src/math/smoke/sinf_test.cpp index b0ba81e..7b671c6 100644 --- a/libc/test/src/math/smoke/sinf_test.cpp +++ b/libc/test/src/math/smoke/sinf_test.cpp @@ -10,6 +10,7 @@ #include "hdr/math_macros.h" #include "hdr/stdint_proxy.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/sinf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -26,8 +27,13 @@ TEST_F(LlvmLibcSinfTest, SpecialNumbers) { EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::sinf(0.0f)); EXPECT_MATH_ERRNO(0); +// When accuracy is not required, signed zeros might not be preserved. +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS + EXPECT_TRUE(0.0f == LIBC_NAMESPACE::sinf(-0.0f)); +#else EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::sinf(-0.0f)); EXPECT_MATH_ERRNO(0); +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::sinf(inf)); EXPECT_MATH_ERRNO(EDOM); diff --git a/libc/test/src/math/tan_test.cpp b/libc/test/src/math/tan_test.cpp index 12dfc02..62f8994 100644 --- a/libc/test/src/math/tan_test.cpp +++ b/libc/test/src/math/tan_test.cpp @@ -7,11 +7,18 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/tan.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 4 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcTanTest = LIBC_NAMESPACE::testing::FPTest<double>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -53,9 +60,9 @@ TEST_F(LlvmLibcTanTest, TrickyInputs) { for (int i = 0; i < N; ++i) { double x = INPUTS[i]; ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, x, - LIBC_NAMESPACE::tan(x), 0.5); + LIBC_NAMESPACE::tan(x), TOLERANCE + 0.5); ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, -x, - LIBC_NAMESPACE::tan(-x), 0.5); + LIBC_NAMESPACE::tan(-x), TOLERANCE + 0.5); } } @@ -89,7 +96,7 @@ TEST_F(LlvmLibcTanTest, InDoubleRange) { ++tested; if (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Tan, x, result, - 0.5, rounding_mode)) { + TOLERANCE + 0.5, rounding_mode)) { ++fails; while (!TEST_MPFR_MATCH_ROUNDING_SILENTLY(mpfr::Operation::Tan, x, result, ulp, rounding_mode)) { diff --git a/libc/test/src/math/tanf16_test.cpp b/libc/test/src/math/tanf16_test.cpp index f2e8741..cd4613b 100644 --- a/libc/test/src/math/tanf16_test.cpp +++ b/libc/test/src/math/tanf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/tanf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcTanf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcTanf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, x, - LIBC_NAMESPACE::tanf16(x), 0.5); + LIBC_NAMESPACE::tanf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcTanf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, x, - LIBC_NAMESPACE::tanf16(x), 0.5); + LIBC_NAMESPACE::tanf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/tanf_test.cpp b/libc/test/src/math/tanf_test.cpp index 2202bd6..b384d8c 100644 --- a/libc/test/src/math/tanf_test.cpp +++ b/libc/test/src/math/tanf_test.cpp @@ -9,12 +9,19 @@ #include "hdr/errno_macros.h" #include "hdr/math_macros.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/macros/optimization.h" #include "src/math/tanf.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "test/src/math/sdcomp26094.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + #include "hdr/stdint_proxy.h" using LlvmLibcTanfTest = LIBC_NAMESPACE::testing::FPTest<float>; @@ -114,9 +121,9 @@ TEST_F(LlvmLibcTanfTest, SpecificBitPatterns) { for (int i = 0; i < N; ++i) { float x = FPBits(INPUTS[i]).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, x, - LIBC_NAMESPACE::tanf(x), 0.5); + LIBC_NAMESPACE::tanf(x), TOLERANCE + 0.5); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tan, -x, - LIBC_NAMESPACE::tanf(-x), 0.5); + LIBC_NAMESPACE::tanf(-x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/tanhf16_test.cpp b/libc/test/src/math/tanhf16_test.cpp index 7124a83..ff79604 100644 --- a/libc/test/src/math/tanhf16_test.cpp +++ b/libc/test/src/math/tanhf16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/tanhf16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcTanhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,7 @@ TEST_F(LlvmLibcTanhf16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanh, x, - LIBC_NAMESPACE::tanhf16(x), 0.5); + LIBC_NAMESPACE::tanhf16(x), TOLERANCE + 0.5); } } @@ -35,6 +42,6 @@ TEST_F(LlvmLibcTanhf16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanh, x, - LIBC_NAMESPACE::tanhf16(x), 0.5); + LIBC_NAMESPACE::tanhf16(x), TOLERANCE + 0.5); } } diff --git a/libc/test/src/math/tanpif16_test.cpp b/libc/test/src/math/tanpif16_test.cpp index 04d1f71..f994781 100644 --- a/libc/test/src/math/tanpif16_test.cpp +++ b/libc/test/src/math/tanpif16_test.cpp @@ -6,11 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/optimization.h" #include "src/math/tanpif16.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" +#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS +#define TOLERANCE 1 +#else +#define TOLERANCE 0 +#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS + using LlvmLibcTanpif16Test = LIBC_NAMESPACE::testing::FPTest<float16>; namespace mpfr = LIBC_NAMESPACE::testing::mpfr; @@ -27,7 +34,8 @@ TEST_F(LlvmLibcTanpif16Test, PositiveRange) { for (uint16_t v = POS_START; v <= POS_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanpi, x, - LIBC_NAMESPACE::tanpif16(x), 0.5); + LIBC_NAMESPACE::tanpif16(x), + TOLERANCE + 0.5); } } @@ -35,6 +43,7 @@ TEST_F(LlvmLibcTanpif16Test, NegativeRange) { for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { float16 x = FPBits(v).get_val(); EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Tanpi, x, - LIBC_NAMESPACE::tanpif16(x), 0.5); + LIBC_NAMESPACE::tanpif16(x), + TOLERANCE + 0.5); } } diff --git a/libc/test/src/nl_types/CMakeLists.txt b/libc/test/src/nl_types/CMakeLists.txt index 4fce637..6bafb32 100644 --- a/libc/test/src/nl_types/CMakeLists.txt +++ b/libc/test/src/nl_types/CMakeLists.txt @@ -7,6 +7,7 @@ add_libc_test( SRCS nl_types_test.cpp DEPENDS + libc.include.llvm-libc-macros.nl_types_macros libc.include.llvm-libc-types.nl_catd libc.src.nl_types.catopen libc.src.nl_types.catclose diff --git a/libc/test/src/nl_types/nl_types_test.cpp b/libc/test/src/nl_types/nl_types_test.cpp index 5ae5c5a..7392200 100644 --- a/libc/test/src/nl_types/nl_types_test.cpp +++ b/libc/test/src/nl_types/nl_types_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "include/llvm-libc-macros/nl-types-macros.h" #include "include/llvm-libc-types/nl_catd.h" #include "src/nl_types/catclose.h" #include "src/nl_types/catgets.h" @@ -15,7 +16,7 @@ using LlvmLibcNlTypesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; TEST_F(LlvmLibcNlTypesTest, CatopenFails) { - ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", 0), + ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", NL_CAT_LOCALE), reinterpret_cast<nl_catd>(-1)); ASSERT_ERRNO_EQ(EINVAL); } @@ -28,6 +29,6 @@ TEST_F(LlvmLibcNlTypesTest, CatgetsFails) { const char *message = "message"; // Note that we test for pointer equality here, since catgets // is expected to return the input argument as-is. - ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, 0, 0, message), + ASSERT_EQ(LIBC_NAMESPACE::catgets(nullptr, NL_SETD, 1, message), const_cast<char *>(message)); } |