| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Falsify.WordN
Contents
Description
N-bit words
Intended for qualified import.
import Data.Falsify.WordN (WordN) import qualified Data.Falsify.WordN as WordN
Synopsis
- data WordN
- newtype Precision = Precision Word8
- forgetPrecision :: WordN -> Word64
- zero :: Precision -> WordN
- truncateAt :: Precision -> Word64 -> WordN
- unsafeFromWord64 :: Precision -> Word64 -> WordN
- toProperFraction :: WordN -> ProperFraction
Documentation
Precision (in bits)
Instances
| Enum Precision Source # | |
Defined in Data.Falsify.WordN Methods succ :: Precision -> Precision # pred :: Precision -> Precision # fromEnum :: Precision -> Int # enumFrom :: Precision -> [Precision] # enumFromThen :: Precision -> Precision -> [Precision] # enumFromTo :: Precision -> Precision -> [Precision] # enumFromThenTo :: Precision -> Precision -> Precision -> [Precision] # | |
| Num Precision Source # | |
Defined in Data.Falsify.WordN | |
| Show Precision Source # | |
| Eq Precision Source # | |
| Ord Precision Source # | |
Construction
truncateAt :: Precision -> Word64 -> WordN Source #
Make n-bit word (n <= 64)
Bits outside the requested precision will be zeroed.
We use this to generate random n-bit words from random 64-bit words.
It is important that we truncate rather than cap the value: capping the
value (limiting it to a certain maximum) would result in a strong bias
towards that maximum value.
Of course, shrinking of a Word64 bit does not translate automatically to
shrinking of the lower n bits of that word (a decrease in the larger
Word64 may very well be an increase in the lower n bits), so this must
be taken into account.
Using
toProperFraction :: WordN -> ProperFraction Source #
Compute fraction from n-bit word