decimal-literals-0.1.0.1: Preprocessing decimal literals more or less as they are (instead of via fractions)

Copyright (c) Justus Sagemüller 2017 GPL v3 (@) jsagemue \$ uni-koeln.de experimental portable Safe Haskell2010

Numeric.Literals.Decimal

Contents

Description

Synopsis

# Documentation

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
 Source # Instance detailsDefined in Numeric.Literals.Decimal Methods Source # Despite the name, fromRational should not be used to promote a Rational value to FractionalLit, because that method contains the heuristic which interprets decimal/scientific literals (which in Haskell are, perhaps unfortunately, always desugared through fromRational). Use / or :% instead, to define exact-ratio values. Instance detailsDefined in Numeric.Literals.Decimal Methods Source # Instance detailsDefined in Numeric.Literals.Decimal Methods Source # Instance detailsDefined in Numeric.Literals.Decimal MethodsshowList :: [FractionalLit] -> ShowS #

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 #

Arguments

 :: 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

data B₁₀Digit Source #

A number between 0 and 9.

Instances
 Source # Instance detailsDefined in Numeric.Literals.Decimal MethodsenumFrom :: B₁₀Digit -> [B₁₀Digit] #enumFromTo :: B₁₀Digit -> B₁₀Digit -> [B₁₀Digit] # Source # Instance detailsDefined in Numeric.Literals.Decimal Methods Source # Instance detailsDefined in Numeric.Literals.Decimal Methods Source # Instance detailsDefined in Numeric.Literals.Decimal Methods(<) :: B₁₀Digit -> B₁₀Digit -> Bool #(>) :: B₁₀Digit -> B₁₀Digit -> Bool # Source # Instance detailsDefined in Numeric.Literals.Decimal MethodsshowList :: [B₁₀Digit] -> ShowS #