finos/morphir-elm/14.1.0

NOTE: the latest version is 22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

Morphir.SDK.Number

This module provides a way to represent a number without the risk of rounding issues or division by zero for any of the basic operations: +, -, *, /. More accurately a Number represents an arbitrary-precision rational number. If you need irrational numbers please use a Float.

type Number
= Rational BigInt BigInt

Represents an arbitrary-precision rational number.

Convert from

fromInt : Int -> Number

Create a Number by converting it from an Int

Comparison

equal : Number -> Number -> Bool

Checks if two numbers are equal.

equal one one == True


equal one (divide ten ten) == True


equal one zero == False
notEqual : Number -> Number -> Bool

Checks if two numbers are not equal.

notEqual one zero == True


notEqual zero one == True


notEqual one one == False
lessThan : Number -> Number -> Bool

Checks if the first number is less than the second

Checks if the first number is less than or equal to the second

Checks if the first number is greater than the second

Checks if the first number is greater or equal than the second

Arithmetic

Adds two numbers together.

Subtracts one number from the other.

Multiplies two numbers together

divide : Number -> Number -> Result DivisionByZero Number

Division

Takes the absolute value of the number

Negate the given number, thus flipping the sign.

Calculates the reciprocal of the number

Convert to

Create a fractional representation of the number

toDecimal : Number -> Maybe Decimal

Turn a number into a decimal. NOTE: it is possible for this operation to fail if the Number is a rational number for 0.

coerceToDecimal : Decimal -> Number -> Decimal

Turn a number into a decimal, by providing a default value in the case things go awry.

Misc

Tries to simplify the number.

Tells if the number is simplified

Constants

Constant for 0

Constant for one