Skip to content

Commit d8c01c4

Browse files
committed
better comments explaining why we can use expressions
1 parent 4115292 commit d8c01c4

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

library/core/src/num/f128.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ impl f128 {
645645
#[unstable(feature = "f128", issue = "116909")]
646646
#[must_use = "this returns the result of the operation, without modifying the original"]
647647
pub const fn to_degrees(self) -> Self {
648+
// The division here is correctly rounded with respect to the true value of 180/π.
649+
// Although π is irrational and already rounded, the double rounding happens
650+
// to produce correct result for f128.
648651
const PIS_IN_180: f128 = 180.0 / consts::PI;
649652
self * PIS_IN_180
650653
}

library/core/src/num/f32.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ impl f32 {
872872
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
873873
#[inline]
874874
pub const fn to_radians(self) -> f32 {
875+
// The division here is correctly rounded with respect to the true value of π/180.
876+
// Although π is irrational and already rounded, the double rounding happens
877+
// to produce correct result for f32.
875878
const RADS_PER_DEG: f32 = consts::PI / 180.0;
876879
self * RADS_PER_DEG
877880
}

library/core/src/num/f64.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,9 @@ impl f64 {
869869
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
870870
#[inline]
871871
pub const fn to_degrees(self) -> f64 {
872-
// The division here is correctly rounded with respect to the true
873-
// value of 180/π. (This differs from f32, where a constant must be
874-
// used to ensure a correctly rounded result.)
872+
// The division here is correctly rounded with respect to the true value of 180/π.
873+
// Although π is irrational and already rounded, the double rounding happens
874+
// to produce correct result for f64.
875875
const PIS_IN_180: f64 = 180.0 / consts::PI;
876876
self * PIS_IN_180
877877
}
@@ -891,6 +891,9 @@ impl f64 {
891891
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
892892
#[inline]
893893
pub const fn to_radians(self) -> f64 {
894+
// The division here is correctly rounded with respect to the true value of π/180.
895+
// Although π is irrational and already rounded, the double rounding happens
896+
// to produce correct result for f64.
894897
const RADS_PER_DEG: f64 = consts::PI / 180.0;
895898
self * RADS_PER_DEG
896899
}

0 commit comments

Comments
 (0)