fix fpnum to f64 conversion
authoralfadur
Mon, 08 Jul 2019 15:16:05 +0300
changeset 15219 b71bae455926
parent 15218 b2c086629fb8
child 15220 ceb289e8a582
fix fpnum to f64 conversion
rust/fpnum/src/lib.rs
--- a/rust/fpnum/src/lib.rs	Sat Jul 06 22:04:59 2019 +0300
+++ b/rust/fpnum/src/lib.rs	Mon Jul 08 15:16:05 2019 +0300
@@ -131,9 +131,9 @@
     #[inline]
     fn from(n: FPNum) -> Self {
         if n.is_negative() {
-            n.value as f64 / (-0x10000000 as f64)
+            n.value as f64 / -0x1_0000_0000i64 as f64
         } else {
-            n.value as f64 / 0x10000000 as f64
+            n.value as f64 / 0x1_0000_0000i64 as f64
         }
     }
 }
@@ -539,6 +539,8 @@
 
     assert_eq!(n.round(), 7);
     assert_eq!((-n).round(), -7);
+
+    assert_eq!(f64::from(fp!(5/2)), 2.5f64);
 }
 
 #[test]