-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Binary fixed-point arithmetic
--
-- This package defines a type for binary fixed-precision arithmetic. Its
-- interface is intended to be almost the same as the one provided by
-- Data.Fixed. The main differences are that this is binary fixed-point
-- and it's polymorphic in the underlying representation.
@package fixed-point
@version 0.2.0.0
-- | This module defines a type for binary fixed-point arithmetic. The main
-- advantage this provides over decimal fixed-point arithmetic is that
-- the point is maintained using fast bit shifts instead of slow
-- div operations. This type is also polymorphic on the underlying
-- representation, so you can use whatever size and signedness you want.
-- You just have to be mindful of overflows if you use a fixed-size
-- representation, especially with operations like multiplication.
module Data.Fixed.Binary
-- | generalisation of div to any instance of Real
div' :: (Real a, Integral b) => a -> a -> b
-- | generalisation of mod to any instance of Real
mod' :: Real a => a -> a -> a
-- | generalisation of divMod to any instance of Real
divMod' :: (Real a, Integral b) => a -> a -> (b, a)
-- | The first type parameter represents the number of bits to devote to
-- the fractional part of the number. The second type parameter is the
-- underlying representation. For example, Fixed E8 Int16 uses
-- eight bits for the integer component (of which one bit is used for the
-- sign) and eight bits for the fractional component.
data Fixed r a
-- | Instances of this class are useful as the first parameter of
-- Fixed.
class HasResolution r
resolution :: (HasResolution r, Num a) => Fixed r a -> Int
data E0
type E1 = S E0
type E2 = E1 :+ E1
type E4 = E2 :+ E2
type E8 = E4 :+ E4
type E10 = S (S E8)
type E16 = E8 :+ E8
type E20 = E10 :+ E10
type E30 = E20 :+ E10
type E32 = E16 :+ E16
type E64 = E32 :+ E32
-- | Increment a resolution
data S n
-- | Decrement a resolution
-- | Fast conversion between fixed-point numbers with the same fractional
-- size.
fixedRadix :: (Integral a, Num b) => Fixed r a -> Fixed r b
-- | Fast conversion between fixed-point numbers with the same
-- representation size.
fixedSize :: (HasResolution r, HasResolution s, Bits a) => Fixed r a -> Fixed s a
-- | Add resolutions
-- | Multiplication without throwing away fractional information. Note that
-- this doesn't help against losing significant information from the
-- integer component. If you are concerned about preventing overflow then
-- convert to a larger representation first.
(*.) :: Num a => Fixed r a -> Fixed s a -> Fixed (r :+ s) a
-- | Subtract resolutions
-- | Division without throwing away fractional information. Same caveats
-- apply as with '(*.)'.
(/.) :: Integral a => Fixed r a -> Fixed s a -> Fixed (r :- s) a
instance Typeable2 Fixed
instance Enum a => Enum (Fixed r a)
instance Eq a => Eq (Fixed r a)
instance Ord a => Ord (Fixed r a)
instance HasResolution E0
instance HasResolution n => HasResolution (S n)
instance (HasResolution r, Bits a, Integral a) => RealFrac (Fixed r a)
instance (HasResolution r, Bits a, Integral a) => Fractional (Fixed r a)
instance (HasResolution r, Bits a, Integral a) => Real (Fixed r a)
instance (HasResolution r, Bits a, Integral a) => Num (Fixed r a)
instance (HasResolution r, Bits a, Integral a) => Show (Fixed r a)
instance (HasResolution r, Bits a, Integral a) => Read (Fixed r a)