Skip to content

Commit a060814

Browse files
committed
Add comments to bootstrapping minnum/maxnum
1 parent de46292 commit a060814

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/libcore/intrinsics.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1408,23 +1408,42 @@ extern "rust-intrinsic" {
14081408
}
14091409

14101410
// Simple bootstrap implementations for stage0 compilation
1411+
14111412
/// Returns the minimum of two `f32` values.
14121413
#[cfg(stage0)]
14131414
pub unsafe fn minnumf32(x: f32, y: f32) -> f32 {
1415+
// IEEE754 says: minNum(x, y) is the canonicalized number x if x < y, y if y < x, the
1416+
// canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
1417+
// is either x or y, canonicalized (this means results might differ among implementations).
1418+
// When either x or y is a signalingNaN, then the result is according to 6.2.
1419+
//
1420+
// Since we do not support sNaN in Rust yet, we do not need to handle them.
1421+
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
1422+
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
14141423
(if x < y || y != y { x } else { y }) * 1.0
14151424
}
14161425
/// Returns the minimum of two `f64` values.
14171426
#[cfg(stage0)]
14181427
pub unsafe fn minnumf64(x: f64, y: f64) -> f64 {
1428+
// Identical to the `f32` case.
14191429
(if x < y || y != y { x } else { y }) * 1.0
14201430
}
14211431
/// Returns the maximum of two `f32` values.
14221432
#[cfg(stage0)]
14231433
pub unsafe fn maxnumf32(x: f32, y: f32) -> f32 {
1434+
// IEEE754 says: maxNum(x, y) is the canonicalized number y if x < y, x if y < x, the
1435+
// canonicalized number if one operand is a number and the other a quiet NaN. Otherwise it
1436+
// is either x or y, canonicalized (this means results might differ among implementations).
1437+
// When either x or y is a signalingNaN, then the result is according to 6.2.
1438+
//
1439+
// Since we do not support sNaN in Rust yet, we do not need to handle them.
1440+
// FIXME(nagisa): due to https://bugs.llvm.org/show_bug.cgi?id=33303 we canonicalize by
1441+
// multiplying by 1.0. Should switch to the `canonicalize` when it works.
14241442
(if x < y || x != x { y } else { x }) * 1.0
14251443
}
14261444
/// Returns the maximum of two `f64` values.
14271445
#[cfg(stage0)]
14281446
pub unsafe fn maxnumf64(x: f64, y: f64) -> f64 {
1447+
// Identical to the `f32` case.
14291448
(if x < y || x != x { y } else { x }) * 1.0
14301449
}

0 commit comments

Comments
 (0)