A number in scientific notation: $c \times 10^{e}$.
coefficient— the significand $c$ (arbitrary-precision integer)base10Exponent— the exponent $e$ (arbitrary-precision integer)
Two Scientific values are logically equal when they represent the same
real number; structural equality after normalize is canonical.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Data.instReprScientific = { reprPrec := Data.instReprScientific.repr }
Smart constructor: $\text{scientific}(c, e) = c \times 10^{e}$.
Equations
- Data.Scientific.scientific c e = { coefficient := c, base10Exponent := e }
Instances For
Create a Scientific from an integer: $n \mapsto n \times 10^{0}$.
Equations
- Data.Scientific.fromInt n = { coefficient := n, base10Exponent := 0 }
Instances For
Remove trailing zeros from the coefficient, adjusting the exponent.
$$\text{normalize}(c \times 10^{e}) = (c / 10^{k}) \times 10^{e+k}$$
where $k$ is the number of trailing zeros in $c$. The result is canonical: the coefficient has no trailing zeros (or is zero).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Is the number zero? $$\text{isZero}(s) \iff c = 0$$
Equations
- s.isZero = (s.coefficient == 0)
Instances For
Is the number an integer? True when the exponent is non-negative (after normalization).
Instances For
Is the number negative zero?
Always false since Int has no negative zero.
Equations
- x✝.isNegativeZero = false
Instances For
Convert to Float (may lose precision for large or very precise values).
$$\text{toRealFloat}(c \times 10^{e}) = \text{Float.ofInt}(c) \times 10^{e}$$
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert a Float to Scientific by decomposing it into decimal digits.
Note: this performs a best-effort conversion through the string
representation, similar to Haskell's fromFloatDigits.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert to a bounded integer, returning none if the number is
fractional or outside the representable range of a 64-bit signed integer.
Range: $[-2^{63}, 2^{63} - 1]$.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decompose into a list of mantissa digits and a base-10 exponent.
Returns (digits, exp) such that:
$$\text{value} = 0.\text{digits} \times 10^{\text{exp}}$$
For example, $123.45$ yields ([1,2,3,4,5], 3).
The digit list has no trailing zeros. For zero, returns ([0], 1).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Data.Scientific.instAdd = { add := fun (a b : Data.Scientific) => match Data.Scientific.align✝ a b with | (c1, c2, e) => { coefficient := c1 + c2, base10Exponent := e } }
Equations
- Data.Scientific.instSub = { sub := fun (a b : Data.Scientific) => match Data.Scientific.align✝ a b with | (c1, c2, e) => { coefficient := c1 - c2, base10Exponent := e } }
Equations
- Data.Scientific.instMul = { mul := fun (a b : Data.Scientific) => { coefficient := a.coefficient * b.coefficient, base10Exponent := a.base10Exponent + b.base10Exponent } }
Equations
- Data.Scientific.instNeg = { neg := fun (s : Data.Scientific) => { coefficient := -s.coefficient, base10Exponent := s.base10Exponent } }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Format a Scientific as a plain decimal string.
- $1.23 \times 10^{5}$ →
"123000.0" - $1.23 \times 10^{-2}$ →
"0.0123" - $-42 \times 10^{0}$ →
"-42.0"
Equations
- One or more equations did not get rendered due to their size.
isZero is true if and only if the coefficient is zero.
$$\text{isZero}(s) = \text{true} \iff s.\text{coefficient} = 0$$
Negation is self-inverse. $$-(-s) = s$$