Update comments for {f16, f32, f64, f128}::midpoint

Clarify what makes some operations not safe, and correct comment in the
default branch ("not safe" -> "safe").
This commit is contained in:
Trevor Gross 2024-07-17 20:45:13 -04:00
parent e18036c769
commit 43836421f8
4 changed files with 12 additions and 12 deletions

View file

@ -851,13 +851,13 @@ pub fn midpoint(self, other: f128) -> f128 {
// Overflow is impossible
(a + b) / 2.
} else if abs_a < LO {
// Not safe to halve a
// Not safe to halve `a` (would underflow)
a + (b / 2.)
} else if abs_b < LO {
// Not safe to halve b
// Not safe to halve `b` (would underflow)
(a / 2.) + b
} else {
// Not safe to halve a and b
// Safe to halve `a` and `b`
(a / 2.) + (b / 2.)
}
}

View file

@ -880,13 +880,13 @@ pub fn midpoint(self, other: f16) -> f16 {
// Overflow is impossible
(a + b) / 2.
} else if abs_a < LO {
// Not safe to halve a
// Not safe to halve `a` (would underflow)
a + (b / 2.)
} else if abs_b < LO {
// Not safe to halve b
// Not safe to halve `b` (would underflow)
(a / 2.) + b
} else {
// Not safe to halve a and b
// Safe to halve `a` and `b`
(a / 2.) + (b / 2.)
}
}

View file

@ -1070,13 +1070,13 @@ pub fn midpoint(self, other: f32) -> f32 {
// Overflow is impossible
(a + b) / 2.
} else if abs_a < LO {
// Not safe to halve a
// Not safe to halve `a` (would underflow)
a + (b / 2.)
} else if abs_b < LO {
// Not safe to halve b
// Not safe to halve `b` (would underflow)
(a / 2.) + b
} else {
// Not safe to halve a and b
// Safe to halve `a` and `b`
(a / 2.) + (b / 2.)
}
}

View file

@ -1064,13 +1064,13 @@ pub fn midpoint(self, other: f64) -> f64 {
// Overflow is impossible
(a + b) / 2.
} else if abs_a < LO {
// Not safe to halve a
// Not safe to halve `a` (would underflow)
a + (b / 2.)
} else if abs_b < LO {
// Not safe to halve b
// Not safe to halve `b` (would underflow)
(a / 2.) + b
} else {
// Not safe to halve a and b
// Safe to halve `a` and `b`
(a / 2.) + (b / 2.)
}
}