Copyright | (c) Dong Han 2017-2019 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
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 ()
- hexUpper :: 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 ()
- 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
- i2wHexUpper :: 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 ()
- quotRem10 :: Word -> (Word, Word)
Integral type formatting
Integral formatting options.
defaultIFormat :: IFormat Source #
defaultIFormat = IFormat 0 NoPadding False
Padding format.
Instances
Arbitrary Padding Source # | |
CoArbitrary Padding Source # | |
Defined in Z.Data.Builder.Numeric coarbitrary :: Padding -> Gen b -> Gen b # | |
Enum Padding Source # | |
Show Padding Source # | |
Eq Padding Source # | |
Ord Padding Source # | |
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 > B.buildText $ B.intWith defaultIFormat (12345 :: Int) "12345" > B.buildText $ B.intWith defaultIFormat{width=10, padding=RightSpacePadding} (12345 :: Int) "12345 " > B.buildText $ 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.build $ B.hex (125 :: Int8) "7d" > T.validate . B.build $ B.hex (-1 :: Int8) "ff" > T.validate . B.build $ B.hex (125 :: Word16) "007d"
hexUpper :: 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
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.
scientific' :: Scientific -> Builder () Source #
This builder try to avoid scientific notation when 0 <= exponent < 16.
:: 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.
i2wHexUpper :: Integral a => a -> Word8 Source #
Hexadecimal digit to UPPERCASED ASCII char.
countDigits :: Integral a => a -> Int Source #
Count how many decimal digits an integer has.
c_intWith :: (Integral a, Bits a) => IFormat -> a -> Builder () Source #
Internal formatting backed by C FFI, it must be used with type smaller than Word64
.
We use rewrite rules to rewrite most of the integral types formatting to this function.