Skip to content

Commit 1f5c1cf

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 6a99a10 commit 1f5c1cf

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
@@ -874,13 +874,13 @@ impl f128 {
874874
// Overflow is impossible
875875
(a + b) / 2.
876876
} else if abs_a < LO {
877-
// Not safe to halve a
877+
// Not safe to halve a (would underflow)
878878
a + (b / 2.)
879879
} else if abs_b < LO {
880-
// Not safe to halve b
880+
// Not safe to halve b (would underflow)
881881
(a / 2.) + b
882882
} else {
883-
// Not safe to halve a and b
883+
// Safe to halve a and b
884884
(a / 2.) + (b / 2.)
885885
}
886886
}

library/core/src/num/f16.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,13 @@ impl f16 {
904904
// Overflow is impossible
905905
(a + b) / 2.
906906
} else if abs_a < LO {
907-
// Not safe to halve a
907+
// Not safe to halve a (would underflow)
908908
a + (b / 2.)
909909
} else if abs_b < LO {
910-
// Not safe to halve b
910+
// Not safe to halve b (would underflow)
911911
(a / 2.) + b
912912
} else {
913-
// Not safe to halve a and b
913+
// Safe to halve a and b
914914
(a / 2.) + (b / 2.)
915915
}
916916
}

library/core/src/num/f32.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1066,13 +1066,13 @@ impl f32 {
10661066
// Overflow is impossible
10671067
(a + b) / 2.
10681068
} else if abs_a < LO {
1069-
// Not safe to halve a
1069+
// Not safe to halve a (would underflow)
10701070
a + (b / 2.)
10711071
} else if abs_b < LO {
1072-
// Not safe to halve b
1072+
// Not safe to halve b (would underflow)
10731073
(a / 2.) + b
10741074
} else {
1075-
// Not safe to halve a and b
1075+
// Safe to halve a and b
10761076
(a / 2.) + (b / 2.)
10771077
}
10781078
}

library/core/src/num/f64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1060,13 +1060,13 @@ impl f64 {
10601060
// Overflow is impossible
10611061
(a + b) / 2.
10621062
} else if abs_a < LO {
1063-
// Not safe to halve a
1063+
// Not safe to halve a (would underflow)
10641064
a + (b / 2.)
10651065
} else if abs_b < LO {
1066-
// Not safe to halve b
1066+
// Not safe to halve b (would underflow)
10671067
(a / 2.) + b
10681068
} else {
1069-
// Not safe to halve a and b
1069+
// Safe to halve a and b
10701070
(a / 2.) + (b / 2.)
10711071
}
10721072
}

0 commit comments

Comments
 (0)