obiloud / numeric-decimal / Numeric.Rational

Definition


type Rational

Arbitrary-precision rational numbers, represented as a ratio of two Int values.

Build ratio

ratio : Basics.Int -> Basics.Int -> Rational

Forms the ratio of two integers.

ratioBounded : Basics.Int -> Basics.Int -> Result Numeric.ArithmeticError.ArithmeticError Rational

Forms the ratio of two integers while checking for Overflow/Underflow.

Conversion

fromInt : Basics.Int -> Rational

Converts Int to Rational.

toFloat : Rational -> Basics.Float

Converts Rational to Float

toString : Rational -> String

Printing Rational to String representation.

inverse : Rational -> Rational

Inverse numerator and denominator of the Rational.

Extracting components of fractions

toPropperFraction : Rational -> ( Basics.Int, Rational )

The function toProperFraction takes a real fractional number x and returns a pair ( n, f ) such that x = n + f, and:

toNumerator : Rational -> Basics.Int

Extract the numerator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.

toDenominator : Rational -> Basics.Int

Extract the denominator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.

truncate : Rational -> Basics.Int

truncate x returns the integer nearest x between zero and x.

round : Rational -> Basics.Int

round x returns the nearest integer to x: the even integer if x is equily distant between two integers.

ceiling : Rational -> Basics.Int

ceiling x returns the least integer not less than x.

floor : Rational -> Basics.Int

floor x returns the greatest integer not greater than x.

Comparison

compare : Rational -> Rational -> Basics.Order

Compare two Rationals.

greaterThan : Rational -> Rational -> Basics.Bool

Compare two Rationals, greater than precidate.

lessThan : Rational -> Rational -> Basics.Bool

Compare two Rationals, less than precidate.

Arithmetic

add : Rational -> Rational -> Rational

Add two Rationals.

subtract : Rational -> Rational -> Rational

Subtract one Rational from another.

multiply : Rational -> Rational -> Rational

Multiply two Rationals.

divide : Rational -> Rational -> Rational

Divide two Rationals.

power : Basics.Int -> Rational -> Rational

Rase Rational to the power.

Bounded arithmetic

addBounded : Rational -> Rational -> Result Numeric.ArithmeticError.ArithmeticError Rational

Adds two Rationals while checking for Overflow/Underflow.

subtractBounded : Rational -> Rational -> Result Numeric.ArithmeticError.ArithmeticError Rational

Subtract one Rational from another while checking for Overflow/Underflow.

multiplyBounded : Rational -> Rational -> Result Numeric.ArithmeticError.ArithmeticError Rational

Multiply two Rationals while checking for Overflow/Underflow.

divideBounded : Rational -> Rational -> Result Numeric.ArithmeticError.ArithmeticError Rational

Divide two Rationals while checking for Overflow/Underflow.

powerBounded : Basics.Int -> Rational -> Result Numeric.ArithmeticError.ArithmeticError Rational

Rase Rational to the power while checking for Overflow/Underflow