crackNum 1.0 → 1.1
raw patch · 5 files changed
+96/−58 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Numbers.CrackNum: crackDP :: Integer -> FP
- Data.Numbers.CrackNum: crackHP :: Integer -> FP
- Data.Numbers.CrackNum: crackSP :: Integer -> FP
+ Data.Numbers.CrackNum: crackFP :: Precision -> Integer -> FP
Files
- CHANGES.md +5/−1
- Data/Numbers/CrackNum.hs +21/−31
- Data/Numbers/CrackNum/Main.hs +18/−22
- README.md +49/−0
- crackNum.cabal +3/−4
CHANGES.md view
@@ -1,7 +1,11 @@ * Hackage: <http://hackage.haskell.org/package/crackNum> * GitHub: <http://leventerkok.github.com/crackNum/> -* Latest Hackage released version: 1.0, 2015-04-01+* Latest Hackage released version: 1.1, 2015-04-02++### Version 1.1, 2015-04-02+ + * Clean-up the API, examples etc. ### Version 1.0, 2015-04-01
Data/Numbers/CrackNum.hs view
@@ -15,7 +15,7 @@ ( -- * Internal representation of a Floating-point numbers FP(..), Precision(..), IPrecision(..), Kind(..) -- * Creating FP values- , crackHP, crackSP, crackDP, convertToIEEE+ , crackFP, convertToIEEE -- * Displaying FP and Int/Word values , displayFP, displayInt )@@ -34,21 +34,11 @@ import Data.Numbers.CrackNum.Data import Data.Numbers.CrackNum.Utils --- | Crack a Haskell Integer value as a Half-precision floating point number-crackHP :: Integer -> FP-crackHP = crack HP 15 15 [14, 13 .. 10] [9, 8 .. 0]---- | Crack a Haskell Integer value as a Single-precision floating point number-crackSP :: Integer -> FP-crackSP = crack SP 127 31 [30, 29 .. 23] [22, 21 .. 0]---- | Crack a Haskell Integer value as a Double-precision floating point number-crackDP :: Integer -> FP-crackDP = crack DP 1023 63 [62, 61 .. 52] [51, 50 .. 0]---- | Use Haskell Float to represent HP-hpVal :: Bool -> Int -> [Bool] -> Float-hpVal = spVal+-- | Crack a Haskell Integer value as the given precision floating value+crackFP :: Precision -> Integer -> FP+crackFP HP = crack HP 15 15 [14, 13 .. 10] [9, 8 .. 0]+crackFP SP = crack SP 127 31 [30, 29 .. 23] [22, 21 .. 0]+crackFP DP = crack DP 1023 63 [62, 61 .. 52] [51, 50 .. 0] -- | Use Haskell Float to represent SP spVal :: Bool -> Int -> [Bool] -> Float@@ -128,7 +118,7 @@ Normal -> nval False ++ " (NORMAL)" nval dn = (if sign then "-" else "+") ++ v where v = case prec of- HP -> showGFloat Nothing (hpVal dn expt fracBits) ""+ HP -> showGFloat Nothing (spVal dn expt fracBits) "" SP -> showGFloat Nothing (spVal dn expt fracBits) "" DP -> showGFloat Nothing (dpVal dn expt fracBits) "" @@ -173,23 +163,23 @@ where i = map toLower (dropWhile (== '+') input) specials :: [(String, (FP, FP))] specials = [ (s, (cvtF f, cvtD d))- | (s, (f, d)) <- [ ("infinity", ( infinity, infinity))- , ("-infinity", (-infinity, -infinity))- , ("0", ( 0, 0))- , ("-0", (-0, -0))- , ("max", ( maxFinite, maxFinite))- , ("-max", (-maxFinite, -maxFinite))- , ("min", ( minNormal, minNormal))- , ("-min", (-minNormal, -minNormal))- , ("epsilon", ( epsilon, epsilon))] ]- ++ [ ("ulp", (crackSP 1, crackDP 1))- , ("snan", (crackSP 0x7f800001, crackDP 0x7ff0000000000001))- , ("qnan", (crackSP 0x7f8c0001, crackDP 0x7ff8000000000001))+ | (s, (f, d)) <- [ ("infinity", ( infinity, infinity))+ , ("-infinity", (-infinity, - infinity))+ , ("0", ( 0, 0))+ , ("-0", (-0, - 0))+ , ("max", ( maxFinite, maxFinite))+ , ("-max", (-maxFinite, - maxFinite))+ , ("min", ( minNormal, minNormal))+ , ("-min", (-minNormal, - minNormal))+ , ("epsilon", ( epsilon, epsilon))] ]+ ++ [ ("ulp", (crackFP SP 1, crackFP DP 1))+ , ("snan", (crackFP SP 0x7f800001, crackFP DP 0x7ff0000000000001))+ , ("qnan", (crackFP SP 0x7f8c0001, crackFP DP 0x7ff8000000000001)) ] cvtF :: Float -> FP- cvtF = crackSP . fromIntegral . floatToWord+ cvtF = crackFP SP . fromIntegral . floatToWord cvtD :: Double -> FP- cvtD = crackDP . fromIntegral . doubleToWord+ cvtD = crackFP DP . fromIntegral . doubleToWord mbF, mbD :: Maybe FP (mbF, mbD) = case (i `lookup` specials, reads i, reads i) of (Just (f, d), _ , _ ) -> (Just f, Just d)
Data/Numbers/CrackNum/Main.hs view
@@ -54,7 +54,7 @@ , Option "" ["uq"] (NoArg (IType W64)) "64 bit unsigned quad" , Option "" ["toIEEE"] (ReqArg ToIEEE "n") "Convert from decimal to IEEE SP/DP formats." , Option "l" ["lanes"] (ReqArg Lanes "n") "number of lanes"- , Option "" ["help"] (NoArg Help) "this help message"+ , Option "h?" ["help"] (NoArg Help) "print help, with examples" , Option "v" ["version"] (NoArg Version) "print version info" ] @@ -71,7 +71,7 @@ putStrLn $ " " ++ pn ++ " --sp 01111111110000000000000000000000" putStrLn $ " " ++ pn ++ " -l2 --hp 01111111110000000000000000000000" putStrLn $ " " ++ pn ++ " --sb 7f"- putStrLn $ " " ++ pn ++ " --sp --toIEEE=2.3"+ putStrLn $ " " ++ pn ++ " --sp --toIEEE=-2.3e6" putStrLn $ " " ++ pn ++ " --dp --toIEEE=max" putStrLn $ " " ++ pn ++ " --dp --toIEEE=ulp" putStrLn ""@@ -102,24 +102,20 @@ then putStrLn $ pn ++ " v" ++ showVersion version ++ ", " ++ copyRight else process pn os rs (_, _, errs) -> do mapM_ putStrLn errs- usage pn+ putStr $ helpStr pn where getChosenPrec os = case [p | p@FPType{} <- os] ++ [p | p@IType{} <- os] of [p] -> Just p _ -> Nothing process pn os rs- | Help `elem` os- = do putStrLn $ pn ++ " v" ++ showVersion version ++ ", " ++ copyRight- usage pn- | Just v <- listToMaybe [s | ToIEEE s <- os], null rs- = case mbPrec of- Just (FPType p) -> putStrLn $ displayFP $ convertToIEEE p v- _ -> usage pn- | all isDigit lcs && lc > 0- = case mbPrec of- Just p -> lane pn lc p rs- _ -> usage pn- | True- = usage pn+ | Help `elem` os+ = do putStrLn $ pn ++ " v" ++ showVersion version ++ ", " ++ copyRight+ usage pn+ | Just v <- listToMaybe [s | ToIEEE s <- os], null rs, Just (FPType p) <- mbPrec+ = putStrLn $ displayFP $ convertToIEEE p v+ | all isDigit lcs && lc > 0, Just p <- mbPrec+ = lane pn lc p rs+ | True+ = putStr $ helpStr pn where mbPrec = getChosenPrec os lcs = fromMaybe (show (guessLaneCount mbPrec (cleanUp (concat rs)))) (listToMaybe (reverse [n | Lanes n <- os])) lc = read lcs@@ -200,12 +196,12 @@ unpack :: String -> Flag -> String -> IO () unpack pn prec orig = case (prec, length s, allHex, allBin) of- (FPType HP, 4, True, _ ) -> putStrLn $ displayFP $ crackHP hexVal- (FPType HP, 16, _ , True) -> putStrLn $ displayFP $ crackHP binVal- (FPType SP, 8, True, _ ) -> putStrLn $ displayFP $ crackSP hexVal- (FPType SP, 32, _ , True) -> putStrLn $ displayFP $ crackSP binVal- (FPType DP, 16, True, _ ) -> putStrLn $ displayFP $ crackDP hexVal- (FPType DP, 64, _ , True) -> putStrLn $ displayFP $ crackDP binVal+ (FPType HP, 4, True, _ ) -> putStrLn $ displayFP $ crackFP HP hexVal+ (FPType HP, 16, _ , True) -> putStrLn $ displayFP $ crackFP HP binVal+ (FPType SP, 8, True, _ ) -> putStrLn $ displayFP $ crackFP SP hexVal+ (FPType SP, 32, _ , True) -> putStrLn $ displayFP $ crackFP SP binVal+ (FPType DP, 16, True, _ ) -> putStrLn $ displayFP $ crackFP DP hexVal+ (FPType DP, 64, _ , True) -> putStrLn $ displayFP $ crackFP DP binVal (IType I8, 2, True, _ ) -> putStrLn $ displayInt I8 hexVal (IType I8, 8, _ , True) -> putStrLn $ displayInt I8 binVal (IType W8, 2, True, _ ) -> putStrLn $ displayInt W8 hexVal
README.md view
@@ -20,3 +20,52 @@ Display/show/analyze IEEE754 Half-precision, Single-precision, and Double-precision values; along with various integer types: Signed/Unsigned, 8, 16, 32, 64 bits.++ $ crackNum --help+ crackNum v1.1, (c) Levent Erkok. Released with a BSD3 license.+ Usage: crackNum precision bit/hex-pattern+ --hp 16 bit half precision+ --sp 32 bit single precision+ --dp 64 bit double precision+ --sb 8 bit signed byte+ --sw 16 bit signed word+ --sd 32 bit signed double+ --sq 64 bit signed quad+ --ub 8 bit unsigned byte+ --uw 16 bit unsigned word+ --ud 32 bit unsigned double+ --uq 64 bit unsigned quad+ --toIEEE=n Convert from decimal to IEEE SP/DP formats.+ -l n --lanes=n number of lanes+ -h, -? --help print help, with examples+ -v --version print version info+ + Examples:+ + crackNum --hp fc00+ crackNum --sp fc00 abcd+ crackNum --dp fc00 abc1 2345 6789+ crackNum --sp 01111111110000000000000000000000+ crackNum -l2 --hp 01111111110000000000000000000000+ crackNum --sb 7f+ crackNum --sp --toIEEE=-2.3e6+ crackNum --dp --toIEEE=max+ crackNum --dp --toIEEE=ulp+ + Notes:+ - You can use hexadecimal or binary as input.+ - You can use _,- or space as a digit to improve readability.+ - You can give input for multiple lanes, we will guess the #of lanes for you.+ Or, you can specify number of lanes with the -l option.+ - For "toIEEE" option:+ - You can enter a number in decimal notation (like 2.3)+ - OR, enter one of the following:+ * infinity, -infinity: Positive/Negative infinities+ * snan, qnan: Not-A-Number; screaming/quiet+ * 0, -0: Both kinds of zeros+ * max : The maximum finite positive value+ * -max: The minimum finite negative value+ * min : The minimum normal positive value+ * -min: The maximum normal negative value+ * epsilon: The smallest possible value x s.t. 1+x /= 1.+ * ulp: The minimum subnormal value
crackNum.cabal view
@@ -1,8 +1,7 @@ Name: crackNum-Version: 1.0-Synopsis: Crack various integer/floating-point data formats-Description: Crack various integer/floating-point data formats;- HP/SP/DP floats and various sized words and integers.+Version: 1.1+Synopsis: Crack various integer, floating-point data formats+Description: Crack HP, SP and DP floats and 8, 16, 32, 64 bit words and integers. License: BSD3 License-file: LICENSE Author: Levent Erkok