falsify-0.4.0: Property-based testing with internal integrated shrinking
Safe HaskellNone
LanguageHaskell2010

Data.Falsify.WordN

Description

N-bit words

Intended for qualified import.

import Data.Falsify.WordN (WordN)
import qualified Data.Falsify.WordN as WordN
Synopsis

Documentation

data WordN Source #

n-bit word

Instances

Instances details
Show WordN Source # 
Instance details

Defined in Data.Falsify.WordN

Methods

showsPrec :: Int -> WordN -> ShowS #

show :: WordN -> String #

showList :: [WordN] -> ShowS #

Eq WordN Source # 
Instance details

Defined in Data.Falsify.WordN

Methods

(==) :: WordN -> WordN -> Bool #

(/=) :: WordN -> WordN -> Bool #

Ord WordN Source # 
Instance details

Defined in Data.Falsify.WordN

Methods

compare :: WordN -> WordN -> Ordering #

(<) :: WordN -> WordN -> Bool #

(<=) :: WordN -> WordN -> Bool #

(>) :: WordN -> WordN -> Bool #

(>=) :: WordN -> WordN -> Bool #

max :: WordN -> WordN -> WordN #

min :: WordN -> WordN -> WordN #

newtype Precision Source #

Precision (in bits)

Constructors

Precision Word8 

forgetPrecision :: WordN -> Word64 Source #

Forget the precision of the WordN

Construction

zero :: Precision -> WordN Source #

Zero can be represented at every precision

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.

unsafeFromWord64 :: Precision -> Word64 -> WordN Source #

Construct from Word64

It is the caller's responsibility to ensure that the Word64 is in range.

Using

toProperFraction :: WordN -> ProperFraction Source #

Compute fraction from n-bit word