We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e6b3ec9 commit 7d5024eCopy full SHA for 7d5024e
src/Data/ZigZag.hs
@@ -2,6 +2,7 @@
2
{-# LANGUAGE FunctionalDependencies #-}
3
{-# LANGUAGE MultiParamTypeClasses #-}
4
{-# LANGUAGE ScopedTypeVariables #-}
5
+{-# LANGUAGE InstanceSigs #-}
6
7
-- |<https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba ZigZag encoding> of signed integrals.
8
module Data.ZigZag (ZigZag(..)) where
@@ -119,9 +120,11 @@ instance ZigZag Int32 Word32
119
120
instance ZigZag Int64 Word64
121
122
instance ZigZag Integer Natural where
123
+ zigZag :: Integer -> Natural
124
zigZag x
125
| x >= 0 = fromIntegral $ x `shiftL` 1
126
| otherwise = fromIntegral $ negate (x `shiftL` 1) - 1
127
128
+ zagZig :: Natural -> Integer
129
zagZig u = let s = fromIntegral u
130
in ((s `shiftR` 1) `xor` negate (s .&. 1))
0 commit comments