Skip to content

Commit

Permalink
Update comments for {f16, f32, f64, f128}::midpoint
Browse files Browse the repository at this point in the history
Clarify what makes some operations not safe, and correct comment in the
default branch ("not safe" -> "safe").
  • Loading branch information
tgross35 committed Aug 1, 2024
1 parent e18036c commit 4383642
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
}
}
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 @@ -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.)
}
}
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
}
}
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 @@ -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.)
}
}
Expand Down

0 comments on commit 4383642

Please sign in to comment.