Copyright | (c) Eric Mertens 2019 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Safe |
Language | Haskell2010 |
This module provides a representation of numbers in scientific notation.
Synopsis
- data Number = MkNumber {}
- data Radix
- radixToInt :: Radix -> Int
- numberToRational :: Number -> Rational
- numberToInteger :: Number -> Maybe Integer
- integerToNumber :: Integer -> Number
- rationalToNumber :: Rational -> Number
Documentation
Numbers are represented as base, coefficient, and exponent.
The most convenient way to get numbers into and out of this form
is to use one of: numberToRational
, numberToInteger
,
rationalToNumber
, or integerToNumber
.
This representation is explicit about the radix and exponent
used to facilitate better pretty-printing. By using explicit
exponents extremely large numbers can be represented compactly.
Consider that it is easy to write `1e100000000` which would use
a significant amount of memory if realized as an Integer
. This
representation allows concerned programs to check bounds before
converting to a representation like Integer
.
Instances
Eq Number Source # | |
Data Number Source # | |
Defined in Config.Number gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Number -> c Number # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Number # toConstr :: Number -> Constr # dataTypeOf :: Number -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Number) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Number) # gmapT :: (forall b. Data b => b -> b) -> Number -> Number # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Number -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Number -> r # gmapQ :: (forall d. Data d => d -> u) -> Number -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Number -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Number -> m Number # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Number -> m Number # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Number -> m Number # | |
Ord Number Source # | |
Read Number Source # | |
Show Number Source # | |
Generic Number Source # | |
type Rep Number Source # | |
Defined in Config.Number type Rep Number = D1 ('MetaData "Number" "Config.Number" "config-value-0.7.0.0-JboFCtXlIzo1Q4jM4SfnDg" 'False) (C1 ('MetaCons "MkNumber" 'PrefixI 'True) (S1 ('MetaSel ('Just "numberRadix") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Radix) :*: S1 ('MetaSel ('Just "numberCoefficient") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Rational))) |
Radix used for a number. Some radix modes support an exponent.
Radix2 | binary, base 2 |
Radix8 | octal, base 8 |
Radix10 !Integer | decimal, base 10, exponent base 10 |
Radix16 !Integer | hexdecimal, base 16, exponent base 2 |
Instances
Eq Radix Source # | |
Data Radix Source # | |
Defined in Config.Number gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Radix -> c Radix # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Radix # dataTypeOf :: Radix -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Radix) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Radix) # gmapT :: (forall b. Data b => b -> b) -> Radix -> Radix # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Radix -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Radix -> r # gmapQ :: (forall d. Data d => d -> u) -> Radix -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Radix -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Radix -> m Radix # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Radix -> m Radix # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Radix -> m Radix # | |
Ord Radix Source # | |
Read Radix Source # | |
Show Radix Source # | |
Generic Radix Source # | |
type Rep Radix Source # | |
Defined in Config.Number type Rep Radix = D1 ('MetaData "Radix" "Config.Number" "config-value-0.7.0.0-JboFCtXlIzo1Q4jM4SfnDg" 'False) ((C1 ('MetaCons "Radix2" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Radix8" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Radix10" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "Radix16" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)))) |
radixToInt :: Radix -> Int Source #
Returns the radix as an integer ignoring any exponent.
numberToRational :: Number -> Rational Source #
Convert a number to a Rational
. Warning: This can use a
lot of member in the case of very large exponent parts.