Skip to content

Commit 219f155

Browse files
authored
Unrolled build for #146225
Rollup merge of #146225 - Jules-Bertholet:simplify-float-midpoint, r=tgross35 Simplify `{f16, f32, f64, f128}::midpoint()` `(float_ty::MAX / 2) - (float_ty::MIN_POSITIVE * 2)` equals `(float_ty::MAX / 2) + (float_ty::MIN_POSITIVE * 2)` equals `(float_ty::MAX / 2)`. So these branches are pointless. CC `@Urgau` who wrote the original implementation in #92048; does this seem right? `@rustbot` label A-floating-point
2 parents 99317ef + bc17bcd commit 219f155

File tree

4 files changed

+0
-32
lines changed

4 files changed

+0
-32
lines changed

library/core/src/num/f128.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ impl f128 {
832832
#[unstable(feature = "f128", issue = "116909")]
833833
#[rustc_const_unstable(feature = "f128", issue = "116909")]
834834
pub const fn midpoint(self, other: f128) -> f128 {
835-
const LO: f128 = f128::MIN_POSITIVE * 2.;
836835
const HI: f128 = f128::MAX / 2.;
837836

838837
let (a, b) = (self, other);
@@ -842,14 +841,7 @@ impl f128 {
842841
if abs_a <= HI && abs_b <= HI {
843842
// Overflow is impossible
844843
(a + b) / 2.
845-
} else if abs_a < LO {
846-
// Not safe to halve `a` (would underflow)
847-
a + (b / 2.)
848-
} else if abs_b < LO {
849-
// Not safe to halve `b` (would underflow)
850-
(a / 2.) + b
851844
} else {
852-
// Safe to halve `a` and `b`
853845
(a / 2.) + (b / 2.)
854846
}
855847
}

library/core/src/num/f16.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ impl f16 {
820820
#[unstable(feature = "f16", issue = "116909")]
821821
#[rustc_const_unstable(feature = "f16", issue = "116909")]
822822
pub const fn midpoint(self, other: f16) -> f16 {
823-
const LO: f16 = f16::MIN_POSITIVE * 2.;
824823
const HI: f16 = f16::MAX / 2.;
825824

826825
let (a, b) = (self, other);
@@ -830,14 +829,7 @@ impl f16 {
830829
if abs_a <= HI && abs_b <= HI {
831830
// Overflow is impossible
832831
(a + b) / 2.
833-
} else if abs_a < LO {
834-
// Not safe to halve `a` (would underflow)
835-
a + (b / 2.)
836-
} else if abs_b < LO {
837-
// Not safe to halve `b` (would underflow)
838-
(a / 2.) + b
839832
} else {
840-
// Safe to halve `a` and `b`
841833
(a / 2.) + (b / 2.)
842834
}
843835
}

library/core/src/num/f32.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ impl f32 {
10251025
((self as f64 + other as f64) / 2.0) as f32
10261026
}
10271027
_ => {
1028-
const LO: f32 = f32::MIN_POSITIVE * 2.;
10291028
const HI: f32 = f32::MAX / 2.;
10301029

10311030
let (a, b) = (self, other);
@@ -1035,14 +1034,7 @@ impl f32 {
10351034
if abs_a <= HI && abs_b <= HI {
10361035
// Overflow is impossible
10371036
(a + b) / 2.
1038-
} else if abs_a < LO {
1039-
// Not safe to halve `a` (would underflow)
1040-
a + (b / 2.)
1041-
} else if abs_b < LO {
1042-
// Not safe to halve `b` (would underflow)
1043-
(a / 2.) + b
10441037
} else {
1045-
// Safe to halve `a` and `b`
10461038
(a / 2.) + (b / 2.)
10471039
}
10481040
}

library/core/src/num/f64.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ impl f64 {
10261026
#[stable(feature = "num_midpoint", since = "1.85.0")]
10271027
#[rustc_const_stable(feature = "num_midpoint", since = "1.85.0")]
10281028
pub const fn midpoint(self, other: f64) -> f64 {
1029-
const LO: f64 = f64::MIN_POSITIVE * 2.;
10301029
const HI: f64 = f64::MAX / 2.;
10311030

10321031
let (a, b) = (self, other);
@@ -1036,14 +1035,7 @@ impl f64 {
10361035
if abs_a <= HI && abs_b <= HI {
10371036
// Overflow is impossible
10381037
(a + b) / 2.
1039-
} else if abs_a < LO {
1040-
// Not safe to halve `a` (would underflow)
1041-
a + (b / 2.)
1042-
} else if abs_b < LO {
1043-
// Not safe to halve `b` (would underflow)
1044-
(a / 2.) + b
10451038
} else {
1046-
// Safe to halve `a` and `b`
10471039
(a / 2.) + (b / 2.)
10481040
}
10491041
}

0 commit comments

Comments
 (0)