summaryrefslogtreecommitdiff
path: root/libc/test/src/math/RoundToIntegerTest.h
AgeCommit message (Collapse)Author
2025-08-24[libc][math][c++23] Add {nearbyint,rint,lrint,llrint,lround,llround}bf16 ↵Krishna Pandey
math functions (#153882) This PR adds the following basic math functions for BFloat16 type along with the tests: - nearbyintbf16 - rintbf16 - lrintbf16 - llrintbf16 - lroundbf16 - llroundbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
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-11[libc] Fix for adding macro I (#111872)Shourya Goel
We have two (EDIT: 4) files in which we are using `I`. This PR replaces them with alternatives like `i` and `IDX` etc.
2024-10-05[libc] remove errno.h includes (#110934)Job Henandez Lara
2024-10-01[libc] Move struct Sign into LIBC_NAMESPACE (#110709)Michael Jones
The struct Sign should be in the correct namespace. Also update the various tests that use it.
2024-07-15[libc] Fix warnings emitted by GCC (#98751)OverMighty
Fixes #98709.
2024-07-08[libc] Fix integer `rint` variants on the GPU (#98095)Joseph Huber
Summary: Currently these are implemented as a static cast on `__builtin_rint()` to a long. Howver, this is not strictly correct. The standard states that the output is unspecified, but most implementations, and the LLVM libc implementation, do some kind of guarantee on this beahvior. This is not guaranteed by just doing a cast. This patch just uses the generic versions until we implement `__builitin_lrint` correctly.
2024-06-10[libc][math][c23] Add MPFR unit tests for ↵OverMighty
{rint,lrint,llrint,lround,llround}f16 (#94473)
2024-05-06[libc][math] fix loose except check in `{EXPECT,ASSERT}_FP_EXCEPTION` macros ↵Michael Flanders
(#88816) Adds more FP test macros for the upcoming test adds for #61092 and the issues opened from it: #88768, #88769, #88770, #88771, #88772. Fix bug in `{EXPECT,ASSERT}_FP_EXCEPTION`. `EXPECT_FP_EXCEPTION(0)` seems to be used to test that an exception did not happen, but it always does `EXPECT_GE(... & 0, 0)` which never fails. Update and refactor tests that break after the above bug fix. An interesting way things broke after the above change is that `ForceRoundingMode` and `quick_get_round()` were raising the inexact exception, breaking a lot of the `atan*` tests. The changes for all files other than `FPMatcher.h` and `libc/test/src/math/smoke/RoundToIntegerTest.h` should have the same semantics as before. For `RoundToIntegerTest.h`, lines 56-58 before the changes do not always hold since this test is used for functions with different exception and errno behavior like `lrint` and `lround`. I've deleted those lines for now, but tests for those cases should be added for the different nearest int functions to account for this. Adding @nickdesaulniers for review.
2024-04-23[libc] Make fenv and math tests preserve fenv_t state (#89658)Roland McGrath
This adds a new test fixture class FEnvSafeTest (usable as a base class for other fixtures) that ensures each test doesn't perturb the `fenv_t` state that the next test will start with. It also provides types and methods tests can use to explicitly wrap code under test either to check that it doesn't perturb the state or to save and restore the state around particular test code. All the fenv and math tests are updated to use this so that none can affect another. Expectations that code under test and/or tests themselves don't perturb state can be added later.
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-20[libc][NFC] Move `Sign` type to separate header (#85930)Guillaume Chatelet
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-02-06[libc] Move libc_errno inside of LIBC_NAMESPACE (#80774)michaelrj-google
Having libc_errno outside of the namespace causes versioning issues when trying to link the tests against LLVM-libc. Most of this patch is just moving libc_errno inside the namespace in tests. This isn't necessary in the function implementations since those are already inside the namespace.
2024-01-30[libc][NFC] Rename `FPBits` nan functions (#79998)Guillaume Chatelet
- [libc][NFC] Rename FPBits nan functions - rename build_signaling_nan in signaling_nan - rename build_quiet_nan to quiet_nan
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.
2024-01-23[libc] Remove specific nan payload in math functions (#79133)Guillaume Chatelet
2024-01-23[reland][libc] Remove unnecessary `FPBits` functions and properties (#79128)Guillaume Chatelet
- reland #79113 - Fix aarch64 RISC-V build
2024-01-23Revert "[libc] Remove unnecessary `FPBits` functions and properties" (#79118)Guillaume Chatelet
Reverts llvm/llvm-project#79113 It broke aarch64 build bot machines.
2024-01-23[libc] Remove unnecessary `FPBits` functions and properties (#79113)Guillaume Chatelet
This patch reduces the surface of `FPBits`.
2024-01-18[libc][NFC] Introduce a Sign type for FPBits (#78500)Guillaume Chatelet
Another patch is needed to cover `DyadicFloat` and `NormalFloat` constructors.
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-12-14[libc][NFC] Remove MantissaWidth traits (#75458)Guillaume Chatelet
Same as #75362, the traits does not bring a lot of value over `FloatProperties::MANTISSA_WIDTH` (or `FPBits::MANTISSA_WIDTH`).
2023-12-11[libc][NFC] Fix mixed up biased/unbiased exponent (#75037)Guillaume Chatelet
According to [wikipedia](https://en.wikipedia.org/wiki/Exponent_bias) the "biased exponent" is the encoded form that is always positive whereas the unbiased form is the actual "real" exponent that can be positive or negative. `FPBits` seems to be using `unbiased_exponent` to describe the encoded form (unsigned). This patch simply use `biased` instead of `unbiased`.
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-09-01[lldb] Fix duplicate word typos; NFCFangrui Song
Those fixes were taken from https://reviews.llvm.org/D137338
2023-06-20[libc] Fix libmath test compilation when using UInt<T>Mikhail R. Gadelha
This patch: (1) adds the add_with_carry_const and sub_with_borrow_const constexpr calls to add and sub, respectively. Both add and sub are constexpr calls and were call the non-constexpr version of add/sub_with_borrow. (2) adds explicit UIntType construct calls in some fp tests. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D150223
2023-06-01[libc] Reduce math tests runtime furtherGuillaume Chatelet
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D151875
2023-03-07[libc][math] Switch math functions to use libc_errno and fix some errno and ↵Tue Ly
floating point exceptions. Switch math functions to use libc_errno and fix some errno and floating point exceptions Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D145349
2023-02-15[libc][NFC] Make tuning macros start with LIBC_COPT_Guillaume Chatelet
Rename preprocessor definitions that control tuning of llvm libc. Differential Revision: https://reviews.llvm.org/D143913
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.
2022-10-06[libc] Resolve NaN/implementation-defined behavior of floating-point testsDominic Chen
Differential Revision: https://reviews.llvm.org/D134917
2022-10-05Revert "[libc] Resolve NaN/implementation-defined behavior of floating-point ↵Dominic Chen
tests" This reverts commit 5470b1fcb5754b45c1233df7759411ff56942d6e.
2022-10-05[libc] Resolve NaN/implementation-defined behavior of floating-point testsDominic Chen
Differential Revision: https://reviews.llvm.org/D134917
2022-03-10[libc] Initial support for darwin-aarch64.Tue Ly
Add initial support for darwin-aarch64 (macOS M1). Some differences compared to linux-aarch64: - `math.h` defined `math_errhandling` by the compiler builtin `__math_errhandling()` but Apple Clang 13.0.0 on M1 does not support `__math_errhandling()` builtin as a macro function or a constexpr function. - `math.h` defines `UNDERFLOW` and `OVERFLOW` macros. - Besides 5 usual floating point exceptions: `FE_INEXACT`, `FE_UNDERFLOW`, `FE_OVERFLOW`, `FE_DIVBYZERO`, and `FE_INVALID`, `fenv.h` also has another floating point exception: `FE_FLUSHTOZERO`. The corresponding trap for `FE_FLUSHTOZERO` in the control register is at the different location compared to the status register. - `FE_FLUSHTOZERO` exception flag cannot be raised with the default CPU floating point operation mode. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D120914
2022-03-08[libc] Add testing macros for errno and floating point exceptions.Tue Ly
Add testing macros for errno and floating point exceptions. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D121235
2022-03-04[libc] Remove the redundant header FPUtil/FEnvUtils.hTue Ly
Remove the redundant header FPUtil/FEnvUtils.h, use FPUtil/FEnvImpl.h header instead. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D120965
2021-12-23[libc][obvious] Fix style of MPFRWrapper.Siva Chandra Reddy
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-12-07[libc] apply new lint rulesMichael Jones
This patch applies the lint rules described in the previous patch. There was also a significant amount of effort put into manually fixing things, since all of the templated functions, or structs defined in /spec, were not updated and had to be handled manually. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D114302
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-07-22[libc] Rename FEnv.h and refactor subsequent filesHedin Garca
Because Windows's pathnames are not case sensitive, to avoid include conflicts between our header file FEnv.h and the one from the C Standard library, <fenv.h>, the prior file was renamed. The motive for the relabel came to fix this include error in TestHelpers.cpp since a conflict arose with a file in the same directory when #include <fenv.h> was being used. Reviewed By: sivachandra, aeubanks Differential Revision: https://reviews.llvm.org/D106470
2021-07-13[libc] Capture floating point encoding and arrange it sequentially in memoryHedin Garca
Redefined FPBits.h and LongDoubleBitsX86 so its implementation works for the Windows and Linux platform while maintaining a packed memory alignment of the precision floating point numbers. For its size in memory to be the same as the data type of the float point number. This change was necessary because the previous attribute((packed)) specification in the struct was not working for Windows like it was for Linux and consequently static_asserts in the FPBits.h file were failing. Reviewed By: aeubanks, sivachandra Differential Revision: https://reviews.llvm.org/D105561
2021-04-17[libc][NFC] Make conversion from FPBits to the float point type explicit.Siva Chandra Reddy
This will help us catch errors like the ones fixed by the commit 31ed45d9cfd5da2bf4f1d7ddba54122df6fc91fa
2021-04-13[libc] Make FPBits a union.Siva Chandra Reddy
This helps us avoid the uncomfortable reinterpret-casts. Avoiding the reinterpret casts prevents us from tripping the sanitizers as well. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D100360
2021-02-16[libc][NFC] Make few maths functions buildable outside of LLVM libc build.Siva Chandra Reddy
Few math functions manipulate errno. They assumed that LLVM libc's errno is available. However, that might not be the case when these functions are used in a libc which does not use LLVM libc's errno. This change switches such uses of LLVM libc's errno to the normal public errno macro. This does not affect LLVM libc's build because the include order ensures we get LLVM libc's errno. Also, the header check rule ensures we are only including LLVM libc's errno.h.
2021-01-20[libc][NFC][obvious] fix the names of MPFR testsMichael Jones
I missed the MPFR tests in my previous commit. They have now been fixed to not fail the prefix check in the test macro.
2020-12-29[libc] Add implementations of rounding functions which depend rounding mode.Siva Chandra Reddy
Namely, implementations for rint, rintf, rintl, lrint, lrintf, lrintl, llrint, llrintf and llrintl have been added. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D93889
2020-12-15[libc][NFC][Obvious] Remove few unnecessary #include directives in tests.Siva Chandra Reddy
2020-12-11[libc] Add implementations of lround[f|l] and llround[f|l].Siva Chandra Reddy
A new function to MPFRWrapper has been added, which is used to set up the unit tests. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D93007