summaryrefslogtreecommitdiff
path: root/lib/Graphics/Fountainhead/Type.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Graphics/Fountainhead/Type.hs')
-rw-r--r--lib/Graphics/Fountainhead/Type.hs28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/Graphics/Fountainhead/Type.hs b/lib/Graphics/Fountainhead/Type.hs
index e809d9c..c412b74 100644
--- a/lib/Graphics/Fountainhead/Type.hs
+++ b/lib/Graphics/Fountainhead/Type.hs
@@ -14,14 +14,40 @@ module Graphics.Fountainhead.Type
) where
import Data.Bits ((.>>.), (.&.))
-import Data.Int (Int16)
+import Data.Int (Int16, Int32)
import Data.Word (Word16, Word32)
import Data.Time (Day(..))
import Data.Time.Calendar.OrdinalDate (fromOrdinalDate)
+import Data.Fixed (HasResolution(..))
newtype Fixed32 = Fixed32 Word32
deriving (Eq, Show)
+instance Num Fixed32
+ where
+ (Fixed32 x) + (Fixed32 y) = Fixed32 $ x + y
+ (Fixed32 x) - (Fixed32 y) = Fixed32 $ x - y
+ (Fixed32 x) * (Fixed32 y) = Fixed32 $ div (x * y) 65536
+ abs (Fixed32 x) = Fixed32 $ fromIntegral $ abs (fromIntegral x :: Int32)
+ signum (Fixed32 x)
+ | x == 0 = Fixed32 0
+ | (fromIntegral x :: Int32) < 0 = Fixed32 0xffff0000
+ | otherwise = Fixed32 0x10000
+ fromInteger x = Fixed32 $ fromInteger $ x * 65536
+
+instance Ord Fixed32
+ where
+ compare (Fixed32 x) (Fixed32 y) =
+ compare (fromIntegral x :: Int32) (fromIntegral y)
+
+instance Real Fixed32
+ where
+ toRational (Fixed32 x) = toRational (fromIntegral x :: Int32) / 65536.0
+
+instance HasResolution Fixed32
+ where
+ resolution = const 65536
+
newtype F2Dot14 = F2Dot14 Int16
deriving (Eq, Show)