pmiddend/elm-number-spinner/1.0.0

NumberSpinner.DecimalNumber

Since the spinner isn't based on float/double, we need a module that provides us with an "infinite precision" numeric type. This module uses elm-decimal for that purpose.

Types

type alias DecimalNumber =
Decimal

Type alias for the Decimal library (to make the choice of library opaque at this point)

Construct

fromFloat : Float -> DecimalNumber

Convert from a floating point value. This function is a bit weird, since it uses Decimal.fromFloat, which can fail. I don't know when this fails. Hopefully, returning 0 in that case is fine.

fromInt : Int -> DecimalNumber

Convert from integer (meaning have 0 as decimal part)

fromString : String -> Maybe DecimalNumber

Convert from a string

tenToThePowerMinus : Int -> DecimalNumber

Implement 10^(-i) which is used to change decimal digits of a number

tenToThePower : Int -> DecimalNumber

Implement 10^i which is used to change integral digits of a number

toFloat : DecimalNumber -> Float

Return a floating-point representation of the number. Use with caution, of course. But might be fine to send the number over the wire (where precision can be safely lost - Tango uses floats anyways, for example)

toString : DecimalNumber -> String

Convert decimal to string

Combine

add : DecimalNumber -> DecimalNumber -> DecimalNumber

Add two decimal numbers

mul : DecimalNumber -> DecimalNumber -> DecimalNumber

Multiply two decimal numbers

subtract : DecimalNumber -> DecimalNumber -> DecimalNumber

Subtract two decimal numbers

Deconstruct

decimalDigits : DecimalNumber -> List Char

Return just the decimal digits of the decimal number (as chars, since we don't do any calculations with it, we jut display it)

integralPart : DecimalNumber -> Int

For a decimal number, return the integral part (the part before the decimal point). NOTE: This is not infinite precision now, of course. If we have more than 2^32 (or something) as integer, this will fail (and return -1337, somewhat randomly)

Compare

gt : DecimalNumber -> DecimalNumber -> Bool

Implement "greater than"

lt : DecimalNumber -> DecimalNumber -> Bool

Implement "less than"