Skip to content

Commit e06ac42

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 f3a832d commit e06ac42

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

library/core/src/num/f128.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,13 @@ impl f128 {
856856
// Overflow is impossible
857857
(a + b) / 2.
858858
} else if abs_a < LO {
859-
// Not safe to halve a
859+
// Not safe to halve `a` (would underflow)
860860
a + (b / 2.)
861861
} else if abs_b < LO {
862-
// Not safe to halve b
862+
// Not safe to halve `b` (would underflow)
863863
(a / 2.) + b
864864
} else {
865-
// Not safe to halve a and b
865+
// Safe to halve `a` and `b`
866866
(a / 2.) + (b / 2.)
867867
}
868868
}

library/core/src/num/f16.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -885,13 +885,13 @@ impl f16 {
885885
// Overflow is impossible
886886
(a + b) / 2.
887887
} else if abs_a < LO {
888-
// Not safe to halve a
888+
// Not safe to halve `a` (would underflow)
889889
a + (b / 2.)
890890
} else if abs_b < LO {
891-
// Not safe to halve b
891+
// Not safe to halve `b` (would underflow)
892892
(a / 2.) + b
893893
} else {
894-
// Not safe to halve a and b
894+
// Safe to halve `a` and `b`
895895
(a / 2.) + (b / 2.)
896896
}
897897
}

library/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
}

library/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)