haskus-binary-1.5: Haskus binary format manipulation

Safe HaskellNone
LanguageHaskell2010

Haskus.Number.FixedPoint

Description

Fixed-point numbers

Synopsis

Documentation

newtype FixedPoint w (i :: Nat) (f :: Nat) Source #

Unsigned fixed-point number * w is the backing type * i is the number of bits for the integer part (before the radix point) * f is the number of bits for the fractional part (after the radix point)

>>> :set -XDataKinds
>>> import Data.Word
>>> fromIntegral 0 :: FixedPoint Word32 16 16
0 % 1
>>> fromIntegral 10 :: FixedPoint Word32 16 16
10 % 1

Constructors

FixedPoint (BitFields w '[BitField i "integer" w, BitField f "fractional" w]) 
Instances
(Integral w, Bits w, Field w, BitSize w ~ (n + d), KnownNat n, KnownNat d) => Eq (FixedPoint w n d) Source # 
Instance details

Defined in Haskus.Number.FixedPoint

Methods

(==) :: FixedPoint w n d -> FixedPoint w n d -> Bool #

(/=) :: FixedPoint w n d -> FixedPoint w n d -> Bool #

(BitSize w ~ (i + f), Num w, FiniteBits w, Bits w, KnownNat i, KnownNat f, Field w, Integral w) => Num (FixedPoint w i f) Source # 
Instance details

Defined in Haskus.Number.FixedPoint

Methods

(+) :: FixedPoint w i f -> FixedPoint w i f -> FixedPoint w i f #

(-) :: FixedPoint w i f -> FixedPoint w i f -> FixedPoint w i f #

(*) :: FixedPoint w i f -> FixedPoint w i f -> FixedPoint w i f #

negate :: FixedPoint w i f -> FixedPoint w i f #

abs :: FixedPoint w i f -> FixedPoint w i f #

signum :: FixedPoint w i f -> FixedPoint w i f #

fromInteger :: Integer -> FixedPoint w i f #

(Integral w, Bits w, Field w, BitSize w ~ (n + d), KnownNat n, KnownNat d) => Ord (FixedPoint w n d) Source # 
Instance details

Defined in Haskus.Number.FixedPoint

Methods

compare :: FixedPoint w n d -> FixedPoint w n d -> Ordering #

(<) :: FixedPoint w n d -> FixedPoint w n d -> Bool #

(<=) :: FixedPoint w n d -> FixedPoint w n d -> Bool #

(>) :: FixedPoint w n d -> FixedPoint w n d -> Bool #

(>=) :: FixedPoint w n d -> FixedPoint w n d -> Bool #

max :: FixedPoint w n d -> FixedPoint w n d -> FixedPoint w n d #

min :: FixedPoint w n d -> FixedPoint w n d -> FixedPoint w n d #

(BitSize w ~ (i + f), Integral w, FiniteBits w, Bits w, Field w, KnownNat i, KnownNat f) => Real (FixedPoint w i f) Source # 
Instance details

Defined in Haskus.Number.FixedPoint

Methods

toRational :: FixedPoint w i f -> Rational #

(Integral w, Bits w, Field w, BitSize w ~ (n + d), KnownNat n, KnownNat d, Show w) => Show (FixedPoint w n d) Source # 
Instance details

Defined in Haskus.Number.FixedPoint

Methods

showsPrec :: Int -> FixedPoint w n d -> ShowS #

show :: FixedPoint w n d -> String #

showList :: [FixedPoint w n d] -> ShowS #

Storable w => Storable (FixedPoint w i f) Source # 
Instance details

Defined in Haskus.Number.FixedPoint

Methods

peekIO :: Ptr (FixedPoint w i f) -> IO (FixedPoint w i f) Source #

pokeIO :: Ptr (FixedPoint w i f) -> FixedPoint w i f -> IO () Source #

alignment :: FixedPoint w i f -> Word Source #

sizeOf :: FixedPoint w i f -> Word Source #

getFixedPointBase :: FixedPoint w i f -> w Source #

Get base value

fromFixedPointBase :: forall w i f. w -> FixedPoint w i f Source #

Set base value

toFixedPoint :: forall a w (n :: Nat) (d :: Nat). (RealFrac a, BitSize w ~ (n + d), KnownNat n, KnownNat d, Bits w, Field w, Num w, Integral w) => a -> FixedPoint w n d Source #

Convert to a fixed point value

fromFixedPoint :: forall a w (n :: Nat) (d :: Nat). (RealFrac a, BitSize w ~ (n + d), KnownNat n, KnownNat d, Bits w, Field w, Num w, Integral w) => FixedPoint w n d -> a Source #

Convert from a fixed-point value