summaryrefslogtreecommitdiff
path: root/libc/test/src/math/sin_test.cpp
AgeCommit message (Collapse)Author
2025-10-21[libc][math] Add tolerance to math tests so that they still work when ↵lntue
accurate path is skipped. (#164522)
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2024-10-10[libc][math] Improve performance of double precision trig functions. (#111793)lntue
- Improve the accuracy of fast pass' range reduction. - Provide tighter error estimations. - Reduce the table size when `LIBC_MATH_SMALL_TABLES` flag is set.
2024-07-28[libc] Create a separate proxy header for math-function-macros.h (#98430)Nhat Nguyen
Fix #98393
2024-06-24[libc][math] Implement double precision sin correctly rounded to all ↵lntue
rounding modes. (#95736) - Algorithm: - Step 1 - Range reduction: for a double precision input `x`, return `k` and `u` such that - k is an integer - u = x - k * pi / 128, and |u| < pi/256 - Step 2 - Calculate `sin(u)` and `cos(u)` in double-double using Taylor polynomials with errors < 2^-70 with FMA or < 2^-66 w/o FMA. - Step 3 - Calculate `sin(x) = sin(k*pi/128) * cos(u) + cos(k*pi/128) * sin(u)` using look-up table for `sin(k*pi/128)` and `cos(k*pi/128)`. - Step 4 - Use Ziv's rounding test to decide if the result is correctly rounded. - Step 4' - If the Ziv's rounding test failed, redo step 1-3 using 128-bit precision. - Currently, without FMA instructions, the large range reduction only works correctly for the default rounding mode (FE_TONEAREST). - Provide `LIBC_MATH` flag so that users can set `LIBC_MATH = LIBC_MATH_SKIP_ACCURATE_PASS` to build the `sin` function without step 4 and 4'.
2024-04-05[libc] Add proxy header math_macros.h. (#87598)lntue
Context: https://github.com/llvm/llvm-project/pull/87017 - Add proxy header `libc/hdr/math_macros.h` that will: - include `<math.h>` in overlay mode, - include `"include/llvm-libc-macros/math-macros.h"` in full build mode. - Its corresponding CMake target `libc.hdr.math_macros` will only depend on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros` in full build mode. - Replace all `#include "include/llvm-libc-macros/math-macros.h"` with `#include "hdr/math_macros.h"`. - Add dependency to `libc.hdr.math_macros` CMake target when using `add_fp_unittest`. - Update the remaining dependency. - Update bazel overlay: add `libc:hdr_math_macros` target, and replacing all dependency on `libc:llvm_libc_macros_math_macros` with `libc:hdr_math_macros`.
2024-03-18[libc] Remove direct math.h includes (#85324)Michael Jones
Reland of #84991 A downstream overlay mode user ran into issues with the isnan macro not working in our sources with a specific libc configuration. This patch replaces the last direct includes of math.h with our internal math_macros.h, along with the necessary build system changes.
2024-01-23[libc][NFC] Remove `FPBits` cast operator (#79142)Guillaume Chatelet
The semantics for casting can range from "bitcast" (same representation) to "different representation", to "type promotion". Here we remove the cast operator and force usage of `get_val` as the only function to get the floating point value, making the intent clearer and more consistent.
2023-12-15[libc] Fix improper initialization of `StorageType` (#75610)Guillaume Chatelet
`StorageType` may be a `BigInt` under the hood. Initializing it with `-1` does not yields the maximum value.
2023-12-15[libc][NFC] Rename `MANTISSA_WIDTH` in `FRACTION_LEN` (#75489)Guillaume Chatelet
This one might be a bit controversial since the terminology has been introduced from the start but I think `FRACTION_LEN` is a better name here. AFAICT it really is "the number of bits after the decimal dot when the number is in normal form." `MANTISSA_WIDTH` is less precise as it's unclear whether we take the leading bit into account. This patch also renames most of the properties to use the `_LEN` suffix and fixes useless casts or variables.
2023-10-19[libc][math][NFC] Remove global scope constants declaration in math tests ↵lntue
(#69558) Clean up usage of `DECLARE_SPECIAL_CONSTANTS` in global scope.
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-06-01[libc] Reduce math tests runtimeGuillaume Chatelet
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D151798
2023-02-07[libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.Siva Chandra Reddy
This part of the effort to make all test related pieces into the `test` directory. This helps is excluding test related pieces in a straight forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move the MPFR wrapper and testutils into the 'test' directory.
2021-12-22[libc] apply formatting to testsMichael Jones
Apply the formatting rules that were applied to the libc/src directory to the libc/test directory, as well as the files in libc/utils that are included by the tests. This does not include automated enforcement. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D116127
2021-10-29[libc][NFC] Move test related pieces from FPUtil to util/UnitTest.Siva Chandra Reddy
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D112673
2021-08-06[libc][nfc] move ctype_utils and FPUtils to __supportMichael Jones
Some ctype functions are called from other libc functions (e.g. isspace is used in atoi). By moving ctype_utils.h to __support it becomes easier to include just the implementations of these functions. For these reasons the implementation for isspace was moved into ctype_utils as well. FPUtils was moved to simplify the build order, and to clarify which files are a part of the actual libc. Many files were modified to accomodate these changes, mostly changing the #include paths. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D107600
2021-06-30[libc][NFC] Remove few deprecated FPUtil header files and test patterns.Siva Chandra Reddy
Few tests have been converted to the new test patterns to facilitate this.
2021-05-13[libc] Add x86_64 implementations of double precision cos, sin and tan.Siva Chandra Reddy
The implementations use the x86_64 FPU instructions. These instructions are extremely slow compared to a polynomial based software implementation. Also, their accuracy falls drastically once the input goes beyond 2PI. To improve both the speed and accuracy, we will be taking the following approach going forward: 1. As a follow up to this CL, we will implement a range reduction algorithm which will expand the accuracy to the entire double precision range. 2. After that, we will replace the HW instructions with a polynomial implementation to improve the run time. After step 2, the implementations will be accurate, performant and target architecture independent. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D102384