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 @@ impl 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 @@ impl 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 @@ impl 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 @@ impl 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.)
}
}