Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Data.FixedPoint
Description
This FixedPoint module implements arbitrary sized fixed point types and
computations. This module intentionally avoids converting to Integer
for
computations because one purpose is to allow easy translation to other
languages to produce stand-alone fixed point libraries. Instead of using
Integer
, elementary long multiplication and long division are implemented
explicitly along with sqrt, exp, and erf functions that are implemented using
only primitive operations.
- type FixedPoint4816 = GenericFixedPoint Int64 Word128 Word16
- type FixedPoint3232 = GenericFixedPoint Int64 Word128 Word32
- type FixedPoint6464 = GenericFixedPoint Int128 Word256 Word64
- type FixedPoint128128 = GenericFixedPoint Int256 Word512 Word128
- type FixedPoint256256 = GenericFixedPoint Int512 Word1024 Word256
- type FixedPoint512512 = GenericFixedPoint Int1024 Word2048 Word512
- type FixedPoint10241024 = GenericFixedPoint Int2048 Word4096 Word1024
- erf' :: (Show a, Eq a, Ord a, Num a, Fractional a) => Int -> a -> a
- exp' :: (Show a, Ord a, Fractional a, Eq a) => Int -> a -> a
- sqrt' :: (Ord b, Integral b, Bits b, Integral a, Num a, Bits a, Bits c, FiniteBits b, FiniteBits c) => GenericFixedPoint a b c -> GenericFixedPoint a b c
- pi' :: (Integral a, Bits a, Integral b, Num a, Bits b, Bits c, FiniteBits c) => GenericFixedPoint a b c
- type Int128 = BigInt Word128
- type Int256 = BigInt Word256
- type Int512 = BigInt Word512
- type Int1024 = BigInt Word1024
- type Int2048 = BigInt Word2048
- type Int4096 = BigInt Word4096
- type Int8192 = BigInt Word8192
- data Word128 = W128 !Word64 !Word64
- type Word72 = BigWord Word8 Word64
- type Word256 = BigWord Word128 Word128
- type Word512 = BigWord Word256 Word256
- type Word576 = BigWord Word64 Word512
- type Word584 = BigWord Word72 Word512
- type Word1024 = BigWord Word512 Word512
- type Word1280 = BigWord Word1024 Word256
- type Word2048 = BigWord Word1024 Word1024
- type Word2632 = BigWord Word584 Word2048
- type Word4096 = BigWord Word2048 Word2048
- type Word8192 = BigWord Word4096 Word4096
- data GenericFixedPoint flat internal fracBitRepr = FixedPoint {
- toFlat :: flat
- newtype BigInt a = BigInt {
- unBI :: a
- data BigWord a b = BigWord !a !b
- fromInternal :: (Integral b, Num a) => b -> GenericFixedPoint a b c
- toInternal :: (Integral a, Num b) => GenericFixedPoint a b c -> b
- fracBits :: FiniteBits c => GenericFixedPoint a b c -> Int
Fixedpoint types
Common Operations
sqrt' :: (Ord b, Integral b, Bits b, Integral a, Num a, Bits a, Bits c, FiniteBits b, FiniteBits c) => GenericFixedPoint a b c -> GenericFixedPoint a b c Source
The square root operation converges in O(bitSize input).
pi' :: (Integral a, Bits a, Integral b, Num a, Bits b, Bits c, FiniteBits c) => GenericFixedPoint a b c Source
Big Int Types
Big Word Types
Type Constructors
data GenericFixedPoint flat internal fracBitRepr Source
GenericFixedPoint is a type constructor for arbitrarily-sized fixed point
tyes. Take note the first type variable, flat
, should be a signed int
equal to the size of the fixed point integral plus fractional bits.
The second type variable, internal
, should be unsigned and twice
as large a bit size as the flat
type. The final type variable,
fracBitRepr
, should be a data structure of equal bit size to the
fractional bits in the fixed point type. See the existing type aliases,
such as FixedPoint4816
, for examples.
Constructors
FixedPoint | |
Fields
|
Instances
A type constructor for building 2^n bit signed ints. BigInt is normally just used as a wrapper around BigWord since twos-complement arithmatic is the same, we simply need to provide alternate show, read, and comparison operations.
Instances
(Bounded a, Ord a, Bits a, Num a, FiniteBits a) => Bounded (BigInt a) | |
(Bits a, Ord a, Integral a, Bounded a, Num a, FiniteBits a) => Enum (BigInt a) | |
Eq a => Eq (BigInt a) | |
(Integral a, Bits a, Bounded a, FiniteBits a) => Integral (BigInt a) | |
(FiniteBits a, Num a, Bits a, Ord a) => Num (BigInt a) | |
(Ord a, Bits a, FiniteBits a) => Ord (BigInt a) | |
(Num a, Bits a, Ord a, FiniteBits a) => Read (BigInt a) | |
(FiniteBits a, Real a, Bounded a, Integral a, Bits a) => Real (BigInt a) | |
(FiniteBits a, Show a, Num a, Bits a, Ord a) => Show (BigInt a) | |
Storable a => Storable (BigInt a) | |
(Bits a, Num a, Ord a, FiniteBits a) => Bits (BigInt a) | |
(Ord a, Num a, FiniteBits a) => FiniteBits (BigInt a) | |
NFData a => NFData (BigInt a) |
A type constuctor allowing construction of 2^n
bit unsigned words
The type variable represents half the underlying representation, so
type Foo = BigWord Word13
would have a bit size of 26 (2*13)
.
Constructors
BigWord !a !b |
Instances
Helpers
fromInternal :: (Integral b, Num a) => b -> GenericFixedPoint a b c Source
toInternal :: (Integral a, Num b) => GenericFixedPoint a b c -> b Source
fracBits :: FiniteBits c => GenericFixedPoint a b c -> Int Source
Obtain the number of bits used to represent the fractional component of this fixed point.