Skip to content

Commit 21d297b

Browse files
committed
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").
1 parent ad27d08 commit 21d297b

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Diff for: core/src/num/f128.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,13 @@ impl f128 {
851851
// Overflow is impossible
852852
(a + b) / 2.
853853
} else if abs_a < LO {
854-
// Not safe to halve a
854+
// Not safe to halve `a` (would underflow)
855855
a + (b / 2.)
856856
} else if abs_b < LO {
857-
// Not safe to halve b
857+
// Not safe to halve `b` (would underflow)
858858
(a / 2.) + b
859859
} else {
860-
// Not safe to halve a and b
860+
// Safe to halve `a` and `b`
861861
(a / 2.) + (b / 2.)
862862
}
863863
}

Diff for: core/src/num/f16.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,13 @@ impl f16 {
880880
// Overflow is impossible
881881
(a + b) / 2.
882882
} else if abs_a < LO {
883-
// Not safe to halve a
883+
// Not safe to halve `a` (would underflow)
884884
a + (b / 2.)
885885
} else if abs_b < LO {
886-
// Not safe to halve b
886+
// Not safe to halve `b` (would underflow)
887887
(a / 2.) + b
888888
} else {
889-
// Not safe to halve a and b
889+
// Safe to halve `a` and `b`
890890
(a / 2.) + (b / 2.)
891891
}
892892
}

Diff for: core/src/num/f32.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1070,13 +1070,13 @@ impl f32 {
10701070
// Overflow is impossible
10711071
(a + b) / 2.
10721072
} else if abs_a < LO {
1073-
// Not safe to halve a
1073+
// Not safe to halve `a` (would underflow)
10741074
a + (b / 2.)
10751075
} else if abs_b < LO {
1076-
// Not safe to halve b
1076+
// Not safe to halve `b` (would underflow)
10771077
(a / 2.) + b
10781078
} else {
1079-
// Not safe to halve a and b
1079+
// Safe to halve `a` and `b`
10801080
(a / 2.) + (b / 2.)
10811081
}
10821082
}

Diff for: core/src/num/f64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1064,13 +1064,13 @@ impl f64 {
10641064
// Overflow is impossible
10651065
(a + b) / 2.
10661066
} else if abs_a < LO {
1067-
// Not safe to halve a
1067+
// Not safe to halve `a` (would underflow)
10681068
a + (b / 2.)
10691069
} else if abs_b < LO {
1070-
// Not safe to halve b
1070+
// Not safe to halve `b` (would underflow)
10711071
(a / 2.) + b
10721072
} else {
1073-
// Not safe to halve a and b
1073+
// Safe to halve `a` and `b`
10741074
(a / 2.) + (b / 2.)
10751075
}
10761076
}

0 commit comments

Comments
 (0)