32 Commits

Author SHA1 Message Date
Roger Curley
80bcd1a61f Consolidate total_cmp tests
This standardizes how max and min subnormals are generated. Since the
new method doesn't use powf, it also enables some of the tests for f128
that were previously disabled due to issues with powf (although it looks
like those issues were already fixed anyway). f16 signalling nan tests
previously disabled are not re-enabled, since the underlying LLVM issue
has not been closed.
2025-08-07 22:06:57 -04:00
Roger Curley
a5e4e7ab52 Consolidate clamp tests 2025-08-07 22:06:57 -04:00
Roger Curley
666bfcae21 Consolidate sqrt_domain tests 2025-08-07 22:06:57 -04:00
Roger Curley
8a65ce4360 Consolidate test_next_down 2025-08-07 22:06:57 -04:00
Roger Curley
f51f68b49a Consolidate test_next_up
Note that the behaviour of the f128 test is slightly changed to use the
same nan mask as is used in test_float_bits_conv, which is the behaviour
used by f16,f32,and f64.
2025-08-07 22:06:56 -04:00
Roger Curley
71973fcbdb Consolidate is_sign_negative tests 2025-08-07 22:06:56 -04:00
Roger Curley
951ef57b85 Consolidate is_positive tests 2025-08-07 22:06:56 -04:00
Roger Curley
83878ea228 Consolidate signum tests 2025-08-07 22:06:51 -04:00
Roger Curley
b4a3d3014e Consolidate abs tests
This clobbers the existing generic abs test, but it covers strictly
more, so that seems fine.
2025-08-07 22:03:30 -04:00
Roger Curley
79769f2d5b Consolidate classify tests 2025-07-11 10:41:24 -04:00
Roger Curley
d2c1900086 Consolidate is_normal tests 2025-07-11 10:41:24 -04:00
Roger Curley
7dd2811b2a Consolidate is_finite tests 2025-07-11 10:41:24 -04:00
Roger Curley
e3d83679cb Consolidate is_infinite tests 2025-07-11 10:41:24 -04:00
Roger Curley
1b8904c0c5 Consolidate is_nan 2025-07-11 10:41:23 -04:00
Roger Curley
868020e059 Consolidate one tests 2025-07-11 10:31:26 -04:00
Roger Curley
fc01eed024 Consolidate negative zero tests 2025-07-11 10:31:25 -04:00
Roger Curley
0c01322ec6 Consolidate zero tests 2025-07-11 10:31:25 -04:00
Roger Curley
c2e6b39474 Consolidate neg_infinity tests 2025-07-11 10:31:25 -04:00
Roger Curley
c5e67b48ef Consolidate test_num tests 2025-07-11 10:31:25 -04:00
Roger Curley
cfb66e5e88 Consolidate infinity tests 2025-07-11 10:31:25 -04:00
Roger Curley
bc2001f158 Refactor nan tests 2025-07-09 23:24:47 -04:00
Matthias Krüger
4cf4473b85
Rollup merge of #142243 - RalfJung:float-test-dedup, r=tgross35
float tests: deduplicate min, max, and rounding tests

Part of https://github.com/rust-lang/rust/issues/141726

Best reviewed commit-by-commit.

- Use `assert_biteq!` in the `mod.rs` tests. This requires some trickery to make shadowing macros with imports work.
- The min, max, minimum, maximum tests in `tests/floats/f*.rs` are entirely subsumed by what we already have in `tests/float/mod.rs`, so I just removed them.
- The rounding tests (floor etc) in `f*.rs` had more test points, so I copied them over. They didn't have `0.5` and `-0.5` though which seem like interesting points in particular regarding the sign of the resulting zero if that's what it sounds to, and they didn't max min/max/inf/nan tests, so this was really a merger of both tests.

