Copyright | (c) Dong Han 2017-2019 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Textual numeric builders.
Synopsis
- data IFormat = IFormat {}
- defaultIFormat :: IFormat
- data Padding
- int :: (Integral a, Bounded a) => a -> Builder ()
- intWith :: (Integral a, Bounded a) => IFormat -> a -> Builder ()
- integer :: Integer -> Builder ()
- hex :: forall a. (FiniteBits a, Integral a) => a -> Builder ()
- heX :: forall a. (FiniteBits a, Integral a) => a -> Builder ()
- data FFormat
- double :: Double -> Builder ()
- doubleWith :: FFormat -> Maybe Int -> Double -> Builder ()
- float :: Float -> Builder ()
- floatWith :: FFormat -> Maybe Int -> Float -> Builder ()
- scientific :: Scientific -> Builder ()
- scientificWith :: FFormat -> Maybe Int -> Scientific -> Builder ()
- grisu3 :: Double -> ([Int], Int)
- grisu3_sp :: Float -> ([Int], Int)
- i2wDec :: Integral a => a -> Word8
- i2wHex :: Integral a => a -> Word8
- i2wHeX :: Integral a => a -> Word8
- countDigits :: Integral a => a -> Int
- c_intWith :: (Integral a, Bits a) => IFormat -> a -> Builder ()
- hs_intWith :: (Integral a, Bounded a) => IFormat -> a -> Builder ()
Integral type formatting
Integral formatting options.
defaultIFormat :: IFormat Source #
defaultIFormat = IFormat 0 NoPadding False
Instances
Enum Padding Source # | |
Eq Padding Source # | |
Ord Padding Source # | |
Show Padding Source # | |
Arbitrary Padding Source # | |
CoArbitrary Padding Source # | |
Defined in Z.Data.Builder.Numeric coarbitrary :: Padding -> Gen b -> Gen b # |
intWith :: (Integral a, Bounded a) => IFormat -> a -> Builder () Source #
Format a Bounded
Integral
type like Int
or Word16
into decimal ASCII digits.
import Z.Data.Builder as B import Z.Data.Text as T > T.validate . B.buildBytes $ B.intWith defaultIFormat (12345 :: Int) "12345" > T.validate . B.buildBytes $ B.intWith defaultIFormat{width=10, padding=RightSpacePadding} (12345 :: Int) "12345 " > T.validate . B.buildBytes $ B.intWith defaultIFormat{width=10, padding=ZeroPadding} (12345 :: Int) "0000012345"
Fixded size hexidecimal formatting
hex :: forall a. (FiniteBits a, Integral a) => a -> Builder () Source #
Format a FiniteBits
Integral
type into hex nibbles.
import Z.Data.Builder as B import Z.Data.Text as T import Data.Word import Data.Int > T.validate . B.buildBytes $ B.hex (125 :: Int8) "7d" > T.validate . B.buildBytes $ B.hex (-1 :: Int8) "ff" > T.validate . B.buildBytes $ B.hex (125 :: Word16) "007d"
heX :: forall a. (FiniteBits a, Integral a) => a -> Builder () Source #
The UPPERCASED version of hex
.
IEEE float formating
Control the rendering of floating point numbers.
Exponent | Scientific notation (e.g. |
Fixed | Standard decimal notation. |
Generic | Use decimal notation for values between |
Instances
Enum FFormat Source # | |
Read FFormat Source # | |
Show FFormat Source # | |
double :: Double -> Builder () Source #
Decimal encoding of an IEEE Double
.
Using standard decimal notation for arguments whose absolute value lies
between 0.1
and 9,999,999
, and scientific notation otherwise.
Format double-precision float using drisu3 with dragon4 fallback.
float :: Float -> Builder () Source #
Decimal encoding of an IEEE Float
.
Using standard decimal notation for arguments whose absolute value lies
between 0.1
and 9,999,999
, and scientific notation otherwise.
Format single-precision float using drisu3 with dragon4 fallback.
scientific :: Scientific -> Builder () Source #
A Builder
which renders a scientific number to full
precision, using standard decimal notation for arguments whose
absolute value lies between 0.1
and 9,999,999
, and scientific
notation otherwise.
:: FFormat | |
-> Maybe Int | Number of decimal places to render. |
-> Scientific | |
-> Builder () |
Like scientific
but provides rendering options.
Misc
grisu3 :: Double -> ([Int], Int) Source #
Decimal encoding of a Double
, note grisu only handles strictly positive finite numbers.
grisu3_sp :: Float -> ([Int], Int) Source #
Decimal encoding of a Float
, note grisu3_sp only handles strictly positive finite numbers.
countDigits :: Integral a => a -> Int Source #
Count how many decimal digits an integer has.