File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4050,7 +4050,9 @@ impl Computable {
40504050 ) {
40514051 match ( left_sign, right_sign) {
40524052 ( Sign :: Plus , Sign :: Minus ) if left_msd > right_msd => Some ( Sign :: Plus ) ,
4053- ( Sign :: Minus , Sign :: Plus ) if right_msd > left_msd => Some ( Sign :: Minus ) ,
4053+ ( Sign :: Plus , Sign :: Minus ) if right_msd > left_msd => Some ( Sign :: Minus ) ,
4054+ ( Sign :: Minus , Sign :: Plus ) if left_msd > right_msd => Some ( Sign :: Minus ) ,
4055+ ( Sign :: Minus , Sign :: Plus ) if right_msd > left_msd => Some ( Sign :: Plus ) ,
40544056 ( Sign :: Plus , Sign :: Plus ) => Some ( Sign :: Plus ) ,
40554057 ( Sign :: Minus , Sign :: Minus ) => Some ( Sign :: Minus ) ,
40564058 ( Sign :: NoSign , Sign :: NoSign ) => Some ( Sign :: NoSign ) ,
Original file line number Diff line number Diff line change @@ -375,6 +375,8 @@ impl Real {
375375 use crate :: real:: Class ;
376376
377377 if matches ! ( self . class, Class :: One )
378+ && self . computable . is_none ( )
379+ && self . signal . is_none ( )
378380 && let fast @ Some ( _) = self . rational . to_f64_lossy ( )
379381 {
380382 // Exact rationals can often be rounded to f64 without touching the
@@ -761,6 +763,17 @@ mod tests {
761763 assert ! ( ( approx + std:: f64 :: consts:: SQRT_2 ) . abs( ) < 1e-15 ) ;
762764 }
763765
766+ #[ test]
767+ fn borrowed_f64_lossy_keeps_positive_translation_over_negative_symbolic_tail ( ) {
768+ let sqrt_two = Real :: from ( 2 ) . sqrt ( ) . unwrap ( ) ;
769+ let value = Real :: from ( 10 ) + ( Real :: from ( 1 ) - sqrt_two) ;
770+
771+ let approx = value. to_f64_lossy ( ) . unwrap ( ) ;
772+
773+ assert ! ( approx. is_sign_positive( ) ) ;
774+ assert ! ( ( approx - ( 11.0 - std:: f64 :: consts:: SQRT_2 ) ) . abs( ) < 1e-12 ) ;
775+ }
776+
764777 #[ test]
765778 #[ cfg( all( feature = "cached-f32-approx" , feature = "cached-f64-approx" ) ) ]
766779 fn primitive_approx_cache_fills_and_upgrades ( ) {
You can’t perform that action at this time.
0 commit comments