Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bdc66a4

Browse files
committedMay 20, 2025·
core_float_math: Move functions to math folder
When these functions were added in #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.
1 parent a8e4c68 commit bdc66a4

File tree

6 files changed

+990
-933
lines changed

6 files changed

+990
-933
lines changed
 

‎library/core/src/num/f32.rs‎

Lines changed: 417 additions & 389 deletions
Large diffs are not rendered by default.

‎library/core/src/num/f64.rs‎

Lines changed: 411 additions & 383 deletions
Large diffs are not rendered by default.

‎library/coretests/tests/floats/f32.rs‎

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -215,88 +215,88 @@ fn test_classify() {
215215

216216
#[test]
217217
fn test_floor() {
218-
assert_approx_eq!(f32::floor(1.0f32), 1.0f32);
219-
assert_approx_eq!(f32::floor(1.3f32), 1.0f32);
220-
assert_approx_eq!(f32::floor(1.5f32), 1.0f32);
221-
assert_approx_eq!(f32::floor(1.7f32), 1.0f32);
222-
assert_approx_eq!(f32::floor(0.0f32), 0.0f32);
223-
assert_approx_eq!(f32::floor(-0.0f32), -0.0f32);
224-
assert_approx_eq!(f32::floor(-1.0f32), -1.0f32);
225-
assert_approx_eq!(f32::floor(-1.3f32), -2.0f32);
226-
assert_approx_eq!(f32::floor(-1.5f32), -2.0f32);
227-
assert_approx_eq!(f32::floor(-1.7f32), -2.0f32);
218+
assert_approx_eq!(f32::math::floor(1.0f32), 1.0f32);
219+
assert_approx_eq!(f32::math::floor(1.3f32), 1.0f32);
220+
assert_approx_eq!(f32::math::floor(1.5f32), 1.0f32);
221+
assert_approx_eq!(f32::math::floor(1.7f32), 1.0f32);
222+
assert_approx_eq!(f32::math::floor(0.0f32), 0.0f32);
223+
assert_approx_eq!(f32::math::floor(-0.0f32), -0.0f32);
224+
assert_approx_eq!(f32::math::floor(-1.0f32), -1.0f32);
225+
assert_approx_eq!(f32::math::floor(-1.3f32), -2.0f32);
226+
assert_approx_eq!(f32::math::floor(-1.5f32), -2.0f32);
227+
assert_approx_eq!(f32::math::floor(-1.7f32), -2.0f32);
228228
}
229229

230230
#[test]
231231
fn test_ceil() {
232-
assert_approx_eq!(f32::ceil(1.0f32), 1.0f32);
233-
assert_approx_eq!(f32::ceil(1.3f32), 2.0f32);
234-
assert_approx_eq!(f32::ceil(1.5f32), 2.0f32);
235-
assert_approx_eq!(f32::ceil(1.7f32), 2.0f32);
236-
assert_approx_eq!(f32::ceil(0.0f32), 0.0f32);
237-
assert_approx_eq!(f32::ceil(-0.0f32), -0.0f32);
238-
assert_approx_eq!(f32::ceil(-1.0f32), -1.0f32);
239-
assert_approx_eq!(f32::ceil(-1.3f32), -1.0f32);
240-
assert_approx_eq!(f32::ceil(-1.5f32), -1.0f32);
241-
assert_approx_eq!(f32::ceil(-1.7f32), -1.0f32);
232+
assert_approx_eq!(f32::math::ceil(1.0f32), 1.0f32);
233+
assert_approx_eq!(f32::math::ceil(1.3f32), 2.0f32);
234+
assert_approx_eq!(f32::math::ceil(1.5f32), 2.0f32);
235+
assert_approx_eq!(f32::math::ceil(1.7f32), 2.0f32);
236+
assert_approx_eq!(f32::math::ceil(0.0f32), 0.0f32);
237+
assert_approx_eq!(f32::math::ceil(-0.0f32), -0.0f32);
238+
assert_approx_eq!(f32::math::ceil(-1.0f32), -1.0f32);
239+
assert_approx_eq!(f32::math::ceil(-1.3f32), -1.0f32);
240+
assert_approx_eq!(f32::math::ceil(-1.5f32), -1.0f32);
241+
assert_approx_eq!(f32::math::ceil(-1.7f32), -1.0f32);
242242
}
243243

244244
#[test]
245245
fn test_round() {
246-
assert_approx_eq!(f32::round(2.5f32), 3.0f32);
247-
assert_approx_eq!(f32::round(1.0f32), 1.0f32);
248-
assert_approx_eq!(f32::round(1.3f32), 1.0f32);
249-
assert_approx_eq!(f32::round(1.5f32), 2.0f32);
250-
assert_approx_eq!(f32::round(1.7f32), 2.0f32);
251-
assert_approx_eq!(f32::round(0.0f32), 0.0f32);
252-
assert_approx_eq!(f32::round(-0.0f32), -0.0f32);
253-
assert_approx_eq!(f32::round(-1.0f32), -1.0f32);
254-
assert_approx_eq!(f32::round(-1.3f32), -1.0f32);
255-
assert_approx_eq!(f32::round(-1.5f32), -2.0f32);
256-
assert_approx_eq!(f32::round(-1.7f32), -2.0f32);
246+
assert_approx_eq!(f32::math::round(2.5f32), 3.0f32);
247+
assert_approx_eq!(f32::math::round(1.0f32), 1.0f32);
248+
assert_approx_eq!(f32::math::round(1.3f32), 1.0f32);
249+
assert_approx_eq!(f32::math::round(1.5f32), 2.0f32);
250+
assert_approx_eq!(f32::math::round(1.7f32), 2.0f32);
251+
assert_approx_eq!(f32::math::round(0.0f32), 0.0f32);
252+
assert_approx_eq!(f32::math::round(-0.0f32), -0.0f32);
253+
assert_approx_eq!(f32::math::round(-1.0f32), -1.0f32);
254+
assert_approx_eq!(f32::math::round(-1.3f32), -1.0f32);
255+
assert_approx_eq!(f32::math::round(-1.5f32), -2.0f32);
256+
assert_approx_eq!(f32::math::round(-1.7f32), -2.0f32);
257257
}
258258

259259
#[test]
260260
fn test_round_ties_even() {
261-
assert_approx_eq!(f32::round_ties_even(2.5f32), 2.0f32);
262-
assert_approx_eq!(f32::round_ties_even(1.0f32), 1.0f32);
263-
assert_approx_eq!(f32::round_ties_even(1.3f32), 1.0f32);
264-
assert_approx_eq!(f32::round_ties_even(1.5f32), 2.0f32);
265-
assert_approx_eq!(f32::round_ties_even(1.7f32), 2.0f32);
266-
assert_approx_eq!(f32::round_ties_even(0.0f32), 0.0f32);
267-
assert_approx_eq!(f32::round_ties_even(-0.0f32), -0.0f32);
268-
assert_approx_eq!(f32::round_ties_even(-1.0f32), -1.0f32);
269-
assert_approx_eq!(f32::round_ties_even(-1.3f32), -1.0f32);
270-
assert_approx_eq!(f32::round_ties_even(-1.5f32), -2.0f32);
271-
assert_approx_eq!(f32::round_ties_even(-1.7f32), -2.0f32);
261+
assert_approx_eq!(f32::math::round_ties_even(2.5f32), 2.0f32);
262+
assert_approx_eq!(f32::math::round_ties_even(1.0f32), 1.0f32);
263+
assert_approx_eq!(f32::math::round_ties_even(1.3f32), 1.0f32);
264+
assert_approx_eq!(f32::math::round_ties_even(1.5f32), 2.0f32);
265+
assert_approx_eq!(f32::math::round_ties_even(1.7f32), 2.0f32);
266+
assert_approx_eq!(f32::math::round_ties_even(0.0f32), 0.0f32);
267+
assert_approx_eq!(f32::math::round_ties_even(-0.0f32), -0.0f32);
268+
assert_approx_eq!(f32::math::round_ties_even(-1.0f32), -1.0f32);
269+
assert_approx_eq!(f32::math::round_ties_even(-1.3f32), -1.0f32);
270+
assert_approx_eq!(f32::math::round_ties_even(-1.5f32), -2.0f32);
271+
assert_approx_eq!(f32::math::round_ties_even(-1.7f32), -2.0f32);
272272
}
273273

274274
#[test]
275275
fn test_trunc() {
276-
assert_approx_eq!(f32::trunc(1.0f32), 1.0f32);
277-
assert_approx_eq!(f32::trunc(1.3f32), 1.0f32);
278-
assert_approx_eq!(f32::trunc(1.5f32), 1.0f32);
279-
assert_approx_eq!(f32::trunc(1.7f32), 1.0f32);
280-
assert_approx_eq!(f32::trunc(0.0f32), 0.0f32);
281-
assert_approx_eq!(f32::trunc(-0.0f32), -0.0f32);
282-
assert_approx_eq!(f32::trunc(-1.0f32), -1.0f32);
283-
assert_approx_eq!(f32::trunc(-1.3f32), -1.0f32);
284-
assert_approx_eq!(f32::trunc(-1.5f32), -1.0f32);
285-
assert_approx_eq!(f32::trunc(-1.7f32), -1.0f32);
276+
assert_approx_eq!(f32::math::trunc(1.0f32), 1.0f32);
277+
assert_approx_eq!(f32::math::trunc(1.3f32), 1.0f32);
278+
assert_approx_eq!(f32::math::trunc(1.5f32), 1.0f32);
279+
assert_approx_eq!(f32::math::trunc(1.7f32), 1.0f32);
280+
assert_approx_eq!(f32::math::trunc(0.0f32), 0.0f32);
281+
assert_approx_eq!(f32::math::trunc(-0.0f32), -0.0f32);
282+
assert_approx_eq!(f32::math::trunc(-1.0f32), -1.0f32);
283+
assert_approx_eq!(f32::math::trunc(-1.3f32), -1.0f32);
284+
assert_approx_eq!(f32::math::trunc(-1.5f32), -1.0f32);
285+
assert_approx_eq!(f32::math::trunc(-1.7f32), -1.0f32);
286286
}
287287

288288
#[test]
289289
fn test_fract() {
290-
assert_approx_eq!(f32::fract(1.0f32), 0.0f32);
291-
assert_approx_eq!(f32::fract(1.3f32), 0.3f32);
292-
assert_approx_eq!(f32::fract(1.5f32), 0.5f32);
293-
assert_approx_eq!(f32::fract(1.7f32), 0.7f32);
294-
assert_approx_eq!(f32::fract(0.0f32), 0.0f32);
295-
assert_approx_eq!(f32::fract(-0.0f32), -0.0f32);
296-
assert_approx_eq!(f32::fract(-1.0f32), -0.0f32);
297-
assert_approx_eq!(f32::fract(-1.3f32), -0.3f32);
298-
assert_approx_eq!(f32::fract(-1.5f32), -0.5f32);
299-
assert_approx_eq!(f32::fract(-1.7f32), -0.7f32);
290+
assert_approx_eq!(f32::math::fract(1.0f32), 0.0f32);
291+
assert_approx_eq!(f32::math::fract(1.3f32), 0.3f32);
292+
assert_approx_eq!(f32::math::fract(1.5f32), 0.5f32);
293+
assert_approx_eq!(f32::math::fract(1.7f32), 0.7f32);
294+
assert_approx_eq!(f32::math::fract(0.0f32), 0.0f32);
295+
assert_approx_eq!(f32::math::fract(-0.0f32), -0.0f32);
296+
assert_approx_eq!(f32::math::fract(-1.0f32), -0.0f32);
297+
assert_approx_eq!(f32::math::fract(-1.3f32), -0.3f32);
298+
assert_approx_eq!(f32::math::fract(-1.5f32), -0.5f32);
299+
assert_approx_eq!(f32::math::fract(-1.7f32), -0.7f32);
300300
}
301301

302302
#[test]
@@ -417,15 +417,15 @@ fn test_mul_add() {
417417
let nan: f32 = f32::NAN;
418418
let inf: f32 = f32::INFINITY;
419419
let neg_inf: f32 = f32::NEG_INFINITY;
420-
assert_approx_eq!(f32::mul_add(12.3f32, 4.5, 6.7), 62.05);
421-
assert_approx_eq!(f32::mul_add(-12.3f32, -4.5, -6.7), 48.65);
422-
assert_approx_eq!(f32::mul_add(0.0f32, 8.9, 1.2), 1.2);
423-
assert_approx_eq!(f32::mul_add(3.4f32, -0.0, 5.6), 5.6);
424-
assert!(f32::mul_add(nan, 7.8, 9.0).is_nan());
425-
assert_eq!(f32::mul_add(inf, 7.8, 9.0), inf);
426-
assert_eq!(f32::mul_add(neg_inf, 7.8, 9.0), neg_inf);
427-
assert_eq!(f32::mul_add(8.9f32, inf, 3.2), inf);
428-
assert_eq!(f32::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
420+
assert_approx_eq!(f32::math::mul_add(12.3f32, 4.5, 6.7), 62.05);
421+
assert_approx_eq!(f32::math::mul_add(-12.3f32, -4.5, -6.7), 48.65);
422+
assert_approx_eq!(f32::math::mul_add(0.0f32, 8.9, 1.2), 1.2);
423+
assert_approx_eq!(f32::math::mul_add(3.4f32, -0.0, 5.6), 5.6);
424+
assert!(f32::math::mul_add(nan, 7.8, 9.0).is_nan());
425+
assert_eq!(f32::math::mul_add(inf, 7.8, 9.0), inf);
426+
assert_eq!(f32::math::mul_add(neg_inf, 7.8, 9.0), neg_inf);
427+
assert_eq!(f32::math::mul_add(8.9f32, inf, 3.2), inf);
428+
assert_eq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf);
429429
}
430430

431431
#[test]

‎library/coretests/tests/floats/f64.rs‎

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::f64::consts;
2-
use std::num::FpCategory as Fp;
1+
use core::f64;
2+
use core::f64::consts;
3+
use core::num::FpCategory as Fp;
34

45
/// Smallest number
56
const TINY_BITS: u64 = 0x1;
@@ -201,88 +202,88 @@ fn test_classify() {
201202

202203
#[test]
203204
fn test_floor() {
204-
assert_approx_eq!(f64::floor(1.0f64), 1.0f64);
205-
assert_approx_eq!(f64::floor(1.3f64), 1.0f64);
206-
assert_approx_eq!(f64::floor(1.5f64), 1.0f64);
207-
assert_approx_eq!(f64::floor(1.7f64), 1.0f64);
208-
assert_approx_eq!(f64::floor(0.0f64), 0.0f64);
209-
assert_approx_eq!(f64::floor(-0.0f64), -0.0f64);
210-
assert_approx_eq!(f64::floor(-1.0f64), -1.0f64);
211-
assert_approx_eq!(f64::floor(-1.3f64), -2.0f64);
212-
assert_approx_eq!(f64::floor(-1.5f64), -2.0f64);
213-
assert_approx_eq!(f64::floor(-1.7f64), -2.0f64);
205+
assert_approx_eq!(f64::math::floor(1.0f64), 1.0f64);
206+
assert_approx_eq!(f64::math::floor(1.3f64), 1.0f64);
207+
assert_approx_eq!(f64::math::floor(1.5f64), 1.0f64);
208+
assert_approx_eq!(f64::math::floor(1.7f64), 1.0f64);
209+
assert_approx_eq!(f64::math::floor(0.0f64), 0.0f64);
210+
assert_approx_eq!(f64::math::floor(-0.0f64), -0.0f64);
211+
assert_approx_eq!(f64::math::floor(-1.0f64), -1.0f64);
212+
assert_approx_eq!(f64::math::floor(-1.3f64), -2.0f64);
213+
assert_approx_eq!(f64::math::floor(-1.5f64), -2.0f64);
214+
assert_approx_eq!(f64::math::floor(-1.7f64), -2.0f64);
214215
}
215216

216217
#[test]
217218
fn test_ceil() {
218-
assert_approx_eq!(f64::ceil(1.0f64), 1.0f64);
219-
assert_approx_eq!(f64::ceil(1.3f64), 2.0f64);
220-
assert_approx_eq!(f64::ceil(1.5f64), 2.0f64);
221-
assert_approx_eq!(f64::ceil(1.7f64), 2.0f64);
222-
assert_approx_eq!(f64::ceil(0.0f64), 0.0f64);
223-
assert_approx_eq!(f64::ceil(-0.0f64), -0.0f64);
224-
assert_approx_eq!(f64::ceil(-1.0f64), -1.0f64);
225-
assert_approx_eq!(f64::ceil(-1.3f64), -1.0f64);
226-
assert_approx_eq!(f64::ceil(-1.5f64), -1.0f64);
227-
assert_approx_eq!(f64::ceil(-1.7f64), -1.0f64);
219+
assert_approx_eq!(f64::math::ceil(1.0f64), 1.0f64);
220+
assert_approx_eq!(f64::math::ceil(1.3f64), 2.0f64);
221+
assert_approx_eq!(f64::math::ceil(1.5f64), 2.0f64);
222+
assert_approx_eq!(f64::math::ceil(1.7f64), 2.0f64);
223+
assert_approx_eq!(f64::math::ceil(0.0f64), 0.0f64);
224+
assert_approx_eq!(f64::math::ceil(-0.0f64), -0.0f64);
225+
assert_approx_eq!(f64::math::ceil(-1.0f64), -1.0f64);
226+
assert_approx_eq!(f64::math::ceil(-1.3f64), -1.0f64);
227+
assert_approx_eq!(f64::math::ceil(-1.5f64), -1.0f64);
228+
assert_approx_eq!(f64::math::ceil(-1.7f64), -1.0f64);
228229
}
229230

230231
#[test]
231232
fn test_round() {
232-
assert_approx_eq!(f64::round(2.5f64), 3.0f64);
233-
assert_approx_eq!(f64::round(1.0f64), 1.0f64);
234-
assert_approx_eq!(f64::round(1.3f64), 1.0f64);
235-
assert_approx_eq!(f64::round(1.5f64), 2.0f64);
236-
assert_approx_eq!(f64::round(1.7f64), 2.0f64);
237-
assert_approx_eq!(f64::round(0.0f64), 0.0f64);
238-
assert_approx_eq!(f64::round(-0.0f64), -0.0f64);
239-
assert_approx_eq!(f64::round(-1.0f64), -1.0f64);
240-
assert_approx_eq!(f64::round(-1.3f64), -1.0f64);
241-
assert_approx_eq!(f64::round(-1.5f64), -2.0f64);
242-
assert_approx_eq!(f64::round(-1.7f64), -2.0f64);
233+
assert_approx_eq!(f64::math::round(2.5f64), 3.0f64);
234+
assert_approx_eq!(f64::math::round(1.0f64), 1.0f64);
235+
assert_approx_eq!(f64::math::round(1.3f64), 1.0f64);
236+
assert_approx_eq!(f64::math::round(1.5f64), 2.0f64);
237+
assert_approx_eq!(f64::math::round(1.7f64), 2.0f64);
238+
assert_approx_eq!(f64::math::round(0.0f64), 0.0f64);
239+
assert_approx_eq!(f64::math::round(-0.0f64), -0.0f64);
240+
assert_approx_eq!(f64::math::round(-1.0f64), -1.0f64);
241+
assert_approx_eq!(f64::math::round(-1.3f64), -1.0f64);
242+
assert_approx_eq!(f64::math::round(-1.5f64), -2.0f64);
243+
assert_approx_eq!(f64::math::round(-1.7f64), -2.0f64);
243244
}
244245

245246
#[test]
246247
fn test_round_ties_even() {
247-
assert_approx_eq!(f64::round_ties_even(2.5f64), 2.0f64);
248-
assert_approx_eq!(f64::round_ties_even(1.0f64), 1.0f64);
249-
assert_approx_eq!(f64::round_ties_even(1.3f64), 1.0f64);
250-
assert_approx_eq!(f64::round_ties_even(1.5f64), 2.0f64);
251-
assert_approx_eq!(f64::round_ties_even(1.7f64), 2.0f64);
252-
assert_approx_eq!(f64::round_ties_even(0.0f64), 0.0f64);
253-
assert_approx_eq!(f64::round_ties_even(-0.0f64), -0.0f64);
254-
assert_approx_eq!(f64::round_ties_even(-1.0f64), -1.0f64);
255-
assert_approx_eq!(f64::round_ties_even(-1.3f64), -1.0f64);
256-
assert_approx_eq!(f64::round_ties_even(-1.5f64), -2.0f64);
257-
assert_approx_eq!(f64::round_ties_even(-1.7f64), -2.0f64);
248+
assert_approx_eq!(f64::math::round_ties_even(2.5f64), 2.0f64);
249+
assert_approx_eq!(f64::math::round_ties_even(1.0f64), 1.0f64);
250+
assert_approx_eq!(f64::math::round_ties_even(1.3f64), 1.0f64);
251+
assert_approx_eq!(f64::math::round_ties_even(1.5f64), 2.0f64);
252+
assert_approx_eq!(f64::math::round_ties_even(1.7f64), 2.0f64);
253+
assert_approx_eq!(f64::math::round_ties_even(0.0f64), 0.0f64);
254+
assert_approx_eq!(f64::math::round_ties_even(-0.0f64), -0.0f64);
255+
assert_approx_eq!(f64::math::round_ties_even(-1.0f64), -1.0f64);
256+
assert_approx_eq!(f64::math::round_ties_even(-1.3f64), -1.0f64);
257+
assert_approx_eq!(f64::math::round_ties_even(-1.5f64), -2.0f64);
258+
assert_approx_eq!(f64::math::round_ties_even(-1.7f64), -2.0f64);
258259
}
259260

260261
#[test]
261262
fn test_trunc() {
262-
assert_approx_eq!(f64::trunc(1.0f64), 1.0f64);
263-
assert_approx_eq!(f64::trunc(1.3f64), 1.0f64);
264-
assert_approx_eq!(f64::trunc(1.5f64), 1.0f64);
265-
assert_approx_eq!(f64::trunc(1.7f64), 1.0f64);
266-
assert_approx_eq!(f64::trunc(0.0f64), 0.0f64);
267-
assert_approx_eq!(f64::trunc(-0.0f64), -0.0f64);
268-
assert_approx_eq!(f64::trunc(-1.0f64), -1.0f64);
269-
assert_approx_eq!(f64::trunc(-1.3f64), -1.0f64);
270-
assert_approx_eq!(f64::trunc(-1.5f64), -1.0f64);
271-
assert_approx_eq!(f64::trunc(-1.7f64), -1.0f64);
263+
assert_approx_eq!(f64::math::trunc(1.0f64), 1.0f64);
264+
assert_approx_eq!(f64::math::trunc(1.3f64), 1.0f64);
265+
assert_approx_eq!(f64::math::trunc(1.5f64), 1.0f64);
266+
assert_approx_eq!(f64::math::trunc(1.7f64), 1.0f64);
267+
assert_approx_eq!(f64::math::trunc(0.0f64), 0.0f64);
268+
assert_approx_eq!(f64::math::trunc(-0.0f64), -0.0f64);
269+
assert_approx_eq!(f64::math::trunc(-1.0f64), -1.0f64);
270+
assert_approx_eq!(f64::math::trunc(-1.3f64), -1.0f64);
271+
assert_approx_eq!(f64::math::trunc(-1.5f64), -1.0f64);
272+
assert_approx_eq!(f64::math::trunc(-1.7f64), -1.0f64);
272273
}
273274

274275
#[test]
275276
fn test_fract() {
276-
assert_approx_eq!(f64::fract(1.0f64), 0.0f64);
277-
assert_approx_eq!(f64::fract(1.3f64), 0.3f64);
278-
assert_approx_eq!(f64::fract(1.5f64), 0.5f64);
279-
assert_approx_eq!(f64::fract(1.7f64), 0.7f64);
280-
assert_approx_eq!(f64::fract(0.0f64), 0.0f64);
281-
assert_approx_eq!(f64::fract(-0.0f64), -0.0f64);
282-
assert_approx_eq!(f64::fract(-1.0f64), -0.0f64);
283-
assert_approx_eq!(f64::fract(-1.3f64), -0.3f64);
284-
assert_approx_eq!(f64::fract(-1.5f64), -0.5f64);
285-
assert_approx_eq!(f64::fract(-1.7f64), -0.7f64);
277+
assert_approx_eq!(f64::math::fract(1.0f64), 0.0f64);
278+
assert_approx_eq!(f64::math::fract(1.3f64), 0.3f64);
279+
assert_approx_eq!(f64::math::fract(1.5f64), 0.5f64);
280+
assert_approx_eq!(f64::math::fract(1.7f64), 0.7f64);
281+
assert_approx_eq!(f64::math::fract(0.0f64), 0.0f64);
282+
assert_approx_eq!(f64::math::fract(-0.0f64), -0.0f64);
283+
assert_approx_eq!(f64::math::fract(-1.0f64), -0.0f64);
284+
assert_approx_eq!(f64::math::fract(-1.3f64), -0.3f64);
285+
assert_approx_eq!(f64::math::fract(-1.5f64), -0.5f64);
286+
assert_approx_eq!(f64::math::fract(-1.7f64), -0.7f64);
286287
}
287288

288289
#[test]

‎library/std/src/f32.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl f32 {
4646
#[stable(feature = "rust1", since = "1.0.0")]
4747
#[inline]
4848
pub fn floor(self) -> f32 {
49-
core::f32::floor(self)
49+
core::f32::math::floor(self)
5050
}
5151

5252
/// Returns the smallest integer greater than or equal to `self`.
@@ -68,7 +68,7 @@ impl f32 {
6868
#[stable(feature = "rust1", since = "1.0.0")]
6969
#[inline]
7070
pub fn ceil(self) -> f32 {
71-
core::f32::ceil(self)
71+
core::f32::math::ceil(self)
7272
}
7373

7474
/// Returns the nearest integer to `self`. If a value is half-way between two
@@ -96,7 +96,7 @@ impl f32 {
9696
#[stable(feature = "rust1", since = "1.0.0")]
9797
#[inline]
9898
pub fn round(self) -> f32 {
99-
core::f32::round(self)
99+
core::f32::math::round(self)
100100
}
101101

102102
/// Returns the nearest integer to a number. Rounds half-way cases to the number
@@ -122,7 +122,7 @@ impl f32 {
122122
#[stable(feature = "round_ties_even", since = "1.77.0")]
123123
#[inline]
124124
pub fn round_ties_even(self) -> f32 {
125-
core::f32::round_ties_even(self)
125+
core::f32::math::round_ties_even(self)
126126
}
127127

128128
/// Returns the integer part of `self`.
@@ -147,7 +147,7 @@ impl f32 {
147147
#[stable(feature = "rust1", since = "1.0.0")]
148148
#[inline]
149149
pub fn trunc(self) -> f32 {
150-
core::f32::trunc(self)
150+
core::f32::math::trunc(self)
151151
}
152152

153153
/// Returns the fractional part of `self`.
@@ -170,7 +170,7 @@ impl f32 {
170170
#[stable(feature = "rust1", since = "1.0.0")]
171171
#[inline]
172172
pub fn fract(self) -> f32 {
173-
core::f32::fract(self)
173+
core::f32::math::fract(self)
174174
}
175175

176176
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
@@ -212,7 +212,7 @@ impl f32 {
212212
#[stable(feature = "rust1", since = "1.0.0")]
213213
#[inline]
214214
pub fn mul_add(self, a: f32, b: f32) -> f32 {
215-
core::f32::mul_add(self, a, b)
215+
core::f32::math::mul_add(self, a, b)
216216
}
217217

218218
/// Calculates Euclidean division, the matching method for `rem_euclid`.
@@ -242,7 +242,7 @@ impl f32 {
242242
#[inline]
243243
#[stable(feature = "euclidean_division", since = "1.38.0")]
244244
pub fn div_euclid(self, rhs: f32) -> f32 {
245-
core::f32::div_euclid(self, rhs)
245+
core::f32::math::div_euclid(self, rhs)
246246
}
247247

248248
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
@@ -279,7 +279,7 @@ impl f32 {
279279
#[inline]
280280
#[stable(feature = "euclidean_division", since = "1.38.0")]
281281
pub fn rem_euclid(self, rhs: f32) -> f32 {
282-
core::f32::rem_euclid(self, rhs)
282+
core::f32::math::rem_euclid(self, rhs)
283283
}
284284

285285
/// Raises a number to an integer power.
@@ -307,7 +307,7 @@ impl f32 {
307307
#[stable(feature = "rust1", since = "1.0.0")]
308308
#[inline]
309309
pub fn powi(self, n: i32) -> f32 {
310-
core::f32::powi(self, n)
310+
core::f32::math::powi(self, n)
311311
}
312312

313313
/// Raises a number to a floating point power.
@@ -362,7 +362,7 @@ impl f32 {
362362
#[stable(feature = "rust1", since = "1.0.0")]
363363
#[inline]
364364
pub fn sqrt(self) -> f32 {
365-
core::f32::sqrt(self)
365+
core::f32::math::sqrt(self)
366366
}
367367

368368
/// Returns `e^(self)`, (the exponential function).
@@ -595,7 +595,7 @@ impl f32 {
595595
)]
596596
pub fn abs_sub(self, other: f32) -> f32 {
597597
#[allow(deprecated)]
598-
core::f32::abs_sub(self, other)
598+
core::f32::math::abs_sub(self, other)
599599
}
600600

601601
/// Returns the cube root of a number.
@@ -622,7 +622,7 @@ impl f32 {
622622
#[stable(feature = "rust1", since = "1.0.0")]
623623
#[inline]
624624
pub fn cbrt(self) -> f32 {
625-
core::f32::cbrt(self)
625+
core::f32::math::cbrt(self)
626626
}
627627

628628
/// Compute the distance between the origin and a point (`x`, `y`) on the

‎library/std/src/f64.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl f64 {
4646
#[stable(feature = "rust1", since = "1.0.0")]
4747
#[inline]
4848
pub fn floor(self) -> f64 {
49-
core::f64::floor(self)
49+
core::f64::math::floor(self)
5050
}
5151

5252
/// Returns the smallest integer greater than or equal to `self`.
@@ -68,7 +68,7 @@ impl f64 {
6868
#[stable(feature = "rust1", since = "1.0.0")]
6969
#[inline]
7070
pub fn ceil(self) -> f64 {
71-
core::f64::ceil(self)
71+
core::f64::math::ceil(self)
7272
}
7373

7474
/// Returns the nearest integer to `self`. If a value is half-way between two
@@ -96,7 +96,7 @@ impl f64 {
9696
#[stable(feature = "rust1", since = "1.0.0")]
9797
#[inline]
9898
pub fn round(self) -> f64 {
99-
core::f64::round(self)
99+
core::f64::math::round(self)
100100
}
101101

102102
/// Returns the nearest integer to a number. Rounds half-way cases to the number
@@ -122,7 +122,7 @@ impl f64 {
122122
#[stable(feature = "round_ties_even", since = "1.77.0")]
123123
#[inline]
124124
pub fn round_ties_even(self) -> f64 {
125-
core::f64::round_ties_even(self)
125+
core::f64::math::round_ties_even(self)
126126
}
127127

128128
/// Returns the integer part of `self`.
@@ -147,7 +147,7 @@ impl f64 {
147147
#[stable(feature = "rust1", since = "1.0.0")]
148148
#[inline]
149149
pub fn trunc(self) -> f64 {
150-
core::f64::trunc(self)
150+
core::f64::math::trunc(self)
151151
}
152152

153153
/// Returns the fractional part of `self`.
@@ -170,7 +170,7 @@ impl f64 {
170170
#[stable(feature = "rust1", since = "1.0.0")]
171171
#[inline]
172172
pub fn fract(self) -> f64 {
173-
core::f64::fract(self)
173+
core::f64::math::fract(self)
174174
}
175175

176176
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
@@ -212,7 +212,7 @@ impl f64 {
212212
#[stable(feature = "rust1", since = "1.0.0")]
213213
#[inline]
214214
pub fn mul_add(self, a: f64, b: f64) -> f64 {
215-
core::f64::mul_add(self, a, b)
215+
core::f64::math::mul_add(self, a, b)
216216
}
217217

218218
/// Calculates Euclidean division, the matching method for `rem_euclid`.
@@ -242,7 +242,7 @@ impl f64 {
242242
#[inline]
243243
#[stable(feature = "euclidean_division", since = "1.38.0")]
244244
pub fn div_euclid(self, rhs: f64) -> f64 {
245-
core::f64::div_euclid(self, rhs)
245+
core::f64::math::div_euclid(self, rhs)
246246
}
247247

248248
/// Calculates the least nonnegative remainder of `self (mod rhs)`.
@@ -279,7 +279,7 @@ impl f64 {
279279
#[inline]
280280
#[stable(feature = "euclidean_division", since = "1.38.0")]
281281
pub fn rem_euclid(self, rhs: f64) -> f64 {
282-
core::f64::rem_euclid(self, rhs)
282+
core::f64::math::rem_euclid(self, rhs)
283283
}
284284

285285
/// Raises a number to an integer power.
@@ -307,7 +307,7 @@ impl f64 {
307307
#[stable(feature = "rust1", since = "1.0.0")]
308308
#[inline]
309309
pub fn powi(self, n: i32) -> f64 {
310-
core::f64::powi(self, n)
310+
core::f64::math::powi(self, n)
311311
}
312312

313313
/// Raises a number to a floating point power.
@@ -362,7 +362,7 @@ impl f64 {
362362
#[stable(feature = "rust1", since = "1.0.0")]
363363
#[inline]
364364
pub fn sqrt(self) -> f64 {
365-
core::f64::sqrt(self)
365+
core::f64::math::sqrt(self)
366366
}
367367

368368
/// Returns `e^(self)`, (the exponential function).
@@ -595,7 +595,7 @@ impl f64 {
595595
)]
596596
pub fn abs_sub(self, other: f64) -> f64 {
597597
#[allow(deprecated)]
598-
core::f64::abs_sub(self, other)
598+
core::f64::math::abs_sub(self, other)
599599
}
600600

601601
/// Returns the cube root of a number.
@@ -622,7 +622,7 @@ impl f64 {
622622
#[stable(feature = "rust1", since = "1.0.0")]
623623
#[inline]
624624
pub fn cbrt(self) -> f64 {
625-
core::f64::cbrt(self)
625+
core::f64::math::cbrt(self)
626626
}
627627

628628
/// Compute the distance between the origin and a point (`x`, `y`) on the

0 commit comments

Comments
 (0)
Please sign in to comment.