obiloud/numeric-decimal/2.0.1

NOTE: the latest version is 3.0.1

Numeric.Rational

Definition

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

Build ratio

ratio : Int -> Int -> Rational

Forms the ratio of two integers.

ratioBounded : Int -> Int -> Result ArithmeticError Rational

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

Conversion

fromInt : Int -> Rational

Converts Int to Rational.

toFloat : Rational -> Float

Converts Rational to Float

toString : Rational -> String

Printing Rational to String representation.

Inverse numerator and denominator of the Rational.

Extracting components of fractions

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

  • n is an integral number with the same sign as x; and
  • f is a ratio with the same type and sign as x, and with absolute value less than 1.

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

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

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

round : Rational -> Int

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

ceiling : Rational -> Int

ceiling x returns the least integer not less than x.

floor : Rational -> Int

floor x returns the greatest integer not greater than x.

Comparison

compare : Rational -> Rational -> Order

Compare two Rationals.

Compare two Rationals, greater than precidate.

Compare two Rationals, less than precidate.

Arithmetic

Add two Rationals.

Subtract one Rational from another.

Multiply two Rationals.

Divide two Rationals.

power : Int -> Rational -> Rational

Rase Rational to the power.

Bounded arithmetic

Adds two Rationals while checking for Overflow/Underflow.

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

Multiply two Rationals while checking for Overflow/Underflow.

Divide two Rationals while checking for Overflow/Underflow.

Rase Rational to the power while checking for Overflow/Underflow