bytestring-read-0.1.0: fast ByteString to Double converting library

Safe HaskellNone
LanguageHaskell2010

Data.ByteString.Read

Contents

Synopsis

functions

floating :: EffectiveDigit r => ByteString -> Maybe (r, ByteString) Source

convert bytestring into unsigned floating using radix.

this function can parse

  • oct/hexa-decimal (0o,0O,0x,0X) (optional)
  • floating(0.1, 12224.3543)
  • exponential (e1, E+2, e-123) (10-radixed only, optional)
>>> floating "12.4" :: Maybe (Double, ByteString)
Just (12.4,"")
>>> floating "1.23e12" :: Maybe (Double, ByteString)
Just (1.23e12,"")
>>> floating "0o0.4" :: Maybe (Double, ByteString)
Just (0.5,"")
>>> floating "0x3f.12" :: Maybe (Double, ByteString)
Just (63.0703125,"")

double :: ByteString -> Maybe (Double, ByteString) Source

double = floating

signed :: Num r => (ByteString -> Maybe (r, ByteString)) -> ByteString -> Maybe (r, ByteString) Source

convert unsigned parser to signed parser.

this function can parse

  • sign (+, -) (optional)
>>> signed double "12.4"
Just (12.4,"")
>>> signed double "-3.21e3"
Just (-3210.0,"")
>>> signed double "+0x1f.4"
Just (31.25,"")

classes

class (Fractional a, Num (Fraction a), Ord (Fraction a)) => EffectiveDigit a where Source

Associated Types

data Fraction a Source

data type to store fractional part of floating

Methods

maxValue :: proxy a -> Maybe (Fraction a) Source

maximum value of fractional part.

Nothing if arbitrary-precision.

Just $ fromIntegral (floatRadix t) ^ floatDigits t

fromFraction :: Num b => Fraction a -> b Source

lifted fromIntegral

class KnownNat n => Base n where Source

Methods

isDigit :: proxy n -> Word8 -> Bool Source

check input Word8 is digit charactor or not.

unsafeToDigit :: proxy n -> Word8 -> Word8 Source

convert digit charactor to number. undefined behaviour when give non-digit charactor.

Instances

Base 2 
Base 3 
Base 4 
Base 5 
Base 6 
Base 7 
Base 8 
Base 9 
Base 10 
Base 11 
Base 12 
Base 13 
Base 14 
Base 15 
Base 16 
Base 17 
Base 18 
Base 19 
Base 20 
Base 21 
Base 22 
Base 23 
Base 24 
Base 25 
Base 26 
Base 27 
Base 28 
Base 29 
Base 30 
Base 31 
Base 32 
Base 33 
Base 34 
Base 35 
Base 36 

raw functions

floating10 :: forall r. EffectiveDigit r => ByteString -> Maybe (r, ByteString) Source

convert bytestring into unsigned floating using radix.

this function can parse

  • floating(0.1, 12224.3543)
  • exponential (e1, E+2, e-123) (optional)
>>> floating10 "12.5" :: Maybe (Double, ByteString)
Just (12.5,"")
>>> floating10 "124.1e12" :: Maybe (Double, ByteString)
Just (1.241e14,"")
>>> floating10 "12.5e-3" :: Maybe (Double, ByteString)
Just (1.25e-2,"")
>>> floating10 "3.11e+3" :: Maybe (Double, ByteString)
Just (3110.0,"")

floating' :: (Base b, EffectiveDigit r) => proxy b -> ByteString -> Maybe (r, ByteString) Source

convert bytestring into unsigned floating using radix.

this function can parse

  • floating(0.1, 12224.3543)
>>> floating' (Proxy :: Proxy 36) "12z" :: Maybe (Double, ByteString)
Just (1403.0,"")
>>> floating' (Proxy :: Proxy 2) "1012" :: Maybe (Double, ByteString)
Just (5.0,"2")
>>> floating' (Proxy :: Proxy 10) "a12" :: Maybe (Double, ByteString)
Nothing