about summary refs log tree commit diff
path: root/library/coretests/tests/floats
AgeCommit message (Collapse)AuthorLines
2025-09-25Rollup merge of #146737 - RalfJung:f16-f128-miri, r=tgross35Stuart Cook-17/+15
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-25Rollup merge of #146735 - Qelxiros:const_mul_add, r=tgross35,RalfJungStuart Cook-80/+37
unstably constify float mul_add methods Tracking issue: rust-lang/rust#146724 r? `@tgross35`
2025-09-24unstably constify float mul_add methodsJeremy Smart-80/+37
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-09-24f16_f128: enable some more tests in MiriRalf Jung-17/+15
2025-09-22constify {float}::total_cmp()Nathaniel McCallum-86/+85
2025-09-10Unify and deduplicate bits conv float testsRomain Perier-110/+63
2025-09-03Unify and deduplicate algebraic float testsRomain Perier-83/+44
2025-08-31dedup to_radians float testKarol Zwolak-68/+26
2025-08-31dedup to_degrees float testKarol Zwolak-59/+29
2025-08-31dedup powi float testKarol Zwolak-66/+28
2025-08-30dedup recip float testKarol Zwolak-50/+22
I left the additional asserts on {f16, f128}::MAX.recip() in a new test_max_recip tests.
2025-08-07Hoist zero and one out into TestableFloatRoger Curley-88/+72
2025-08-07Consolidate total_cmp testsRoger Curley-578/+166
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-07Consolidate clamp testsRoger Curley-72/+45
2025-08-07Consolidate sqrt_domain testsRoger Curley-48/+23
2025-08-07Consolidate test_next_downRoger Curley-183/+34
2025-08-07Consolidate test_next_upRoger Curley-119/+69
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-07Consolidate is_sign_negative testsRoger Curley-52/+21
2025-08-07Consolidate is_positive testsRoger Curley-52/+21
2025-08-07Consolidate signum testsRoger Curley-24/+20
2025-08-07Consolidate abs testsRoger Curley-53/+9
This clobbers the existing generic abs test, but it covers strictly more, so that seems fine.
2025-07-11Consolidate classify testsRoger Curley-71/+23
2025-07-11Consolidate is_normal testsRoger Curley-82/+51
2025-07-11Consolidate is_finite testsRoger Curley-52/+22
2025-07-11Consolidate is_infinite testsRoger Curley-52/+22
2025-07-11Consolidate is_nanRoger Curley-52/+22
2025-07-11Consolidate one testsRoger Curley-52/+19
2025-07-11Consolidate negative zero testsRoger Curley-56/+20
2025-07-11Consolidate zero testsRoger Curley-52/+19
2025-07-11Consolidate neg_infinity testsRoger Curley-48/+18
2025-07-11Consolidate test_num testsRoger Curley-50/+33
2025-07-11Consolidate infinity testsRoger Curley-48/+18
2025-07-09Refactor nan testsRoger Curley-56/+23
2025-06-14Rollup merge of #142243 - RalfJung:float-test-dedup, r=tgross35Matthias Krüger-676/+308
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-13tweak runtime/const macro managementRalf Jung-44/+49
2025-06-09Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJungbors-3/+8
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-09float midpoint tests: add missing NAN casesRalf Jung-0/+2
2025-06-09make the default float comparison tolerance type-dependentRalf Jung-15/+31
2025-06-09float tests: deduplicate min, max, and rounding testsRalf Jung-456/+56
2025-06-09float tests: use assert_biteq in more placesRalf Jung-215/+224
2025-06-05change tests to use fixed constants to let them pass with miriLorrensP-2158466-2/+7
2025-06-04coretests: move float tests from num to floats module and use a more ↵Ralf Jung-0/+548
flexible macro to generate them
2025-06-03Enable Float non-determinism in miri. Update and add tests and changeLorrensP-2158466-1/+1
change tests in std, core and coretests.
2025-05-30Rollup merge of #141669 - tgross35:float-test-cleanup, r=RalfJungMatthias Krüger-717/+680
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-29float: Use `assert_biteq!` where possibleTrevor Gross-482/+492
`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-29float: Enable some f16 and f128 rounding tests on miriTrevor Gross-60/+26
The rounding tests are now supported, so there is no longer any reason to skip these.
2025-05-29float: Replace some approximate assertions with exactTrevor Gross-276/+276
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-29float: Use a shared `assert_biteq!` macro for testsTrevor Gross-176/+163
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-28float: Disable `total_cmp` sNaN tests for `f16`Trevor Gross-37/+40
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-20`core_float_math`: Move functions to `math` folderDaniel McNab-135/+136
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.