torreyatcitty / the-best-decimal / Decimal

The datatype


type Decimal

The Decimal data type It is represented as mantissa * 10 ^ exponent

From stuff

fromInt : Basics.Int -> Decimal

Converts an Int to a Decimal

fromIntWithExponent : Basics.Int -> Basics.Int -> Decimal

Converts an Int to a Decimal, but specifying the exponent

fromString : String -> Maybe Decimal

Converts a String to a Maybe Decimal. The string shall be in the format [][.][e]

fromFloat : Basics.Float -> Maybe Decimal

Converts a Float to a Decimal

fromBigInt : BigInt -> Decimal

Converts an BigInt to a Decimal

fromBigIntWithExponent : Basics.Int -> BigInt -> Decimal

Converts an BigInt to a Decimal

To stuff

toString : Decimal -> String

Converts a Decimal to a String

toFloat : Decimal -> Basics.Float

Converts a Decimal to a Float

Arithmetic operations

add : Decimal -> Decimal -> Decimal

Addition

sub : Decimal -> Decimal -> Decimal

Substraction

negate : Decimal -> Decimal

Changes the sign of a Decimal

mul : Decimal -> Decimal -> Decimal

Multiplication

fastdiv : Decimal -> Decimal -> Maybe Decimal

Fast and dirty division. Don't expect too much precision from this division. Dividing by zero is bad, and Nothing will be returned.

Rounding

truncate : Basics.Int -> Decimal -> Decimal

Truncates the Decimal to the specified decimal places

round : Basics.Int -> Decimal -> Decimal

Rounds the Decimal to the specified decimal places

Comparing

gt : Decimal -> Decimal -> Basics.Bool

Greater than

gte : Decimal -> Decimal -> Basics.Bool

Greater than or equals

eq : Decimal -> Decimal -> Basics.Bool

Equals

neq : Decimal -> Decimal -> Basics.Bool

Not equals

lt : Decimal -> Decimal -> Basics.Bool

Less than

lte : Decimal -> Decimal -> Basics.Bool

Less than or equals

compare : Decimal -> Decimal -> Basics.Order

Compares two Decimals

Misc operations

abs : Decimal -> Decimal

Absolute value (sets the sign as positive)

getDigit : Basics.Int -> Decimal -> Basics.Int

Gets the specified digit from a Decimal. The digits are: 0 -> units 1 -> tens 2 -> hundreds and so on -1 -> tenths -2 -> hundredths and so on

Common numbers

zero : Decimal

The number 0

one : Decimal

The number 1

minusOne : Decimal

The number -1