File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff 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 f64 and f128. However, f32 and f16 require a literal to avoid error.
648651 const PIS_IN_180 : f128 = 180.0 / consts:: PI ;
649652 self * PIS_IN_180
650653 }
Original file line number Diff line number Diff 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 f64 and f32. However, f128 and f16 require a literal to avoid error.
875878 const RADS_PER_DEG : f32 = consts:: PI / 180.0 ;
876879 self * RADS_PER_DEG
877880 }
Original file line number Diff line number Diff 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 and f128. However, f32 and f16 require a literal to avoid error.
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 and f32. However, f128 and f16 require a literal to avoid error.
894897 const RADS_PER_DEG : f64 = consts:: PI / 180.0 ;
895898 self * RADS_PER_DEG
896899 }
You can’t perform that action at this time.
0 commit comments