Skip to content

Commit

Permalink
Implementation of lengthWordHex
Browse files Browse the repository at this point in the history
  • Loading branch information
trskop committed Sep 6, 2015
1 parent 73bd509 commit 2037231
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/Data/Word/Length.hs
Expand Up @@ -114,4 +114,15 @@ lengthWord64hex n -- Maximum is 18446744073709551615 = 0xffffffffffffffff.
-- n >= 0x10000
{-# INLINE lengthWord64hex #-}

lengthWordHex :: Word -> Int
lengthWordHex n
| is64bit = lengthWord64hex (fromIntegral n)
| otherwise = lengthWord32hex (fromIntegral n)
where
is64bit = maxWord32 < maxWord

maxWord32 = fromIntegral (maxBound :: Word32) :: Word64
maxWord = fromIntegral (maxBound :: Word) :: Word64
{-# INLINE lengthWordHex #-}

-- }}} Hexadecimal ------------------------------------------------------------
10 changes: 4 additions & 6 deletions test/TestCase/Data/Word/Length.hs
Expand Up @@ -38,7 +38,7 @@ import Data.Word.Length
, lengthWord64hex
, lengthWord8
, lengthWord8hex
-- , lengthWordHex
, lengthWordHex
)


Expand Down Expand Up @@ -80,9 +80,9 @@ tests =
, testCase "lengthWord64hex maxBound" test_lengthWord64hex_maxBound
, testProperty "lengthWord64hex = length . show" property_lengthWord64hex

-- , testCase "lengthWordHex minBound" test_lengthWordHex_minBound
-- , testCase "lengthWordHex maxBound" test_lengthWordHex_maxBound
-- , testProperty "lengthWordHex = length . show" property_lengthWordHex
, testCase "lengthWordHex minBound" test_lengthWordHex_minBound
, testCase "lengthWordHex maxBound" test_lengthWordHex_maxBound
, testProperty "lengthWordHex = length . show" property_lengthWordHex
]

numberLength :: Show n => n -> Int
Expand Down Expand Up @@ -227,7 +227,6 @@ property_lengthWord64hex = lengthWord64hex <==> numberLengthHex
-- }}} lengthWord64hex --------------------------------------------------------
-- {{{ lengthWordHex ----------------------------------------------------------

{-
test_lengthWordHex_minBound, test_lengthWordHex_maxBound :: Assertion

test_lengthWordHex_minBound =
Expand All @@ -238,7 +237,6 @@ test_lengthWordHex_maxBound =

property_lengthWordHex :: Word -> Bool
property_lengthWordHex = lengthWordHex <==> numberLengthHex
-}

-- }}} lengthWordHex ----------------------------------------------------------
-- }}} Hexadecimal ------------------------------------------------------------

0 comments on commit 2037231

Please sign in to comment.