about summary refs log tree commit diff
path: root/library/compiler-builtins/libm
AgeCommit message (Collapse)AuthorLines
2025-02-07Add an enum representation of rounding modeTrevor Gross-0/+22
We only round using nearest, but some incoming code has more handling of rounding modes that would be nice to `match` on. Rather than checking integer values, add an enum representation.
2025-02-07Work arouind iai-callgrind apt failuresTrevor Gross-0/+2
Usually `cargo binstall iai-callgrind-runner` handles apt dependencies. However, the following has been happening: Err:11 mirror+file:/etc/apt/apt-mirrors.txt noble-updates/main amd64 libc6-dbg amd64 2.39-0ubuntu8.3 404 Not Found [IP: 40.81.13.82 80] E: Failed to fetch mirror+file:/etc/apt/apt-mirrors.txt/pool/main/g/glibc/libc6-dbg_2.39-0ubuntu8.3_amd64.deb 404 Not Found [IP: 40.81.13.82 80] Fetched 19.8 MB in 6s (3138 kB/s) E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing? Installing the dependencies manually seems to resolve the issue.
2025-02-07Uncomment some hex float tests that should work nowTrevor Gross-8/+5
2025-02-06Convert `fmaf` to a generic implementationTrevor Gross-99/+129
Introduce a version of generic `fma` that works when there is a larger hardware-backed float type available to compute the result with more precision. This is currently used only for `f32`, but with some minor adjustments it should work for `f16` as well.
2025-02-06Remove or reduce the scope of `allow(unused)` where possibleTrevor Gross-29/+20
Now that we have more in this crate making use of traits, try to be more specific about what is actually unused.
2025-02-07fmaf128: fix exponent calculation for subnormalsTrevor Gross-12/+26
When `fmaf128` was introduced in [1], it included a bug where `self` gets returned rather than the expected minimum positive value. Resolve this and add a regression test. [1]: https://github.com/rust-lang/libm/pull/494
2025-02-07Check more subnormal values during edge cases testsTrevor Gross-2/+20
Add checks at the max subnormal value and a couple values scatted throughout the subnormal range. This helped identifiy a bug in `fmaf128`. As part of this, slightly reduce the amount of edge cases checked without optimizations because the change makes it become noticible.
2025-02-07Run standard tests before running integration testsTrevor Gross-0/+3
To ensure we don't waste time running extensive tests when there is an easily identifiable failure, run the normal test suite for relevant functions before starting extensive tests.
2025-02-06Add better edge case testing for `scalbn`Trevor Gross-24/+101
Include integer values around the minimum and maximum exponents which require different behavior in the scale functions.
2025-02-06Add `fmaf128`Trevor Gross-67/+237
Resolve all remaining `f64`-specific items in the generic version of `fma`, then expose `fmaf128`.
2025-02-06Make it possible to use `hf32!` and similar macros outside of `libm`Trevor Gross-6/+16
Adjust paths such that these macros don't go through the private `math` module. `feature = "private-test-deps"` is still needed. Additionally, ensure that `cargo check` for this crate gets run in CI because `cargo test` does not seem to identify this problem. `compiler_builtins` will need to reexport the `support` module.
2025-02-06Improve tidy outputTrevor Gross-4/+3
Print a better diff when lists are unsorted, and always check tidy lists even if `--check` is not passed.
2025-02-06Add an integration test that verifies a list of casesTrevor Gross-5/+750
We need someplace to collect known failures, previous regressions, edge cases that are difficult to construct from generics, and similar. Introduce this here.
2025-02-06Switch `musl` to track `master`Trevor Gross-0/+0
A few bugs have been fixed, including the sign of `fma(tiny, -tiny, 0.0)`. Switch to tracking `master` rather than the latest tag so we don't need to xfail these tests.
2025-02-06fma: Ensure zero has the correct signTrevor Gross-46/+3
Currently, `fma(tiny, -tiny, 0.0)` returns 0.0 while the answer should be -0.0. This is because `-0.0 + 0.0 = +0.0` in the default rounding mode; however, the result should be negative. Musl has the same pattern but that version worked because the C compiler was contracting `x*y + z` to (ironically) `fmadd`. Musl was fixed in 9683bd6241 ("math: fix fma(x,y,0) when x*y rounds to -0"). Add the same fix here, which allows dropping the xfails.
2025-02-05Print the hex float format upon failureTrevor Gross-7/+39
Now that we have a hex float formatter, make use of it for test output. This produces values that are easier to read than the bitwise hex representation. Example: thread 'mp_quickspace_fmaf128' panicked at crates/libm-test/tests/multiprecision.rs:17:48: called `Result::unwrap()` on an `Err` value: input: (0xe38d71c71c71c71c71c71c71c71c71c8, 0xe38d71c71c71c71c71c71c71c71c71c8, 0xffff0000000000000000000000000000) as hex: (-0x1.71c71c71c71c71c71c71c71c71c8p+9102, -0x1.71c71c71c71c71c71c71c71c71c8p+9102, -inf) as bits: (0xe38d71c71c71c71c71c71c71c71c71c8, 0xe38d71c71c71c71c71c71c71c71c71c8, 0xffff0000000000000000000000000000) expected: 0xffff0000000000000000000000000000 -inf 0xffff0000000000000000000000000000 actual: 0x7fff8000000000000000000000000000 NaN 0x7fff8000000000000000000000000000 Caused by: real value != NaN
2025-02-05Commonize the signature for all instances of `get_test_cases`Trevor Gross-33/+45
In order to make these more interchangeable in more places, always return `(impl Iterator, u64)`. This will facilitate using other generators for extensive tests.
2025-02-05Start converting `fma` to a generic functionTrevor Gross-192/+278
This is the first step toward making `fma` usable for `f128`, and possibly `f32` on platforms where growing to `f64` is not fast. This does not yet work for anything other than `f64`.
2025-02-05Add checks via annotation that lists are sorted or exhaustiveTrevor Gross-21/+187
This crate has a handful of lists that need to list all API and can't easily be verified. Additionally, some longer lists should be kept sorted so they are easier to look through. Resolve both of these by adding a check in `update-api-list.py` that looks for annotations and verifies the contents are as expected. Annotations are `verify-apilist-start`, `verify-apilist-end`, `verify-sorted-start`, and `verify-sorted-end`. This includes fixes for anything that did not meet the criteria.
2025-02-05Do not add `libm_helper.rs` to the sources listTrevor Gross-57/+9
This is just a collection of all functions and should not trigger extensive tests when changed.
2025-02-05Add a check in the `shared.rs` that the function list is sortedTrevor Gross-7/+13
2025-02-05Add `scalbnf16`, `scalbnf128`, `ldexpf16`, and `ldexpf128`Trevor Gross-39/+195
Use the generic `scalbn` to provide `f16` and `f128` versions, which also work for `ldexp`. This involves a new algorithm for `f16` because the default does not converge fast enough with a limited number of rounds.
2025-02-05Fix hex float trait recursion problemTrevor Gross-25/+5
2025-01-31Rename `EXP_MAX` to `EXP_SAT`Trevor Gross-12/+15
`EXP_MAX` sounds like it would be the maximum value representable by that float type's exponent, rather than the maximum unsigned value of its bits. Clarify this by renaming to `EXP_SAT`, the "saturated" exponent representation.
2025-01-30Specify license as just MITManish Goregaokar-1/+1
Simplify the SPDX string to the user-facing version to make it easier for users and tooling to understand. Contributions must still be `MIT OR Apache-2.0`. [ add commit body with context - Trevor ]
2025-01-29Util: also print the hex float format for outputsTrevor Gross-2/+9
2025-01-29Introduce a wrapper type for IEEE hex float formattingTrevor Gross-4/+181
2025-01-29Support parsing NaN and infinities from the `hf*` functionsTrevor Gross-12/+61
This isn't very useful for constants since the trait constants are available, but does enable roundtripping via hex float syntax.
2025-01-28Revert "Temporarily pin `indicatif` to 0.17.9"Trevor Gross-2/+1
This reverts commit 1dacdabdb6186f97144c50f8952575576deb3730.
2025-01-28Temporarily pin `indicatif` to 0.17.9Trevor Gross-1/+2
0.17.10 introduced a change that removes `Sync` from `ProgressStyle`, which makes it more difficult to share in a callback. Pin the dependency for now until we see if `indicatif` will change this back or if we need to find a workaround.
2025-01-28Switch musl from a script download to a submoduleTrevor Gross-46/+19
Rather than keeping a script that downloads the tarball, we can just add musl as a submodule and let git handle the synchronizatoin. Do so here.
2025-01-27Ignore specific `atan2` and `sin` tests on i586Trevor Gross-16/+25
There seems to be a case of unsoundness with the `i586` version of `atan2`. For the following test: assert_eq!(atan2(2.0, -1.0), atan(2.0 / -1.0) + PI);atan2(2.0, -1.0) The output is optimization-dependent. The new `release-checked` profile produces the following failure: thread 'math::atan2::sanity_check' panicked at src/math/atan2.rs:123:5: assertion `left == right` failed left: 2.0344439357957027 right: 2.0344439357957027 Similarly, `sin::test_near_pi` fails with the following: thread 'math::sin::test_near_pi' panicked at src/math/sin.rs:91:5: assertion `left == right` failed left: 6.273720864039203e-7 right: 6.273720864039205e-7 Mark the tests ignored on `i586` for now.
2025-01-25Rework the available Cargo profilesTrevor Gross-13/+21
Currently the default release profile enables LTO and single CGU builds, which is very slow to build. Most tests are better run with optimizations enabled since it allows testing a much larger number of inputs, so it is inconvenient that building can sometimes take significantly longer than the tests. Remedy this by doing the following: * Move the existing `release` profile to `release-opt`. * With the above, the default `release` profile is untouched (16 CGUs and thin local LTO). * `release-checked` inherits `release`, so no LTO or single CGU. This means that the simple `cargo test --release` becomes much faster for local development. We are able to enable the other profiles as needed in CI. Tests should ideally still be run with `--profile release-checked` to ensure there are no debug assetions or unexpected wrapping math hit. `no-panic` still needs a single CGU, so must be run with `--profile release-opt`. Since it is not possible to detect CGU or profilel configuration from within build scripts, the `ENSURE_NO_PANIC` environment variable must now always be set.
2025-01-25Remove remnants of the `checked` featureTrevor Gross-15/+10
The Cargo feature `checked` was added in 410b0633a6b9 ("Overhaul tests") and later removed in e4ac1399062c ("swap stable to be unstable, checked is now debug_assertions"). However, there are a few remaining uses of `feature = "checked"` that did not get removed. Clean these up here.
2025-01-25Use `remquo` from RugTrevor Gross-67/+5
Rug 1.27.0 exposes `remquo`; make use of it for our tests. Removing our workaround also allows removing the direct dependency on `gmp-mpfr-sys`
2025-01-25Use `frexp` from RugTrevor Gross-6/+1
Rug 1.27.0 exposes `frexp`. Make use of it for our tests.
2025-01-25Use `az` exported from RugTrevor Gross-7/+5
Since Rug 1.27.0, `az` is reexported. This means we no longer need to track it as a separate dependency.
2025-01-25Upgrade all dependencies to the latest versionTrevor Gross-8/+8
In particular, this includes updates to Rug that we can make use of [1], [2], [3], [4]. [1]: https://gitlab.com/tspiteri/rug/-/issues/78 [2]: https://gitlab.com/tspiteri/rug/-/issues/80 [3]: https://gitlab.com/tspiteri/rug/-/issues/76 [4]: https://gitlab.com/tspiteri/rug/-/issues/73
2025-01-24Enable missing icount benchmarksTrevor Gross-0/+6
A few new functions were added but this list did not get updated. Do so here.
2025-01-24Add `fmodf128`Trevor Gross-33/+40
This function is significantly slower than all others so includes an override in `EXTREMELY_SLOW_TESTS`. Without it, PR CI takes ~1hour and the extensive tests in CI take ~1day.
2025-01-24Add way to override the number of iterations for specific testsTrevor Gross-9/+29
Certain functions (`fmodf128`) are significantly slower than others, to the point that running the default number of tests adds tens of minutes to PR CI and extensive test time increases to ~1day. It does not make sense to do this by default; so, introduce `EXTREMELY_SLOW_TESTS` to test configuration that allows setting specific tests that need to have a reduced iteration count.
2025-01-24Increase or set CI timeoutsTrevor Gross-2/+8
With the new routines, some of our tests are running close to their timeouts. Increase the timeout for test jobs, and set a short timeout for all other jobs that did not have one.
2025-01-24Add `fmodf16` using the generic implementationTrevor Gross-1/+37
2025-01-24Add a generic version of `fmod`Trevor Gross-162/+96
This can replace `fmod` and `fmodf`. As part of this change I was able to replace some of the `while` loops with `leading_zeros`.
2025-01-24Add `fminf16`, `fmaxf16`, `fminf128`, and `fmaxf128`Trevor Gross-4/+76
2025-01-24Add a generic version of `fmin` and `fmax`Trevor Gross-40/+47
These can be used for `fmin`, `fminf`, `fmax`, and `fmaxf`. No changes to the implementation are made, so [1] is not fixed. [1]: https://github.com/rust-lang/libm/issues/439
2025-01-24Remove an outdated note about precisionTrevor Gross-3/+0
2025-01-24Add `roundf16` and `roundf128`Trevor Gross-2/+78
2025-01-24Add a generic version of `round`Trevor Gross-52/+54
This replaces `round` and `roundf`.
2025-01-23Add a generic version of `scalbn`Trevor Gross-59/+133
This replaces the `f32` and `f64` versions of `scalbn` and `ldexp`.