| Copyright | (c) Ashley Yakeley 2005 2006 2009 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | Ashley Yakeley <ashley@semantic.org> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Data.Fixed
Description
This module defines a "Fixed" type for fixed-precision arithmetic.
The parameter to Fixed is any type that's an instance of HasResolution.
HasResolution has a single method that gives the resolution of the Fixed
type.
This module also contains generalisations of div, mod, and divMod to
work with any Real instance.
Synopsis
- div' :: (Real a, Integral b) => a -> a -> b
- mod' :: Real a => a -> a -> a
- divMod' :: (Real a, Integral b) => a -> a -> (b, a)
- newtype Fixed (a :: k) = MkFixed Integer
- class HasResolution (a :: k) where
- resolution :: p a -> Integer
- showFixed :: HasResolution a => Bool -> Fixed a -> String
- data E0
- type Uni = Fixed E0
- data E1
- type Deci = Fixed E1
- data E2
- type Centi = Fixed E2
- data E3
- type Milli = Fixed E3
- data E6
- type Micro = Fixed E6
- data E9
- type Nano = Fixed E9
- data E12
- type Pico = Fixed E12
Documentation
The type parameter should be an instance of HasResolution.
Instances
| (Typeable k, Typeable a) => Data (Fixed a) # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Fixed a -> c (Fixed a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Fixed a) # toConstr :: Fixed a -> Constr # dataTypeOf :: Fixed a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Fixed a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Fixed a)) # gmapT :: (forall b. Data b => b -> b) -> Fixed a -> Fixed a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Fixed a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Fixed a -> r # gmapQ :: (forall d. Data d => d -> u) -> Fixed a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Fixed a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Fixed a -> m (Fixed a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Fixed a -> m (Fixed a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Fixed a -> m (Fixed a) # | |
| Enum (Fixed a) # | Recall that, for numeric types, succ (0.000 :: Milli) == 1.001 and likewise pred (0.000 :: Milli) == -0.001 In other words, succ (0.000000000000 :: Pico) == 0.000000000001 and similarly pred (0.000000000000 :: Pico) == -0.000000000001 This is worth bearing in mind when defining [1..10] :: [Pico] evaluates to However, this is not true. On the contrary, similarly to the above
implementations of [1.000000000000, 1.00000000001, 1.00000000002, ..., 10.000000000000] and contains Since: base-2.1 |
| HasResolution a => Num (Fixed a) # | Since: base-2.1 |
| HasResolution a => Read (Fixed a) # | Since: base-4.3.0.0 |
| HasResolution a => Fractional (Fixed a) # | Since: base-2.1 |
| HasResolution a => Real (Fixed a) # | Since: base-2.1 |
Defined in Data.Fixed Methods toRational :: Fixed a -> Rational # | |
| HasResolution a => RealFrac (Fixed a) # | Since: base-2.1 |
| HasResolution a => Show (Fixed a) # | Since: base-2.1 |
| Eq (Fixed a) # | Since: base-2.1 |
| Ord (Fixed a) # | Since: base-2.1 |
class HasResolution (a :: k) where #
Methods
resolution :: p a -> Integer #
Instances
| KnownNat n => HasResolution (n :: Nat) # | For example, |
Defined in Data.Fixed Methods resolution :: p n -> Integer # | |
| HasResolution E0 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E0 -> Integer # | |
| HasResolution E1 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E1 -> Integer # | |
| HasResolution E12 # | Since: base-2.1 |
Defined in Data.Fixed Methods resolution :: p E12 -> Integer # | |
| HasResolution E2 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E2 -> Integer # | |
| HasResolution E3 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E3 -> Integer # | |
| HasResolution E6 # | Since: base-2.1 |
Defined in Data.Fixed Methods resolution :: p E6 -> Integer # | |
| HasResolution E9 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E9 -> Integer # | |
showFixed :: HasResolution a => Bool -> Fixed a -> String #
First arg is whether to chop off trailing zeros
Instances
| HasResolution E0 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E0 -> Integer # | |
Instances
| HasResolution E1 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E1 -> Integer # | |
Instances
| HasResolution E2 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E2 -> Integer # | |
Instances
| HasResolution E3 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E3 -> Integer # | |
Instances
| HasResolution E6 # | Since: base-2.1 |
Defined in Data.Fixed Methods resolution :: p E6 -> Integer # | |
Instances
| HasResolution E9 # | Since: base-4.1.0.0 |
Defined in Data.Fixed Methods resolution :: p E9 -> Integer # | |
Instances
| HasResolution E12 # | Since: base-2.1 |
Defined in Data.Fixed Methods resolution :: p E12 -> Integer # | |