r? ``@tgross35``
2025-06-14 11:27:11 +02:00
Ralf Jung
79cb013b55 float tests: deduplicate min, max, and rounding tests 2025-06-09 14:24:12 +02:00
Ralf Jung
20cf8ca3f7 float tests: use assert_biteq in more places 2025-06-09 14:17:28 +02:00
LorrensP-2158466
5bafe9d8fc Enable Float non-determinism in miri. Update and add tests and change
change tests in std, core and coretests.
2025-06-03 19:46:13 +02:00
Trevor Gross
70cce1c762 float: Use assert_biteq! where possible
`assert_eq!` ignores the sign of zero, but for any tests involving zeros
we do care about this sign. Replace `assert_eq!` with `assert_biteq!`
everywhere possible for float tests to ensure we don't miss this.
`assert_biteq!` is also updated to check equality on non-NaNs, to catch
the unlikely case that bitwise equality works but our `==`
implementation is broken.

There is one notable output change: we were asserting that
`(-0.0).fract()` and `(-1.0).fract()` both return -0.0, but both
actually return +0.0.
2025-05-29 21:13:26 +00:00
Trevor Gross
9907c5a806 float: Replace some approximate assertions with exact
As was mentioned at [1], we currently use `assert_approx_eq` for testing
some math functions that guarantee exact results. Replace approximate
assertions with exact ones for the following:

* `ceil`
* `floor`
* `fract`
* `from_bits`
* `mul_add`
* `round_ties_even`
* `round`
* `trunc`

This likely wasn't done in the past to avoid writing out exact decimals
that don't match the intuitive answer (e.g. 1.3 - 1.0 = 0.300...004),
but ensuring our results are accurate seems more important here.

[1]: https://github.com/rust-lang/rust/pull/138087#issuecomment-2842069281
2025-05-29 21:13:26 +00:00
Trevor Gross
6a79b272ba float: Use a shared assert_biteq! macro for tests
Clean up the separate `assert_f{16,32,64,128}` macros with a single
`assert_biteq!` macro that works for all float widths.
2025-05-29 21:13:26 +00:00
Daniel McNab
f6709bb683 core_float_math: Move functions to math folder
When these functions were added in
https://github.com/rust-lang/rust/pull/138087
It made a relatively common pattern for emulating
these functions using an extension trait (which
internally uses `libm`) much more fragile.
If `core::f32` happened to be imported by the user
(to access a constant, say), then that import in
the module namespace would take precedence over
`f32` in the type namespace for resolving these
functions, running headfirst into the stability
attribute.

We ran into this in Color -
https://github.com/linebender/color - and chose to
release the remedial 0.3.1 and 0.2.4, to allow
downstream crates to build on `docs.rs`.
As these methods are perma-unstable, moving them
into a new module should not have any long-term
concerns, and ensures that this breakage doesn't
adversely impact anyone else.
2025-05-20 16:41:43 +01:00
Trevor Gross
65117eeda8 Skip {f32,f64}::mul_add tests on MinGW
Per [1], MinGW has an incorrect fma implementation. This showed up in
tests run with cranelift after adding float math operations to `core`.
Presumably we hadn't noticed this when running tests with LLVM because
LLVM was constant folding the result away.

Rust issue: https://github.com/rust-lang/rust/issues/140515

[1]: https://sourceforge.net/p/mingw-w64/bugs/848/
2025-05-14 14:30:03 +00:00
Trevor Gross
2b9256e1c8 Move applicable float tests from coretests back to std
The previous commit moved all test files from `std` to `core` so git
understands the move. Not all functionality is actually testable in
`core`, however, so perform move the relevant portions back. Changes
from inherent to module methods is also done since this is the form of
math operations available in `core` (as `core_float_math`).
2025-05-14 14:29:58 +00:00
Trevor Gross
48f3e63f70 Move float tests from std to core
Many float-related tests in `std` only depend on `core`, so move the
tests there. This also allows us to verify functions from
`core_float_math`.

Since the majority of test files need to be moved to `coretests`, move
the files here without any cleanup; this is done in a followup commit.
This makes git history slightly cleaner, but coretests will not build
immediately after this commit.
2025-05-13 22:22:15 +00:00