base-4.6.0.1: Basic libraries

Portability | portable
Stability | experimental
Maintainer | Ashley Yakeley <ashley@semantic.org>
Safe Haskell | Trustworthy

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)
- data Fixed a
- class HasResolution a 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

div' :: (Real a, Integral b) => a -> a -> b

generalisation of `div` to any instance of Real

mod' :: Real a => a -> a -> a

generalisation of `mod` to any instance of Real

divMod' :: (Real a, Integral b) => a -> a -> (b, a)

generalisation of `divMod` to any instance of Real

data Fixed a

The type parameter should be an instance of `HasResolution`.

Instances

Typeable1 Fixed |
Enum (Fixed a) |
Eq (Fixed a) |
HasResolution a => Fractional (Fixed a) |
Typeable a => Data (Fixed a) |
HasResolution a => Num (Fixed a) |
Ord (Fixed a) |
HasResolution a => Read (Fixed a) |
HasResolution a => Real (Fixed a) |
HasResolution a => RealFrac (Fixed a) |
HasResolution a => Show (Fixed a) |

class HasResolution a where

Methods

resolution :: p a -> Integer

Instances

HasResolution E12 |
HasResolution E9 |
HasResolution E6 |
HasResolution E3 |
HasResolution E2 |
HasResolution E1 |
HasResolution E0 |

showFixed :: HasResolution a => Bool -> Fixed a -> String

First arg is whether to chop off trailing zeros

data E0

Instances

Typeable E0 |
HasResolution E0 |

type Uni = Fixed E0

resolution of 1, this works the same as Integer

data E1

Instances

Typeable E1 |
HasResolution E1 |

type Deci = Fixed E1

resolution of 10^-1 = .1

data E2

Instances

Typeable E2 |
HasResolution E2 |

type Centi = Fixed E2

resolution of 10^-2 = .01, useful for many monetary currencies

data E3

Instances

Typeable E3 |
HasResolution E3 |

type Milli = Fixed E3

resolution of 10^-3 = .001

data E6

Instances

Typeable E6 |
HasResolution E6 |

type Micro = Fixed E6

resolution of 10^-6 = .000001

data E9

Instances

Typeable E9 |
HasResolution E9 |

type Nano = Fixed E9

resolution of 10^-9 = .000000001

data E12

Instances

Typeable E12 |
HasResolution E12 |

type Pico = Fixed E12

resolution of 10^-12 = .000000000001