aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/config/linux/aarch64/entrypoints.txt1
-rw-r--r--libc/config/linux/riscv/entrypoints.txt1
-rw-r--r--libc/config/linux/x86_64/entrypoints.txt6
-rw-r--r--libc/config/linux/x86_64/headers.txt1
-rw-r--r--libc/docs/dev/undefined_behavior.rst7
-rw-r--r--libc/include/CMakeLists.txt12
-rw-r--r--libc/include/arpa/inet.yaml10
-rw-r--r--libc/include/llvm-libc-macros/CMakeLists.txt12
-rw-r--r--libc/include/llvm-libc-macros/annex-k-macros.h27
-rw-r--r--libc/include/llvm-libc-macros/nl-types-macros.h15
-rw-r--r--libc/include/llvm-libc-types/CMakeLists.txt1
-rw-r--r--libc/include/llvm-libc-types/nl_catd.h14
-rw-r--r--libc/include/nl_types.yaml35
-rw-r--r--libc/include/wchar.yaml11
-rw-r--r--libc/src/CMakeLists.txt1
-rw-r--r--libc/src/__support/FPUtil/double_double.h5
-rw-r--r--libc/src/__support/math/CMakeLists.txt1
-rw-r--r--libc/src/__support/math/atan2f.h4
-rw-r--r--libc/src/__support/math/cosf.h30
-rw-r--r--libc/src/__support/math/sincosf_float_eval.h223
-rw-r--r--libc/src/arpa/inet/CMakeLists.txt13
-rw-r--r--libc/src/arpa/inet/inet_aton.cpp57
-rw-r--r--libc/src/arpa/inet/inet_aton.h21
-rw-r--r--libc/src/math/generic/asinpif16.cpp2
-rw-r--r--libc/src/math/generic/sinf.cpp24
-rw-r--r--libc/src/nl_types/CMakeLists.txt31
-rw-r--r--libc/src/nl_types/catclose.cpp22
-rw-r--r--libc/src/nl_types/catclose.h21
-rw-r--r--libc/src/nl_types/catgets.cpp25
-rw-r--r--libc/src/nl_types/catgets.h22
-rw-r--r--libc/src/nl_types/catopen.cpp26
-rw-r--r--libc/src/nl_types/catopen.h21
-rw-r--r--libc/src/wchar/wcsnrtombs.cpp2
-rw-r--r--libc/src/wchar/wcsnrtombs.h2
-rw-r--r--libc/src/wchar/wcsrtombs.cpp2
-rw-r--r--libc/src/wchar/wcsrtombs.h2
-rw-r--r--libc/test/UnitTest/FPMatcher.h53
-rw-r--r--libc/test/src/CMakeLists.txt1
-rw-r--r--libc/test/src/arpa/inet/CMakeLists.txt11
-rw-r--r--libc/test/src/arpa/inet/inet_aton_test.cpp92
-rw-r--r--libc/test/src/math/CMakeLists.txt28
-rw-r--r--libc/test/src/math/acos_test.cpp9
-rw-r--r--libc/test/src/math/acosf16_test.cpp11
-rw-r--r--libc/test/src/math/acosf_test.cpp11
-rw-r--r--libc/test/src/math/acoshf_test.cpp9
-rw-r--r--libc/test/src/math/asin_test.cpp11
-rw-r--r--libc/test/src/math/asinf_test.cpp11
-rw-r--r--libc/test/src/math/asinhf16_test.cpp13
-rw-r--r--libc/test/src/math/asinhf_test.cpp11
-rw-r--r--libc/test/src/math/atan2f_test.cpp19
-rw-r--r--libc/test/src/math/atanf16_test.cpp11
-rw-r--r--libc/test/src/math/cbrt_test.cpp13
-rw-r--r--libc/test/src/math/cos_test.cpp9
-rw-r--r--libc/test/src/math/cosf16_test.cpp11
-rw-r--r--libc/test/src/math/cosf_float_test.cpp35
-rw-r--r--libc/test/src/math/cosf_test.cpp24
-rw-r--r--libc/test/src/math/coshf16_test.cpp11
-rw-r--r--libc/test/src/math/erff_test.cpp18
-rw-r--r--libc/test/src/math/exhaustive/CMakeLists.txt30
-rw-r--r--libc/test/src/math/exhaustive/cosf_float_test.cpp44
-rw-r--r--libc/test/src/math/exhaustive/exhaustive_test.h13
-rw-r--r--libc/test/src/math/exhaustive/sinf_float_test.cpp47
-rw-r--r--libc/test/src/math/exp10_test.cpp18
-rw-r--r--libc/test/src/math/exp10f16_test.cpp13
-rw-r--r--libc/test/src/math/exp10m1f16_test.cpp13
-rw-r--r--libc/test/src/math/exp10m1f_test.cpp11
-rw-r--r--libc/test/src/math/exp2_test.cpp6
-rw-r--r--libc/test/src/math/exp2f16_test.cpp11
-rw-r--r--libc/test/src/math/exp2f_test.cpp10
-rw-r--r--libc/test/src/math/exp2m1f16_test.cpp13
-rw-r--r--libc/test/src/math/exp2m1f_test.cpp10
-rw-r--r--libc/test/src/math/exp_test.cpp18
-rw-r--r--libc/test/src/math/expf16_test.cpp11
-rw-r--r--libc/test/src/math/expf_test.cpp10
-rw-r--r--libc/test/src/math/expm1_test.cpp12
-rw-r--r--libc/test/src/math/expm1f16_test.cpp13
-rw-r--r--libc/test/src/math/expm1f_test.cpp12
-rw-r--r--libc/test/src/math/log10_test.cpp16
-rw-r--r--libc/test/src/math/log10f16_test.cpp13
-rw-r--r--libc/test/src/math/log10f_test.cpp10
-rw-r--r--libc/test/src/math/log1p_test.cpp19
-rw-r--r--libc/test/src/math/log1pf_test.cpp10
-rw-r--r--libc/test/src/math/log2_test.cpp6
-rw-r--r--libc/test/src/math/log2f16_test.cpp10
-rw-r--r--libc/test/src/math/log_test.cpp16
-rw-r--r--libc/test/src/math/logf16_test.cpp11
-rw-r--r--libc/test/src/math/logf_test.cpp14
-rw-r--r--libc/test/src/math/powf_test.cpp13
-rw-r--r--libc/test/src/math/sin_test.cpp9
-rw-r--r--libc/test/src/math/sincos_test.cpp23
-rw-r--r--libc/test/src/math/sincosf_test.cpp24
-rw-r--r--libc/test/src/math/sinf16_test.cpp11
-rw-r--r--libc/test/src/math/sinf_float_test.cpp35
-rw-r--r--libc/test/src/math/sinf_test.cpp36
-rw-r--r--libc/test/src/math/sinhf16_test.cpp11
-rw-r--r--libc/test/src/math/sinhf_test.cpp12
-rw-r--r--libc/test/src/math/smoke/sinf_test.cpp6
-rw-r--r--libc/test/src/math/tan_test.cpp13
-rw-r--r--libc/test/src/math/tanf16_test.cpp11
-rw-r--r--libc/test/src/math/tanf_test.cpp11
-rw-r--r--libc/test/src/math/tanhf16_test.cpp11
-rw-r--r--libc/test/src/math/tanpif16_test.cpp13
-rw-r--r--libc/test/src/nl_types/CMakeLists.txt15
-rw-r--r--libc/test/src/nl_types/nl_types_test.cpp34
104 files changed, 1644 insertions, 216 deletions
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 8bf6c44..714120a 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -945,6 +945,7 @@ if(LLVM_LIBC_FULL_BUILD)
# arpa/inet.h entrypoints
libc.src.arpa.inet.htonl
libc.src.arpa.inet.htons
+ libc.src.arpa.inet.inet_aton
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index dffccba..f6bbb34 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1077,6 +1077,7 @@ if(LLVM_LIBC_FULL_BUILD)
# arpa/inet.h entrypoints
libc.src.arpa.inet.htonl
libc.src.arpa.inet.htons
+ libc.src.arpa.inet.inet_aton
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index b4ab073..7a8d74a 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1113,6 +1113,7 @@ if(LLVM_LIBC_FULL_BUILD)
# arpa/inet.h entrypoints
libc.src.arpa.inet.htonl
libc.src.arpa.inet.htons
+ libc.src.arpa.inet.inet_aton
libc.src.arpa.inet.ntohl
libc.src.arpa.inet.ntohs
@@ -1373,6 +1374,11 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.wchar.wcstombs
libc.src.wchar.wcsrtombs
libc.src.wchar.wcsnrtombs
+
+ # nl_types.h entrypoints
+ libc.src.nl_types.catopen
+ libc.src.nl_types.catclose
+ libc.src.nl_types.catgets
)
endif()
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 0573851..d0f62eb 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -19,6 +19,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.malloc
libc.include.math
libc.include.netinet_in
+ libc.include.nl_types
libc.include.poll
libc.include.pthread
libc.include.sched
diff --git a/libc/docs/dev/undefined_behavior.rst b/libc/docs/dev/undefined_behavior.rst
index aeeaf17..4f8ac22 100644
--- a/libc/docs/dev/undefined_behavior.rst
+++ b/libc/docs/dev/undefined_behavior.rst
@@ -156,3 +156,10 @@ parsed as normal. For l64a it's unspecified what happens if the input value is
negative. For LLVM-libc, all inputs to l64a are treated as unsigned 32 bit ints.
Additionally, the return of l64a is in a thread-local buffer that's overwritten
on each call.
+
+`inet_aton` and Non-Standard Binary Integers
+--------------------------------------------
+The current implementation of the `inet_aton` function utilizes the same code
+as `strtol` to parse IPv4 numbers-and-dots notations. This approach may permit
+the use of binary integers (prefixed with 0b), which is not supported by the
+standard.
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 81360aa..a277690 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -218,6 +218,9 @@ add_header_macro(
DEPENDS
.llvm_libc_common_h
.llvm-libc-macros.complex_macros
+ .llvm-libc-types.float128
+ .llvm-libc-types.cfloat128
+ .llvm-libc-types.cfloat16
)
add_header_macro(
@@ -768,6 +771,15 @@ add_header_macro(
.llvm-libc-macros.poll-macros
)
+add_header_macro(
+ nl_types
+ ../libc/include/nl_types.yaml
+ nl_types.h
+ DEPENDS
+ .llvm-libc-macros.nl_types_macros
+ .llvm-libc-types.nl_catd
+ )
+
# UEFI spec references "Uefi.h" so we use that name for compatibility
add_header_macro(
uefi
diff --git a/libc/include/arpa/inet.yaml b/libc/include/arpa/inet.yaml
index 10cd56d..6e06290 100644
--- a/libc/include/arpa/inet.yaml
+++ b/libc/include/arpa/inet.yaml
@@ -1,7 +1,8 @@
header: arpa/inet.h
header_template: inet.h.def
macros: []
-types: []
+types:
+ - type_name: in_addr
enums: []
objects: []
functions:
@@ -17,6 +18,13 @@ functions:
return_type: uint16_t
arguments:
- type: uint16_t
+ - name: inet_aton
+ standards:
+ - llvm_libc_ext
+ return_type: int
+ arguments:
+ - type: const char *
+ - type: in_addr *
- name: ntohl
standards:
- POSIX
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/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 5f506c4..a428a0e 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -46,6 +46,7 @@ add_header(mbstate_t HDR mbstate_t.h)
add_header(mode_t HDR mode_t.h)
add_header(mtx_t HDR mtx_t.h DEPENDS .__futex_word .__mutex_type)
add_header(nfds_t HDR nfds_t.h)
+add_header(nl_catd HDR nl_catd.h)
add_header(nlink_t HDR nlink_t.h)
add_header(off_t HDR off_t.h)
add_header(once_flag HDR once_flag.h DEPENDS .__futex_word)
diff --git a/libc/include/llvm-libc-types/nl_catd.h b/libc/include/llvm-libc-types/nl_catd.h
new file mode 100644
index 0000000..ccdb020
--- /dev/null
+++ b/libc/include/llvm-libc-types/nl_catd.h
@@ -0,0 +1,14 @@
+//===-- Definition of nl_catd type ----------------------------------------===//
+//
+// 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_TYPES_NL_CATD_H
+#define LLVM_LIBC_TYPES_NL_CATD_H
+
+typedef void *nl_catd;
+
+#endif // LLVM_LIBC_TYPES_NL_CATD_H
diff --git a/libc/include/nl_types.yaml b/libc/include/nl_types.yaml
new file mode 100644
index 0000000..bdb59a8
--- /dev/null
+++ b/libc/include/nl_types.yaml
@@ -0,0 +1,35 @@
+header: nl_types.h
+standards:
+ - posix
+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: []
+objects: []
+functions:
+ - name: catopen
+ standards:
+ - posix
+ return_type: nl_catd
+ arguments:
+ - type: const char *
+ - type: int
+ - name: catclose
+ standards:
+ - posix
+ return_type: int
+ arguments:
+ - type: nl_catd
+ - name: catgets
+ standards:
+ - posix
+ return_type: char *
+ arguments:
+ - type: nl_catd
+ - type: int
+ - type: int
+ - type: const char*
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/CMakeLists.txt b/libc/src/CMakeLists.txt
index d7a1e1f..b2afe0a 100644
--- a/libc/src/CMakeLists.txt
+++ b/libc/src/CMakeLists.txt
@@ -37,6 +37,7 @@ add_subdirectory(arpa)
add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(locale)
+add_subdirectory(nl_types)
add_subdirectory(search)
add_subdirectory(setjmp)
add_subdirectory(signal)
diff --git a/libc/src/__support/FPUtil/double_double.h b/libc/src/__support/FPUtil/double_double.h
index 9affced..3913f7a 100644
--- a/libc/src/__support/FPUtil/double_double.h
+++ b/libc/src/__support/FPUtil/double_double.h
@@ -144,8 +144,9 @@ LIBC_INLINE NumberPair<T> exact_mult(T a, T b) {
return r;
}
-LIBC_INLINE DoubleDouble quick_mult(double a, const DoubleDouble &b) {
- DoubleDouble r = exact_mult(a, b.hi);
+template <typename T = double>
+LIBC_INLINE NumberPair<T> quick_mult(T a, const NumberPair<T> &b) {
+ NumberPair<T> r = exact_mult(a, b.hi);
r.lo = multiply_add(a, b.lo, r.lo);
return r;
}
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 47bb328..6209000 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -926,6 +926,7 @@ add_header_library(
sincosf_utils
HDRS
sincosf_utils.h
+ sincosf_float_eval.h
DEPENDS
.range_reduction
libc.src.__support.FPUtil.fp_bits
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/__support/math/cosf.h b/libc/src/__support/math/cosf.h
index 074be0b..48ba71a 100644
--- a/libc/src/__support/math/cosf.h
+++ b/libc/src/__support/math/cosf.h
@@ -9,7 +9,6 @@
#ifndef LIBC_SRC___SUPPORT_MATH_COSF_H
#define LIBC_SRC___SUPPORT_MATH_COSF_H
-#include "sincosf_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/except_value_utils.h"
@@ -18,6 +17,26 @@
#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_TARGET_CPU_HAS_FMA_FLOAT)
+
+#include "sincosf_float_eval.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE static constexpr float cosf(float x) {
+ return sincosf_float_eval::sincosf_eval</*IS_SIN*/ false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#else // !LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT
+
+#include "sincosf_utils.h"
+
namespace LIBC_NAMESPACE_DECL {
namespace math {
@@ -51,7 +70,6 @@ LIBC_INLINE static constexpr float cosf(float x) {
xbits.set_sign(Sign::POS);
uint32_t x_abs = xbits.uintval();
- double xd = static_cast<double>(xbits.get_val());
// Range reduction:
// For |x| > pi/16, we perform range reduction as follows:
@@ -90,6 +108,7 @@ LIBC_INLINE static constexpr float cosf(float x) {
// computed using degree-7 and degree-6 minimax polynomials generated by
// Sollya respectively.
+#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
// |x| < 0x1.0p-12f
if (LIBC_UNLIKELY(x_abs < 0x3980'0000U)) {
// When |x| < 2^-12, the relative error of the approximation cos(x) ~ 1
@@ -108,12 +127,12 @@ LIBC_INLINE static constexpr float cosf(float x) {
// emulated version of FMA.
#if defined(LIBC_TARGET_CPU_HAS_FMA_FLOAT)
return fputil::multiply_add(xbits.get_val(), -0x1.0p-25f, 1.0f);
-#else
+#else // !LIBC_TARGET_CPU_HAS_FMA_FLOAT
+ double xd = static_cast<double>(xbits.get_val());
return static_cast<float>(fputil::multiply_add(xd, -0x1.0p-25, 1.0));
#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
}
-#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
if (auto r = COSF_EXCEPTS.lookup(x_abs); LIBC_UNLIKELY(r.has_value()))
return r.value();
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
@@ -132,6 +151,7 @@ LIBC_INLINE static constexpr float cosf(float x) {
return x + FPBits::quiet_nan().get_val();
}
+ double xd = static_cast<double>(xbits.get_val());
// Combine the results with the sine of sum formula:
// cos(x) = cos((k + y)*pi/32)
// = cos(y*pi/32) * cos(k*pi/32) - sin(y*pi/32) * sin(k*pi/32)
@@ -150,3 +170,5 @@ LIBC_INLINE static constexpr float cosf(float x) {
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_SRC___SUPPORT_MATH_COSF_H
+
+#endif // LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT
diff --git a/libc/src/__support/math/sincosf_float_eval.h b/libc/src/__support/math/sincosf_float_eval.h
new file mode 100644
index 0000000..836e928
--- /dev/null
+++ b/libc/src/__support/math/sincosf_float_eval.h
@@ -0,0 +1,223 @@
+//===-- Compute sin + cos for small angles ----------------------*- C++ -*-===//
+//
+// 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_SRC___SUPPORT_MATH_SINCOSF_FLOAT_EVAL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SINCOSF_FLOAT_EVAL_H
+
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/double_double.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/nearest_integer.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+namespace sincosf_float_eval {
+
+// Since the worst case of `x mod pi` in single precision is > 2^-28, in order
+// to be bounded by 1 ULP, the range reduction accuracy will need to be at
+// least 2^(-28 - 23) = 2^-51.
+// For fast small range reduction, we will compute as follow:
+// Let pi ~ c0 + c1 + c2
+// with |c1| < ulp(c0)/2 and |c2| < ulp(c1)/2
+// then:
+// k := nearest_int(x * 1/pi);
+// u = (x - k * c0) - k * c1 - k * c2
+// We requires k * c0, k * c1 to be exactly representable in single precision.
+// Let p_k be the precision of k, then the precision of c0 and c1 are:
+// 24 - p_k,
+// and the ulp of (k * c2) is 2^(-3 * (24 - p_k)).
+// This give us the following bound on the precision of k:
+// 3 * (24 - p_k) >= 51,
+// or equivalently:
+// p_k <= 7.
+// We set the bound for p_k to be 6 so that we can have some more wiggle room
+// for computations.
+LIBC_INLINE static unsigned sincosf_range_reduction_small(float x, float &u) {
+ // > display=hexadecimal;
+ // > a = round(pi/8, 18, RN);
+ // > b = round(pi/8 - a, 18, RN);
+ // > c = round(pi/8 - a - b, SG, RN);
+ // > round(8/pi, SG, RN);
+ constexpr float MPI[3] = {-0x1.921f8p-2f, -0x1.aa22p-21f, -0x1.68c234p-41f};
+ constexpr float ONE_OVER_PI = 0x1.45f306p+1f;
+ float prod_hi = x * ONE_OVER_PI;
+ float k = fputil::nearest_integer(prod_hi);
+
+ float y_hi = fputil::multiply_add(k, MPI[0], x); // Exact
+ u = fputil::multiply_add(k, MPI[1], y_hi);
+ u = fputil::multiply_add(k, MPI[2], u);
+ return static_cast<unsigned>(static_cast<int>(k));
+}
+
+// TODO: Add non-FMA version of large range reduction.
+LIBC_INLINE static unsigned sincosf_range_reduction_large(float x, float &u) {
+ // > for i from 0 to 13 do {
+ // if i < 2 then { pi_inv = 0.25 + 2^(8*(i - 2)) / pi; }
+ // else { pi_inv = 2^(8*(i-2)) / pi; };
+ // pn = nearestint(pi_inv);
+ // pi_frac = pi_inv - pn;
+ // a = round(pi_frac, SG, RN);
+ // b = round(pi_frac - a, SG, RN);
+ // c = round(pi_frac - a - b, SG, RN);
+ // d = round(pi_frac - a - b - c, SG, RN);
+ // print("{", 2^3 * a, ",", 2^3 * b, ",", 2^3 * c, ",", 2^3 * d, "},");
+ // };
+ constexpr float EIGHT_OVER_PI[14][4] = {
+ {0x1.000146p1f, -0x1.9f246cp-28f, -0x1.bbead6p-54f, -0x1.ec5418p-85f},
+ {0x1.0145f4p1f, -0x1.f246c6p-24f, -0x1.df56bp-49f, -0x1.ec5418p-77f},
+ {0x1.45f306p1f, 0x1.b9391p-24f, 0x1.529fc2p-50f, 0x1.d5f47ep-76f},
+ {0x1.f306dcp1f, 0x1.391054p-24f, 0x1.4fe13ap-49f, 0x1.7d1f54p-74f},
+ {-0x1.f246c6p0f, -0x1.df56bp-25f, -0x1.ec5418p-53f, 0x1.f534dep-78f},
+ {-0x1.236378p1f, 0x1.529fc2p-26f, 0x1.d5f47ep-52f, -0x1.65912p-77f},
+ {0x1.391054p0f, 0x1.4fe13ap-25f, 0x1.7d1f54p-50f, -0x1.6447e4p-75f},
+ {0x1.1054a8p0f, -0x1.ec5418p-29f, 0x1.f534dep-54f, -0x1.f924ecp-81f},
+ {0x1.529fc2p-2f, 0x1.d5f47ep-28f, -0x1.65912p-53f, 0x1.b6c52cp-79f},
+ {-0x1.ac07b2p1f, 0x1.5f47d4p-24f, 0x1.a6ee06p-49f, 0x1.b6295ap-74f},
+ {-0x1.ec5418p-5f, 0x1.f534dep-30f, -0x1.f924ecp-57f, 0x1.5993c4p-82f},
+ {0x1.3abe9p-1f, -0x1.596448p-27f, 0x1.b6c52cp-55f, -0x1.9b0ef2p-80f},
+ {-0x1.505c16p1f, 0x1.a6ee06p-25f, 0x1.b6295ap-50f, -0x1.b0ef1cp-76f},
+ {-0x1.70565ap-1f, 0x1.dc0db6p-26f, 0x1.4acc9ep-53f, 0x1.0e4108p-80f},
+ };
+
+ using FPBits = typename fputil::FPBits<float>;
+ using fputil::FloatFloat;
+ FPBits xbits(x);
+
+ int x_e_m32 = xbits.get_biased_exponent() - (FPBits::EXP_BIAS + 32);
+ unsigned idx = static_cast<unsigned>((x_e_m32 >> 3) + 2);
+ // Scale x down by 2^(-(8 * (idx - 2))
+ xbits.set_biased_exponent((x_e_m32 & 7) + FPBits::EXP_BIAS + 32);
+ // 2^32 <= |x_reduced| < 2^(32 + 8) = 2^40
+ float x_reduced = xbits.get_val();
+ // x * c_hi = ph.hi + ph.lo exactly.
+ FloatFloat ph = fputil::exact_mult<float>(x_reduced, EIGHT_OVER_PI[idx][0]);
+ // x * c_mid = pm.hi + pm.lo exactly.
+ FloatFloat pm = fputil::exact_mult<float>(x_reduced, EIGHT_OVER_PI[idx][1]);
+ // x * c_lo = pl.hi + pl.lo exactly.
+ FloatFloat pl = fputil::exact_mult<float>(x_reduced, EIGHT_OVER_PI[idx][2]);
+ // Extract integral parts and fractional parts of (ph.lo + pm.hi).
+ float sum_hi = ph.lo + pm.hi;
+ float k = fputil::nearest_integer(sum_hi);
+
+ // x * 8/pi mod 1 ~ y_hi + y_mid + y_lo
+ float y_hi = (ph.lo - k) + pm.hi; // Exact
+ FloatFloat y_mid = fputil::exact_add(pm.lo, pl.hi);
+ float y_lo = pl.lo;
+
+ // y_l = x * c_lo_2 + pl.lo
+ float y_l = fputil::multiply_add(x_reduced, EIGHT_OVER_PI[idx][3], y_lo);
+ FloatFloat y = fputil::exact_add(y_hi, y_mid.hi);
+ y.lo += (y_mid.lo + y_l);
+
+ // Digits of pi/8, generated by Sollya with:
+ // > a = round(pi/8, SG, RN);
+ // > b = round(pi/8 - SG, D, RN);
+ constexpr FloatFloat PI_OVER_8 = {-0x1.777a5cp-27f, 0x1.921fb6p-2f};
+
+ // Error bound: with {a} denote the fractional part of a, i.e.:
+ // {a} = a - round(a)
+ // Then,
+ // | {x * 8/pi} - (y_hi + y_lo) | <= ulp(ulp(y_hi)) <= 2^-47
+ // | {x mod pi/8} - (u.hi + u.lo) | < 2 * 2^-5 * 2^-47 = 2^-51
+ u = fputil::multiply_add(y.hi, PI_OVER_8.hi, y.lo * PI_OVER_8.hi);
+
+ return static_cast<unsigned>(static_cast<int>(k));
+}
+
+template <bool IS_SIN> LIBC_INLINE static float sincosf_eval(float x) {
+ // sin(k * pi/8) for k = 0..15, generated by Sollya with:
+ // > for k from 0 to 16 do {
+ // print(round(sin(k * pi/8), SG, RN));
+ // };
+ constexpr float SIN_K_PI_OVER_8[16] = {
+ 0.0f, 0x1.87de2ap-2f, 0x1.6a09e6p-1f, 0x1.d906bcp-1f,
+ 1.0f, 0x1.d906bcp-1f, 0x1.6a09e6p-1f, 0x1.87de2ap-2f,
+ 0.0f, -0x1.87de2ap-2f, -0x1.6a09e6p-1f, -0x1.d906bcp-1f,
+ -1.0f, -0x1.d906bcp-1f, -0x1.6a09e6p-1f, -0x1.87de2ap-2f,
+ };
+
+ using FPBits = fputil::FPBits<float>;
+ FPBits xbits(x);
+ uint32_t x_abs = cpp::bit_cast<uint32_t>(x) & 0x7fff'ffffU;
+
+ float y;
+ unsigned k = 0;
+ if (x_abs < 0x4880'0000U) {
+ k = sincosf_range_reduction_small(x, y);
+ } else {
+
+ if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
+ if (xbits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+
+ if (x_abs == 0x7f80'0000U) {
+ fputil::set_errno_if_required(EDOM);
+ fputil::raise_except_if_required(FE_INVALID);
+ }
+ return x + FPBits::quiet_nan().get_val();
+ }
+
+ k = sincosf_range_reduction_large(x, y);
+ }
+
+ float sin_k = SIN_K_PI_OVER_8[k & 15];
+ // cos(k * pi/8) = sin(k * pi/8 + pi/2) = sin((k + 4) * pi/8).
+ // cos_k = cos(k * pi/8)
+ float cos_k = SIN_K_PI_OVER_8[(k + 4) & 15];
+
+ float y_sq = y * y;
+
+ // Polynomial approximation of sin(y) and cos(y) for |y| <= pi/16:
+ //
+ // Using Taylor polynomial for sin(y):
+ // sin(y) ~ y - y^3 / 6 + y^5 / 120
+ // Using minimax polynomial generated by Sollya for cos(y) with:
+ // > Q = fpminimax(cos(x), [|0, 2, 4|], [|1, SG...|], [0, pi/16]);
+ //
+ // Error bounds:
+ // * For sin(y)
+ // > P = x - SG(1/6)*x^3 + SG(1/120) * x^5;
+ // > dirtyinfnorm((sin(x) - P)/sin(x), [-pi/16, pi/16]);
+ // 0x1.825...p-27
+ // * For cos(y)
+ // > Q = fpminimax(cos(x), [|0, 2, 4|], [|1, SG...|], [0, pi/16]);
+ // > dirtyinfnorm((sin(x) - P)/sin(x), [-pi/16, pi/16]);
+ // 0x1.aa8...p-29
+
+ // p1 = y^2 * 1/120 - 1/6
+ float p1 = fputil::multiply_add(y_sq, 0x1.111112p-7f, -0x1.555556p-3f);
+ // q1 = y^2 * coeff(Q, 4) + coeff(Q, 2)
+ float q1 = fputil::multiply_add(y_sq, 0x1.54b8bep-5f, -0x1.ffffc4p-2f);
+ float y3 = y_sq * y;
+ // c1 ~ cos(y)
+ float c1 = fputil::multiply_add(y_sq, q1, 1.0f);
+ // s1 ~ sin(y)
+ float s1 = fputil::multiply_add(y3, p1, y);
+
+ if constexpr (IS_SIN) {
+ // sin(x) = cos(k * pi/8) * sin(y) + sin(k * pi/8) * cos(y).
+ return fputil::multiply_add(cos_k, s1, sin_k * c1);
+ } else {
+ // cos(x) = cos(k * pi/8) * cos(y) - sin(k * pi/8) * sin(y).
+ return fputil::multiply_add(cos_k, c1, -sin_k * s1);
+ }
+}
+
+} // namespace sincosf_float_eval
+
+} // namespace math
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SINCOSF_FLOAT_EVAL_H
diff --git a/libc/src/arpa/inet/CMakeLists.txt b/libc/src/arpa/inet/CMakeLists.txt
index 1f39a07..bb43e24 100644
--- a/libc/src/arpa/inet/CMakeLists.txt
+++ b/libc/src/arpa/inet/CMakeLists.txt
@@ -23,6 +23,19 @@ add_entrypoint_object(
)
add_entrypoint_object(
+ inet_aton
+ SRCS
+ inet_aton.cpp
+ HDRS
+ inet_aton.h
+ DEPENDS
+ libc.include.arpa_inet
+ libc.include.llvm-libc-types.in_addr
+ libc.src.__support.common
+ libc.src.__support.str_to_integer
+)
+
+add_entrypoint_object(
ntohl
SRCS
ntohl.cpp
diff --git a/libc/src/arpa/inet/inet_aton.cpp b/libc/src/arpa/inet/inet_aton.cpp
new file mode 100644
index 0000000..71419cb
--- /dev/null
+++ b/libc/src/arpa/inet/inet_aton.cpp
@@ -0,0 +1,57 @@
+//===-- Implementation of inet_aton function ------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/arpa/inet/inet_aton.h"
+#include "src/__support/common.h"
+#include "src/__support/endian_internal.h"
+#include "src/__support/str_to_integer.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, inet_aton, (const char *cp, in_addr *inp)) {
+ constexpr int IPV4_MAX_DOT_NUM = 3;
+ unsigned long parts[IPV4_MAX_DOT_NUM + 1] = {0};
+ int dot_num = 0;
+
+ for (; dot_num <= IPV4_MAX_DOT_NUM; ++dot_num) {
+ auto result = internal::strtointeger<unsigned long>(cp, 0);
+ parts[dot_num] = result;
+
+ if (result.has_error() || result.parsed_len == 0)
+ return 0;
+ char next_char = *(cp + result.parsed_len);
+ if (next_char != '.' && next_char != '\0')
+ return 0;
+ else if (next_char == '\0')
+ break;
+ else
+ cp += (result.parsed_len + 1);
+ }
+
+ if (dot_num > IPV4_MAX_DOT_NUM)
+ return 0;
+
+ // converts the Internet host address cp from the IPv4 numbers-and-dots
+ // notation (a[.b[.c[.d]]]) into binary form (in network byte order)
+ unsigned long result = 0;
+ for (int i = 0; i <= dot_num; ++i) {
+ unsigned long max_part =
+ i == dot_num ? (0xffffffffUL >> (8 * dot_num)) : 0xffUL;
+ if (parts[i] > max_part)
+ return 0;
+ int shift = i == dot_num ? 0 : 8 * (IPV4_MAX_DOT_NUM - i);
+ result |= parts[i] << shift;
+ }
+
+ if (inp)
+ inp->s_addr = Endian::to_big_endian(static_cast<uint32_t>(result));
+
+ return 1;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/arpa/inet/inet_aton.h b/libc/src/arpa/inet/inet_aton.h
new file mode 100644
index 0000000..ea387d1
--- /dev/null
+++ b/libc/src/arpa/inet/inet_aton.h
@@ -0,0 +1,21 @@
+//===-- Implementation header of inet_aton ----------------------*- C++ -*-===//
+//
+// 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_SRC_ARPA_INET_INET_ATON_H
+#define LLVM_LIBC_SRC_ARPA_INET_INET_ATON_H
+
+#include "include/llvm-libc-types/in_addr.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int inet_aton(const char *cp, in_addr *inp);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_ARPA_INET_INET_ATON_H
diff --git a/libc/src/math/generic/asinpif16.cpp b/libc/src/math/generic/asinpif16.cpp
index aabc086..395f4c4 100644
--- a/libc/src/math/generic/asinpif16.cpp
+++ b/libc/src/math/generic/asinpif16.cpp
@@ -77,7 +77,7 @@ LLVM_LIBC_FUNCTION(float16, asinpif16, (float16 x)) {
};
// polynomial evaluation using horner's method
// work only for |x| in [0, 0.5]
- auto asinpi_polyeval = [](double x) -> double {
+ auto asinpi_polyeval = [&](double x) -> double {
return x * fputil::polyeval(x * x, POLY_COEFFS[0], POLY_COEFFS[1],
POLY_COEFFS[2], POLY_COEFFS[3], POLY_COEFFS[4],
POLY_COEFFS[5], POLY_COEFFS[6], POLY_COEFFS[7]);
diff --git a/libc/src/math/generic/sinf.cpp b/libc/src/math/generic/sinf.cpp
index a8e634c..c362628 100644
--- a/libc/src/math/generic/sinf.cpp
+++ b/libc/src/math/generic/sinf.cpp
@@ -17,13 +17,30 @@
#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_TARGET_CPU_HAS_FMA_FLOAT)
+
+#include "src/__support/math/sincosf_float_eval.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, sinf, (float x)) {
+ return math::sincosf_float_eval::sincosf_eval</*IS_SIN*/ true>(x);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#else // !LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT
+
#include "src/__support/math/sincosf_utils.h"
-#if defined(LIBC_TARGET_CPU_HAS_FMA_DOUBLE)
+#ifdef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
#include "src/__support/math/range_reduction_fma.h"
-#else
+#else // !LIBC_TARGET_CPU_HAS_FMA_DOUBLE
#include "src/__support/math/range_reduction.h"
-#endif
+#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
namespace LIBC_NAMESPACE_DECL {
@@ -162,3 +179,4 @@ LLVM_LIBC_FUNCTION(float, sinf, (float x)) {
}
} // namespace LIBC_NAMESPACE_DECL
+#endif // LIBC_MATH_HAS_INTERMEDIATE_COMP_IN_FLOAT
diff --git a/libc/src/nl_types/CMakeLists.txt b/libc/src/nl_types/CMakeLists.txt
new file mode 100644
index 0000000..9783e0e
--- /dev/null
+++ b/libc/src/nl_types/CMakeLists.txt
@@ -0,0 +1,31 @@
+add_entrypoint_object(
+ catopen
+ SRCS
+ catopen.cpp
+ HDRS
+ catopen.h
+ DEPENDS
+ libc.include.llvm-libc-types.nl_catd
+ libc.src.errno.errno
+)
+
+add_entrypoint_object(
+ catclose
+ SRCS
+ catclose.cpp
+ HDRS
+ catclose.h
+ DEPENDS
+ libc.include.llvm-libc-types.nl_catd
+)
+
+add_entrypoint_object(
+ catgets
+ SRCS
+ catgets.cpp
+ HDRS
+ catgets.h
+ DEPENDS
+ libc.include.llvm-libc-types.nl_catd
+)
+
diff --git a/libc/src/nl_types/catclose.cpp b/libc/src/nl_types/catclose.cpp
new file mode 100644
index 0000000..1f87900d
--- /dev/null
+++ b/libc/src/nl_types/catclose.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of catclose ----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/nl_types/catclose.h"
+#include "include/llvm-libc-types/nl_catd.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, catclose, ([[maybe_unused]] nl_catd catalog)) {
+ // TODO: Add implementation for message catalogs. For now, return error
+ // regardless of input.
+ return -1;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/nl_types/catclose.h b/libc/src/nl_types/catclose.h
new file mode 100644
index 0000000..433020a
--- /dev/null
+++ b/libc/src/nl_types/catclose.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for catclose ----------------------*- C++ -*-===//
+//
+// 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_SRC_NL_TYPES_CATCLOSE_H
+#define LLVM_LIBC_SRC_NL_TYPES_CATCLOSE_H
+
+#include "include/llvm-libc-types/nl_catd.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int catclose(nl_catd catalog);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_NL_TYPES_CATCLOSE_H
diff --git a/libc/src/nl_types/catgets.cpp b/libc/src/nl_types/catgets.cpp
new file mode 100644
index 0000000..3768977
--- /dev/null
+++ b/libc/src/nl_types/catgets.cpp
@@ -0,0 +1,25 @@
+//===-- Implementation of catgets -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/nl_types/catgets.h"
+#include "include/llvm-libc-types/nl_catd.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(char *, catgets,
+ ([[maybe_unused]] nl_catd catalog,
+ [[maybe_unused]] int set_number,
+ [[maybe_unused]] int message_number, const char *message)) {
+ // TODO: Add implementation for message catalogs. For now, return backup
+ // message regardless of input.
+ return const_cast<char *>(message);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/nl_types/catgets.h b/libc/src/nl_types/catgets.h
new file mode 100644
index 0000000..c909bec
--- /dev/null
+++ b/libc/src/nl_types/catgets.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for catgets -----------------------*- C++ -*-===//
+//
+// 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_SRC_NL_TYPES_CATGETS_H
+#define LLVM_LIBC_SRC_NL_TYPES_CATGETS_H
+
+#include "include/llvm-libc-types/nl_catd.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+char *catgets(nl_catd catalog, int set_number, int message_number,
+ const char *message);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_NL_TYPES_CATGETS_H
diff --git a/libc/src/nl_types/catopen.cpp b/libc/src/nl_types/catopen.cpp
new file mode 100644
index 0000000..393d760
--- /dev/null
+++ b/libc/src/nl_types/catopen.cpp
@@ -0,0 +1,26 @@
+//===-- Implementation of catopen -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/nl_types/catopen.h"
+#include "include/llvm-libc-types/nl_catd.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(nl_catd, catopen,
+ ([[maybe_unused]] const char *name,
+ [[maybe_unused]] int flag)) {
+ // TODO: Add implementation for message catalogs. For now, return error
+ // regardless of input.
+ libc_errno = EINVAL;
+ return reinterpret_cast<nl_catd>(-1);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/nl_types/catopen.h b/libc/src/nl_types/catopen.h
new file mode 100644
index 0000000..08ff71a
--- /dev/null
+++ b/libc/src/nl_types/catopen.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for catopen -----------------------*- C++ -*-===//
+//
+// 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_SRC_NL_TYPES_CATOPEN_H
+#define LLVM_LIBC_SRC_NL_TYPES_CATOPEN_H
+
+#include "include/llvm-libc-types/nl_catd.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+nl_catd catopen(const char *name, int flag);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_NL_TYPES_CATOPEN_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/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index c576e08..0c6ec9f 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -96,6 +96,7 @@ add_subdirectory(assert)
add_subdirectory(compiler)
add_subdirectory(dirent)
add_subdirectory(locale)
+add_subdirectory(nl_types)
add_subdirectory(signal)
add_subdirectory(spawn)
diff --git a/libc/test/src/arpa/inet/CMakeLists.txt b/libc/test/src/arpa/inet/CMakeLists.txt
index 21760df..690f751 100644
--- a/libc/test/src/arpa/inet/CMakeLists.txt
+++ b/libc/test/src/arpa/inet/CMakeLists.txt
@@ -23,6 +23,17 @@ add_libc_unittest(
)
add_libc_unittest(
+ inet_aton
+ SUITE
+ libc_arpa_inet_unittests
+ SRCS
+ inet_aton_test.cpp
+ DEPENDS
+ libc.src.arpa.inet.htonl
+ libc.src.arpa.inet.inet_aton
+)
+
+add_libc_unittest(
ntohl
SUITE
libc_arpa_inet_unittests
diff --git a/libc/test/src/arpa/inet/inet_aton_test.cpp b/libc/test/src/arpa/inet/inet_aton_test.cpp
new file mode 100644
index 0000000..c9c9787
--- /dev/null
+++ b/libc/test/src/arpa/inet/inet_aton_test.cpp
@@ -0,0 +1,92 @@
+//===-- Unittests for inet_aton -------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/arpa/inet/htonl.h"
+#include "src/arpa/inet/inet_aton.h"
+#include "test/UnitTest/Test.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+TEST(LlvmLibcInetAton, ValidTest) {
+ in_addr a;
+
+ // a.b.c.d
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("127.1.2.4", &a));
+ ASSERT_EQ(htonl(0x7f010204), a.s_addr);
+
+ // a.b.c
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("127.1.4", &a));
+ ASSERT_EQ(htonl(0x7f010004), a.s_addr);
+
+ // a.b
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("127.1", &a));
+ ASSERT_EQ(htonl(0x7f000001), a.s_addr);
+
+ // a
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("0x7f000001", &a));
+ ASSERT_EQ(htonl(0x7f000001), a.s_addr);
+
+ // Hex (0x) and mixed-case hex digits.
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("0xFf.0.0.1", &a));
+ ASSERT_EQ(htonl(0xff000001), a.s_addr);
+
+ // Hex (0X) and mixed-case hex digits.
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("0XfF.0.0.1", &a));
+ ASSERT_EQ(htonl(0xff000001), a.s_addr);
+
+ // Octal.
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("0177.0.0.1", &a));
+ ASSERT_EQ(htonl(0x7f000001), a.s_addr);
+
+ a.s_addr = 0;
+ ASSERT_EQ(1, inet_aton("036", &a));
+ ASSERT_EQ(htonl(036U), a.s_addr);
+}
+
+TEST(LlvmLibcInetAton, InvalidTest) {
+ ASSERT_EQ(0, inet_aton("", nullptr)); // Empty.
+ ASSERT_EQ(0, inet_aton("x", nullptr)); // Leading junk.
+ ASSERT_EQ(0, inet_aton("127.0.0.1x", nullptr)); // Trailing junk.
+ ASSERT_EQ(0, inet_aton("09.0.0.1", nullptr)); // Invalid octal.
+ ASSERT_EQ(0, inet_aton("0xg.0.0.1", nullptr)); // Invalid hex.
+ ASSERT_EQ(0, inet_aton("1.2.3.4.5", nullptr)); // Too many dots.
+ ASSERT_EQ(0, inet_aton("1.2.3.4.", nullptr)); // Trailing dot.
+
+ // Out of range a.b.c.d form.
+ ASSERT_EQ(0, inet_aton("999.0.0.1", nullptr));
+ ASSERT_EQ(0, inet_aton("0.999.0.1", nullptr));
+ ASSERT_EQ(0, inet_aton("0.0.999.1", nullptr));
+ ASSERT_EQ(0, inet_aton("0.0.0.999", nullptr));
+
+ // Out of range a.b.c form.
+ ASSERT_EQ(0, inet_aton("256.0.0", nullptr));
+ ASSERT_EQ(0, inet_aton("0.256.0", nullptr));
+ ASSERT_EQ(0, inet_aton("0.0.0x10000", nullptr));
+
+ // Out of range a.b form.
+ ASSERT_EQ(0, inet_aton("256.0", nullptr));
+ ASSERT_EQ(0, inet_aton("0.0x1000000", nullptr));
+
+ // Out of range a form.
+ ASSERT_EQ(0, inet_aton("0x100000000", nullptr));
+
+ // 64-bit overflow.
+ ASSERT_EQ(0, inet_aton("0x10000000000000000", nullptr));
+
+ // Out of range octal.
+ ASSERT_EQ(0, inet_aton("0400.0.0.1", nullptr));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index b3f54ab..ff5c511 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -17,6 +17,20 @@ add_fp_unittest(
)
add_fp_unittest(
+ cosf_float_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ cosf_float_test.cpp
+ DEPENDS
+ libc.src.__support.math.sincosf_utils
+ libc.src.__support.FPUtil.fp_bits
+ FLAGS
+ FMA_OPT__ONLY
+)
+
+add_fp_unittest(
cos_test
NEED_MPFR
SUITE
@@ -97,6 +111,20 @@ add_fp_unittest(
)
add_fp_unittest(
+ sinf_float_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ sinf_float_test.cpp
+ DEPENDS
+ libc.src.__support.math.sincosf_utils
+ libc.src.__support.FPUtil.fp_bits
+ FLAGS
+ FMA_OPT__ONLY
+)
+
+add_fp_unittest(
sinf16_test
NEED_MPFR
SUITE
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_float_test.cpp b/libc/test/src/math/cosf_float_test.cpp
new file mode 100644
index 0000000..3d573b2
--- /dev/null
+++ b/libc/test/src/math/cosf_float_test.cpp
@@ -0,0 +1,35 @@
+//===-- Unittests for cosf float-only -------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/sincosf_float_eval.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+#include "hdr/stdint_proxy.h"
+
+using LlvmLibcCosfFloatTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+float cosf_fast(float x) {
+ return LIBC_NAMESPACE::math::sincosf_float_eval::sincosf_eval<
+ /*IS_SIN*/ false>(x);
+}
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+TEST_F(LlvmLibcCosfFloatTest, InFloatRange) {
+ constexpr uint32_t COUNT = 100'000;
+ constexpr uint32_t STEP = UINT32_MAX / COUNT;
+ for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+ float x = FPBits(v).get_val();
+ if (FPBits(v).is_nan() || FPBits(v).is_inf())
+ continue;
+ ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, cosf_fast(x), 3.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/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index 1583ab6..2ff4f02 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -58,6 +58,21 @@ add_fp_unittest(
)
add_fp_unittest(
+ sinf_float_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ sinf_float_test.cpp
+ LINK_LIBRARIES
+ -lpthread
+ DEPENDS
+ .exhaustive_test
+ libc.src.__support.math.sincosf_utils
+)
+
+add_fp_unittest(
sinpif_test
NO_RUN_POSTBUILD
NEED_MPFR
@@ -90,6 +105,21 @@ add_fp_unittest(
)
add_fp_unittest(
+ cosf_float_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ cosf_float_test.cpp
+ LINK_LIBRARIES
+ -lpthread
+ DEPENDS
+ .exhaustive_test
+ libc.src.__support.math.sincosf_utils
+)
+
+add_fp_unittest(
cospif_test
NO_RUN_POSTBUILD
NEED_MPFR
diff --git a/libc/test/src/math/exhaustive/cosf_float_test.cpp b/libc/test/src/math/exhaustive/cosf_float_test.cpp
new file mode 100644
index 0000000..0c3a988
--- /dev/null
+++ b/libc/test/src/math/exhaustive/cosf_float_test.cpp
@@ -0,0 +1,44 @@
+//===-- Exhaustive test for cosf - float-only -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "exhaustive_test.h"
+#include "src/__support/math/sincosf_float_eval.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+float cosf_fast(float x) {
+ return LIBC_NAMESPACE::math::sincosf_float_eval::sincosf_eval<
+ /*IS_SIN*/ false>(x);
+}
+
+using LlvmLibcCosfExhaustiveTest =
+ LlvmLibcUnaryOpExhaustiveMathTest<float, mpfr::Operation::Cos, cosf_fast,
+ 3>;
+
+// Range: [0, Inf];
+static constexpr uint32_t POS_START = 0x0000'0000U;
+static constexpr uint32_t POS_STOP = 0x7f80'0000U;
+
+TEST_F(LlvmLibcCosfExhaustiveTest, PostiveRange) {
+ std::cout << "-- Testing for FE_TONEAREST in range [0x" << std::hex
+ << POS_START << ", 0x" << POS_STOP << ") --" << std::dec
+ << std::endl;
+ test_full_range(mpfr::RoundingMode::Nearest, POS_START, POS_STOP);
+}
+
+// Range: [-Inf, 0];
+static constexpr uint32_t NEG_START = 0x8000'0000U;
+static constexpr uint32_t NEG_STOP = 0xff80'0000U;
+
+TEST_F(LlvmLibcCosfExhaustiveTest, NegativeRange) {
+ std::cout << "-- Testing for FE_TONEAREST in range [0x" << std::hex
+ << NEG_START << ", 0x" << NEG_STOP << ") --" << std::dec
+ << std::endl;
+ test_full_range(mpfr::RoundingMode::Nearest, NEG_START, NEG_STOP);
+}
diff --git a/libc/test/src/math/exhaustive/exhaustive_test.h b/libc/test/src/math/exhaustive/exhaustive_test.h
index 8be65ba..322d774 100644
--- a/libc/test/src/math/exhaustive/exhaustive_test.h
+++ b/libc/test/src/math/exhaustive/exhaustive_test.h
@@ -40,7 +40,7 @@ template <typename OutType, typename InType = OutType>
using UnaryOp = OutType(InType);
template <typename OutType, typename InType, mpfr::Operation Op,
- UnaryOp<OutType, InType> Func>
+ UnaryOp<OutType, InType> Func, unsigned Tolerance = 0>
struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
using FloatType = InType;
using FPBits = LIBC_NAMESPACE::fputil::FPBits<FloatType>;
@@ -57,8 +57,8 @@ struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
do {
FPBits xbits(bits);
FloatType x = xbits.get_val();
- bool correct =
- TEST_MPFR_MATCH_ROUNDING_SILENTLY(Op, x, Func(x), 0.5, rounding);
+ bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(
+ Op, x, Func(x), static_cast<double>(Tolerance) + 0.5, rounding);
failed += (!correct);
// Uncomment to print out failed values.
if (!correct) {
@@ -256,9 +256,10 @@ struct LlvmLibcExhaustiveMathTest
}
};
-template <typename FloatType, mpfr::Operation Op, UnaryOp<FloatType> Func>
-using LlvmLibcUnaryOpExhaustiveMathTest =
- LlvmLibcExhaustiveMathTest<UnaryOpChecker<FloatType, FloatType, Op, Func>>;
+template <typename FloatType, mpfr::Operation Op, UnaryOp<FloatType> Func,
+ unsigned Tolerance = 0>
+using LlvmLibcUnaryOpExhaustiveMathTest = LlvmLibcExhaustiveMathTest<
+ UnaryOpChecker<FloatType, FloatType, Op, Func, Tolerance>>;
template <typename OutType, typename InType, mpfr::Operation Op,
UnaryOp<OutType, InType> Func>
diff --git a/libc/test/src/math/exhaustive/sinf_float_test.cpp b/libc/test/src/math/exhaustive/sinf_float_test.cpp
new file mode 100644
index 0000000..1e735e6
--- /dev/null
+++ b/libc/test/src/math/exhaustive/sinf_float_test.cpp
@@ -0,0 +1,47 @@
+//===-- Exhaustive test for sinf - float-only -----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Test float-only fast math implementation for sinf.
+#define LIBC_MATH (LIBC_MATH_FAST | LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT)
+
+#include "exhaustive_test.h"
+#include "src/__support/math/sincosf_float_eval.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+float sinf_fast(float x) {
+ return LIBC_NAMESPACE::math::sincosf_float_eval::sincosf_eval<
+ /*IS_SIN*/ true>(x);
+}
+
+using LlvmLibcSinfExhaustiveTest =
+ LlvmLibcUnaryOpExhaustiveMathTest<float, mpfr::Operation::Sin, sinf_fast,
+ 3>;
+
+// Range: [0, Inf];
+static constexpr uint32_t POS_START = 0x0000'0000U;
+static constexpr uint32_t POS_STOP = 0x7f80'0000U;
+
+TEST_F(LlvmLibcSinfExhaustiveTest, PostiveRange) {
+ std::cout << "-- Testing for FE_TONEAREST in range [0x" << std::hex
+ << POS_START << ", 0x" << POS_STOP << ") --" << std::dec
+ << std::endl;
+ test_full_range(mpfr::RoundingMode::Nearest, POS_START, POS_STOP);
+}
+
+// Range: [-Inf, 0];
+static constexpr uint32_t NEG_START = 0x8000'0000U;
+static constexpr uint32_t NEG_STOP = 0xff80'0000U;
+
+TEST_F(LlvmLibcSinfExhaustiveTest, NegativeRange) {
+ std::cout << "-- Testing for FE_TONEAREST in range [0x" << std::hex
+ << NEG_START << ", 0x" << NEG_STOP << ") --" << std::dec
+ << std::endl;
+ test_full_range(mpfr::RoundingMode::Nearest, NEG_START, NEG_STOP);
+}
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_float_test.cpp b/libc/test/src/math/sinf_float_test.cpp
new file mode 100644
index 0000000..33aab96
--- /dev/null
+++ b/libc/test/src/math/sinf_float_test.cpp
@@ -0,0 +1,35 @@
+//===-- Unittests for sinf float-only -------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/sincosf_float_eval.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+#include "hdr/stdint_proxy.h"
+
+using LlvmLibcSinfFloatTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+float sinf_fast(float x) {
+ return LIBC_NAMESPACE::math::sincosf_float_eval::sincosf_eval<
+ /*IS_SIN*/ true>(x);
+}
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+TEST_F(LlvmLibcSinfFloatTest, InFloatRange) {
+ constexpr uint32_t COUNT = 100'000;
+ constexpr uint32_t STEP = UINT32_MAX / COUNT;
+ for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+ float x = FPBits(v).get_val();
+ if (FPBits(v).is_nan() || FPBits(v).is_inf())
+ continue;
+ ASSERT_MPFR_MATCH(mpfr::Operation::Sin, x, sinf_fast(x), 3.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
new file mode 100644
index 0000000..6bafb32
--- /dev/null
+++ b/libc/test/src/nl_types/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_custom_target(libc-nl-types-tests)
+
+add_libc_test(
+ nl_types_test
+ SUITE
+ libc-nl-types-tests
+ 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
+ libc.src.nl_types.catgets
+)
diff --git a/libc/test/src/nl_types/nl_types_test.cpp b/libc/test/src/nl_types/nl_types_test.cpp
new file mode 100644
index 0000000..7392200
--- /dev/null
+++ b/libc/test/src/nl_types/nl_types_test.cpp
@@ -0,0 +1,34 @@
+//===-- Unittests for nl_types --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#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"
+#include "src/nl_types/catopen.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
+
+using LlvmLibcNlTypesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcNlTypesTest, CatopenFails) {
+ ASSERT_EQ(LIBC_NAMESPACE::catopen("/somepath", NL_CAT_LOCALE),
+ reinterpret_cast<nl_catd>(-1));
+ ASSERT_ERRNO_EQ(EINVAL);
+}
+
+TEST_F(LlvmLibcNlTypesTest, CatcloseFails) {
+ ASSERT_EQ(LIBC_NAMESPACE::catclose(nullptr), -1);
+}
+
+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, NL_SETD, 1, message),
+ const_cast<char *>(message));
+}