Copyright | (c) Justus Sagemüller 2017 |
---|---|
License | GPL v3 |
Maintainer | (@) jsagemue $ uni-koeln.de |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Synopsis
- data FractionalLit
- pattern (:%) :: Integer -> Integer -> FractionalLit
- pattern Scientific :: Int -> [B₁₀Digit] -> Int -> FractionalLit
- data B₁₀Digit
Documentation
data FractionalLit Source #
A type whose Fractional
instance gives a somewhat reliable indication whether
a value was actually defined as an integer or a ratio, or as a decimal-fraction
literal. This is useful to know for a type that supports both exact fraction
values and more floating-point-like / physical values; it allows avoiding
issues like 0.524
showing up as 589971551185535/1125899906842624
, or conversely
7/23
as 0.30434782608695654
. Both of these scenarios are quite awkward.
Instances
pattern (:%) :: Integer -> Integer -> FractionalLit Source #
Construct an exact fraction. The values behave like Rational
, until combined
– e.g. added – with a Scientific
value (which has an implicit
measurement-uncertainty, and that carries over to the result).
pattern Scientific Source #
:: Int | Integral part of the mantissa |
-> [B₁₀Digit] | Digits after the point of the mantissa |
-> Int | Base-10 exponent of the number in scientific form |
-> FractionalLit |
Construct a scientific number of the form m.n * 10^e
, where m
and e
are
integers and n
is a list of digits after the decimal point. The result
is considered to be only exact up to the precision indicated by the number
of digits. I.e. Scientific 2 [4,8,3] (-4)
basically means 2.483×10⁻⁴ ± 10⁻⁷
,
The Fractional
instance allows these values to be written in the standard
2.483e-4
notation. Note that this cannot completely reconstruct the written
form, e.g. 12.483e-4
will actually show up as Scientific 1 [2,4,8,3] (-3)
.
Leading and trailing zeroes are always ignored.
Auxiliary
A number between 0
and 9
.
Instances
Enum B₁₀Digit Source # | |
Defined in Numeric.Literals.Decimal | |
Eq B₁₀Digit Source # | |
Num B₁₀Digit Source # | |
Ord B₁₀Digit Source # | |
Defined in Numeric.Literals.Decimal | |
Show B₁₀Digit Source # | |