add decWord for machine-sized words

This commit is contained in:
Andrew Martin 2019-09-04 14:34:33 -04:00
parent 2e8d4279c7
commit 071b55568d
2 changed files with 14 additions and 0 deletions

View file

@ -32,6 +32,7 @@ module Data.ByteArray.Builder
, word32Dec , word32Dec
, word16Dec , word16Dec
, word8Dec , word8Dec
, wordDec
, int64Dec , int64Dec
, int32Dec , int32Dec
, int16Dec , int16Dec
@ -282,6 +283,12 @@ word16Dec w = fromBounded Nat.constant (Bounded.word16Dec w)
word8Dec :: Word8 -> Builder word8Dec :: Word8 -> Builder
word8Dec w = fromBounded Nat.constant (Bounded.word8Dec w) word8Dec w = fromBounded Nat.constant (Bounded.word8Dec w)
-- | Encodes an unsigned machine-sized integer as decimal.
-- This encoding never starts with a zero unless the
-- argument was zero.
wordDec :: Word -> Builder
wordDec w = fromBounded Nat.constant (Bounded.wordDec w)
-- | Encode a double-floating-point number, using decimal notation or -- | Encode a double-floating-point number, using decimal notation or
-- scientific notation depending on the magnitude. This has undefined -- scientific notation depending on the magnitude. This has undefined
-- behavior when representing @+inf@, @-inf@, and @NaN@. It will not -- behavior when representing @+inf@, @-inf@, and @NaN@. It will not

View file

@ -29,6 +29,7 @@ module Data.ByteArray.Builder.Bounded
, word32Dec , word32Dec
, word16Dec , word16Dec
, word8Dec , word8Dec
, wordDec
, int64Dec , int64Dec
, int32Dec , int32Dec
, int16Dec , int16Dec
@ -162,6 +163,12 @@ word16Dec (W16# w) = wordCommonDec# w
word8Dec :: Word8 -> Builder 3 word8Dec :: Word8 -> Builder 3
word8Dec (W8# w) = wordCommonDec# w word8Dec (W8# w) = wordCommonDec# w
-- | Requires up to 19 bytes. Encodes an unsigned machine-sized integer
-- as decimal. This encoding never starts with a zero unless the argument
-- was zero.
wordDec :: Word -> Builder 19
wordDec (W# w) = wordCommonDec# w
-- | Requires up to 20 bytes. Encodes a signed 64-bit integer as decimal. -- | Requires up to 20 bytes. Encodes a signed 64-bit integer as decimal.
-- This encoding never starts with a zero unless the argument was zero. -- This encoding never starts with a zero unless the argument was zero.
-- Negative numbers are preceded by a minus sign. Positive numbers -- Negative numbers are preceded by a minus sign. Positive numbers