shithub: MicroHs

Download patch

ref: 130472fef7ee4735af14c4796fdcc963f5517001
parent: 5c79f3d3f6e4967c1a60a9a079ab3335c3a948ec
author: Lennart Augustsson <lennart@augustsson.net>
date: Mon Oct 7 20:06:39 EDT 2024

Implement properFraction

--- a/lib/Data/FloatW.hs
+++ b/lib/Data/FloatW.hs
@@ -12,6 +12,7 @@
 import Data.Fractional
 import Data.Function
 import Data.Integer
+import Data.Integral
 import Data.List
 import Data.Ord
 import Data.Ratio
@@ -77,7 +78,12 @@
       (m, e) -> toRational m * 2^^e
 
 instance RealFrac FloatW where
-  properFraction _ = error "FloatW.properFraction not implemented"
+  properFraction x =
+    case decodeFloat x of
+      (m, e) ->   -- x = m * 2^e
+        let m' | e < 0     = m `quot` 2^(-e)
+               | otherwise = m * 2^e
+        in  (fromInteger m', x - fromInteger m')
 
 instance Floating FloatW where
   pi     = 3.141592653589793