commit 0fb2edf2d770b1e74302b1ec32f0431c1a01b5e3
parent c6957bcca894d968e17b890e806140e0a5378545
Author: Jared Tobin <jared@jtobin.io>
Date: Sun, 30 Nov 2025 12:26:01 +0400
wide: add num instance
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/lib/Data/Word/Wide.hs b/lib/Data/Word/Wide.hs
@@ -57,6 +57,17 @@ instance Show Wide where
show (Wide (# Limb a, Limb b #)) =
"(" <> show (W# a) <> ", " <> show (W# b) <> ")"
+instance Num Wide where
+ (+) = add
+ (-) = sub
+ (*) = mul
+ abs = id
+ fromInteger = to
+ negate w = add (not w) (Wide (# Limb 1##, Limb 0## #))
+ signum a = case a of
+ Wide (# Limb 0##, Limb 0## #) -> 0
+ _ -> 1
+
instance NFData Wide where
rnf (Wide a) = case a of (# _, _ #) -> ()