Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
---|---|
Safe Haskell | None |
This module is designed to be imported qualified:
import Data.Scientific as Scientific
- data Scientific
- scientific :: Integer -> Int -> Scientific
- coefficient :: Scientific -> Integer
- base10Exponent :: Scientific -> Int
- toFractional :: Fractional a => Scientific -> a
- fromRealFloat :: RealFloat a => a -> Scientific
- data FPFormat
- scientificBuilder :: Scientific -> Builder
- formatScientificBuilder :: FPFormat -> Maybe Int -> Scientific -> Builder
- formatScientific :: FPFormat -> Maybe Int -> Scientific -> String
- toDecimalDigits :: Scientific -> ([Int], Int)
Documentation
data Scientific Source
An arbitrary-precision number represented using scientific notation.
This type describes the set of all
which have a finite
decimal expansion.
Real
s
A scientific number with coefficient
c
and base10Exponent
e
corresponds to the Fractional
number: fromInteger
c * 10 ^^
e
Eq Scientific | |
Fractional Scientific | WARNING: |
Num Scientific | |
Ord Scientific | |
Read Scientific | |
Real Scientific | |
RealFrac Scientific | |
Show Scientific | |
Typeable Scientific | |
NFData Scientific | |
Hashable Scientific |
scientific :: Integer -> Int -> ScientificSource
scientific c e
constructs a scientific number with
coefficient
c
and base10Exponent
e
.
coefficient :: Scientific -> IntegerSource
The coefficient of a scientific number.
base10Exponent :: Scientific -> IntSource
The base-10 exponent of a scientific number.
Conversions
toFractional :: Fractional a => Scientific -> aSource
Efficient conversion from a Scientific
to a Fractional
number.
Note that this module provides rewrite RULES that convert
realToFrac
into toFractional
when going from a Scientific
to
either a Double
, Float
, CDouble
or CFloat
to avoid going
via Rational
.
So it's recommended to use realToFrac
to convert to a
Fractional
number. However, if you don't want to rely on these
RULES this function can be used.
fromRealFloat :: RealFloat a => a -> ScientificSource
Efficient conversion from a RealFloat
into a Scientific
number.
Note that this module provides rewrite RULES that convert
realToFrac
into fromRealFloat
when going from either a
Double
, Float
, CDouble
or CFloat
to a Scientific
to avoid
going via Rational
.
So it's recommended to use realToFrac
to convert Real
numbers
into Scientific
. However, if you don't want to rely on these
RULES this function can be used.
Pretty printing
Control the rendering of floating point numbers.
scientificBuilder :: Scientific -> BuilderSource
A Text
Builder
which renders a scientific number to full
precision, using standard decimal notation for arguments whose
absolute value lies between 0.1
and 9,999,999
, and scientific
notation otherwise.
:: FPFormat | |
-> Maybe Int | Number of decimal places to render. |
-> Scientific | |
-> Builder |
Like scientificBuilder
but provides rendering options.
:: FPFormat | |
-> Maybe Int | Number of decimal places to render. |
-> Scientific | |
-> String |
Like show
but provides rendering options.
toDecimalDigits :: Scientific -> ([Int], Int)Source
Similar to floatToDigits
, toDecimalDigits
takes a
non-negative Scientific
number, and returns a list of digits and
a base-10 exponent. In particular, if x>=0
, and
toDecimalDigits x = ([d1,d2,...,dn], e)
then
n >= 1
x = 0.d1d2...dn * (10^^e)
0 <= di <= 9