haskus-binary-1.5: Haskus binary format manipulation

Safe HaskellNone
LanguageHaskell2010

Haskus.Number.Signed

Description

Signed 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
  • Positive and negative zeros are zero

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.Signed

Methods

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

show :: Signed b -> String #

showList :: [Signed b] -> ShowS #

signedIsZero :: forall b. SignedIsZero b => Signed b -> Bool Source #

Test for zero

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

signedFromBitNat :: forall b. SignedFromBitNat b => BitNat b -> Signed b Source #

Create from a BitNat

>>> signedFromBitNat (bitNat @18)
18

type SignedNegate b = IsBitNat (b + 1) Source #

signedNegate :: SignedNegate b => Signed b -> Signed b Source #

Negate a signed number

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

signedPos :: forall (v :: Nat) b. SignedPos b v => Signed b Source #

Positive signed literal

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

signedNeg :: forall (v :: Nat) b. SignedNeg b v => Signed b Source #

Negative signed literal

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