Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,17 +977,17 @@ impl f128 {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub const fn midpoint(self, other: f128) -> f128 {
const HI: f128 = f128::MAX / 2.;
const HI: f128 = f128::MAX * 0.5;

let (a, b) = (self, other);
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
(a + b) / 2.
(a + b) * 0.5
} else {
(a / 2.) + (b / 2.)
(a * 0.5) + (b * 0.5)
}
}

Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,17 +973,17 @@ impl f16 {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub const fn midpoint(self, other: f16) -> f16 {
const HI: f16 = f16::MAX / 2.;
const HI: f16 = f16::MAX * 0.5;

let (a, b) = (self, other);
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
(a + b) / 2.
(a + b) * 0.5
} else {
(a / 2.) + (b / 2.)
(a * 0.5) + (b * 0.5)
}
}

Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,20 +1164,20 @@ impl f32 {
target_arch = "wasm32",
target_arch = "wasm64",
) => {
((self as f64 + other as f64) / 2.0) as f32
((self as f64 + other as f64) * 0.5) as f32
}
_ => {
const HI: f32 = f32::MAX / 2.;
const HI: f32 = f32::MAX * 0.5;

let (a, b) = (self, other);
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
(a + b) / 2.
(a + b) * 0.5
} else {
(a / 2.) + (b / 2.)
(a * 0.5) + (b * 0.5)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,17 +1150,17 @@ impl f64 {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
pub const fn midpoint(self, other: f64) -> f64 {
const HI: f64 = f64::MAX / 2.;
const HI: f64 = f64::MAX * 0.5;

let (a, b) = (self, other);
let abs_a = a.abs();
let abs_b = b.abs();

if abs_a <= HI && abs_b <= HI {
// Overflow is impossible
(a + b) / 2.
(a + b) * 0.5
} else {
(a / 2.) + (b / 2.)
(a * 0.5) + (b * 0.5)
}
}

Expand Down
Loading