haskus-binary-1.5: Haskus binary format manipulation

Safe HaskellNone
LanguageHaskell2010

Haskus.Number.SignedSafe

Description

Signed safe numbers

Synopsis

Documentation

newtype Signed (b :: Nat) Source #

A signed number (not in two-complement form)

  • Bits: ddd..ddds where "s" is the sign bit
  • Allows symetric positive and negative numbers
  • Negative zero is NaN

Constructors

Signed (BitNat (b + 1)) 
Instances
(KnownNat b, Integral (BitNatWord b), IndexableBits (BitNatWord (b + 1)), Num (BitNatWord (b + 1)), Eq (BitNatWord (b + 1)), Integral (BitNatWord (b + 1)), ShiftableBits (BitNatWord (b + 1)), Narrow (b + 1) ((b + 1) - 1)) => Show (Signed b) Source #

Show instance for Signed

Instance details

Defined in Haskus.Number.SignedSafe

Methods

showsPrec :: Int -> Signed b -> ShowS #

show :: Signed b -> String #

showList :: [Signed b] -> ShowS #

signedIsZero :: (Num (BitNatWord (b + 1)), Eq (BitNatWord (b + 1))) => Signed b -> Bool Source #

Test for zero

>>> signedIsZero (signedNeg @5)
False
>>> signedIsZero (signedNeg @0)
True

signedIsNaN :: (Num (BitNatWord (b + 1)), Eq (BitNatWord (b + 1))) => Signed b -> Bool Source #

Test for NaN

>>> signedIsNaN (signedPos @5)
False
>>> signedIsNaN (signedPos @0)
False

signedFromBitNat :: (ShiftableBits (BitNatWord (b + 1)), Widen b (b + 1)) => BitNat b -> Signed b Source #

Create from a BitNat

>>> signedFromBitNat (bitNat @18)
18

signedNegate :: IsBitNat (b + 1) => Signed b -> Signed b Source #

Negate a signed number

>>> signedNegate (signedPos @5)
-5
>>> signedNegate (signedNeg @5)
5

signedPos :: forall (v :: Nat) b. (b ~ NatBitCount v, MakeBitNat b, Bitwise (BitNatWord b), Integral (BitNatWord (b + 1)), KnownNat v, ShiftableBits (BitNatWord (b + 1)), Widen b (b + 1)) => Signed b Source #

Positive signed literal

>>> signedPos @5
5
>>> signedPos @0
0

signedNeg :: forall (v :: Nat) b. (b ~ NatBitCount v, MakeBitNat b, Bitwise (BitNatWord b), KnownNat v, Widen b (b + 1), ShiftableBits (BitNatWord (b + 1)), IsBitNat (b + 1)) => Signed b Source #

Negative signed literal

>>> signedNeg @5
-5
>>> signedNeg @0
0