Commit Graph

53 Commits

Author SHA1 Message Date
Stuart Cook cec668fefc Rollup merge of #146737 - RalfJung:f16-f128-miri, r=tgross35
f16_f128: enable some more tests in Miri

For some reason, a bunch of tests were disabled in Miri that don't use any fancy intrinsics. Let's enable them.

I verified this with `./x miri library/core --no-doc -- float`.

r? `@tgross35`
2025-09-25 20:31:55 +10:00
Stuart Cook 8e62f95376 Rollup merge of #146735 - Qelxiros:const_mul_add, r=tgross35,RalfJung
unstably constify float mul_add methods

Tracking issue: rust-lang/rust#146724
r? `@tgross35`
2025-09-25 20:31:54 +10:00
Jeremy Smart a00f24116e unstably constify float mul_add methods
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-09-24 15:21:31 -04:00
Ralf Jung f509dff56d f16_f128: enable some more tests in Miri 2025-09-24 16:47:13 +02:00
Nathaniel McCallum 5dde557fc4 constify {float}::total_cmp() 2025-09-22 10:24:39 -04:00
Romain Perier b1c4e19e13 Unify and deduplicate bits conv float tests 2025-09-10 14:25:36 +02:00
Romain Perier 4e872375d4 Unify and deduplicate algebraic float tests 2025-09-03 14:39:50 +02:00
Karol Zwolak 9028efcf2e dedup to_radians float test 2025-08-31 18:20:49 +02:00
Karol Zwolak c81a8a89ee dedup to_degrees float test 2025-08-31 18:19:05 +02:00
Karol Zwolak e10e6d78ac dedup powi float test 2025-08-31 18:16:00 +02:00
Karol Zwolak 6ebd009d47 dedup recip float test
I left the additional asserts on {f16, f128}::MAX.recip() in a new
test_max_recip tests.
2025-08-30 14:54:41 +02:00
Roger Curley 57cf40cd82 Hoist zero and one out into TestableFloat 2025-08-07 22:51:46 -04:00
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 25ec235b86 tweak runtime/const macro management 2025-06-13 10:22:56 +02:00
bors c6768de2d6 Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJung
Enable Non-determinism of float operations in Miri and change std tests

Links to [#4208](https://github.com/rust-lang/miri/issues/4208) and [#3555](https://github.com/rust-lang/miri/issues/3555) in Miri.

Non-determinism of floating point operations was disabled in rust-lang/rust#137594 because it breaks the tests and doc-tests in core/coretests and std. This PR enables some of them.

This pr includes the following changes:

- Enables the float non-determinism but with a lower relative error of 4ULP instead of 16ULP
- These operations now have a fixed output based on the C23 standard, except the pow operations, this is tracked in [#4286](https://github.com/rust-lang/miri/issues/4286#issue-3010677983)
- Changes tests that made incorrect assumptions about the operations, not to make that assumption anymore (from `assert_eq!` to `assert_approx_eq!`.
- Changed the doctests of the stdlib of these operations to compare against fixed constants instead of `f*::EPSILON`, which now succeed with Miri and `-Zmiri-many-seeds`
- Added a constant `APPROX_DELTA` in `std/tests/floats/f32.rs` which is used for approximation tests, but with a different value when run in Miri. This is to make these tests succeed.
- Added tests in the float tests of Miri to test the C23 behaviour.

Fixes https://github.com/rust-lang/miri/issues/4208
2025-06-09 21:21:58 +00:00
Ralf Jung 1b6bb4566d float midpoint tests: add missing NAN cases 2025-06-09 14:24:24 +02:00
Ralf Jung 2766b77f1e make the default float comparison tolerance type-dependent 2025-06-09 14:24:24 +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 00452bd783 change tests to use fixed constants to let them pass with miri 2025-06-05 16:22:13 +02:00
Ralf Jung 7742d0e230 coretests: move float tests from num to floats module and use a more flexible macro to generate them 2025-06-04 16:32:17 +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
Matthias Krüger 3ebdd59770 Rollup merge of #141669 - tgross35:float-test-cleanup, r=RalfJung
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

The first commit is a small bit of macro cleanup.

try-job: aarch64-gnu
try-job: x86_64-gnu-aux
2025-05-30 07:01:31 +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 5446ba3c2d float: Enable some f16 and f128 rounding tests on miri
The rounding tests are now supported, so there is no longer any reason
to skip these.
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
Trevor Gross 19fd098446 float: Disable total_cmp sNaN tests for f16
There is an LLVM bug with lowering of basic `f16` operations that mean a
round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple
`abs` calls or bitcasts [1]. This is problematic because the round trip
quiets signaling NaNs. For most operations this is acceptable, but it is
causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is
resolved.

Fixes: https://github.com/rust-lang/rustc_codegen_cranelift/issues/1578
Fixes: https://github.com/rust-lang/rust/issues/141503

[1]: https://github.com/llvm/llvm-project/issues/104915
2025-05-28 06:49:04 +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