Skip to content
FutureBlitz

    Install

    Import std.math.big.rational

    std.math.big.rational

    Rational: a fraction of two BigInts, which never changes once it's made, kept in lowest terms with its denominator above 0, so its arithmetic is exact: 1/3 + 1/6 is 1/2. An Int64 on either side of an operator works too.

    std/math/big/rational.fb

    Types

    Rational class

    Public Class Rational Implements Comparable, Hashable, Printable, Numeric

    A fraction of two BigInts, in lowest terms, which is exact however it's added and multiplied.

    std/math/big/rational.fb, line 17

    • Public ReadOnly Field Numerator: BigInt field #

      Its numerator, which has its sign.

    • Public ReadOnly Field Denominator: BigInt field #

      Its denominator, which is above 0.

    • @PanicsAtCaller Public New(numerator: BigInt, denominator: BigInt) constructor #

      The fraction in lowest terms, with its denominator above 0, so Rational(2, -4) is -1/2. A denominator of 0 panics.

    • @PanicsAtCaller Public New(numerator: Int64, denominator: Int64 = 1) constructor #

      The fraction numerator over denominator, in lowest terms. A denominator of 0 panics.

    • Public New(value: BigInt) constructor #

      The BigInt, over 1.

    • Public Static Method Zero(): Rational static method #

      The number that adding leaves alone: 0.

      Doc from std.core.interfaces.Numeric.Zero.

    • Public Static Method One(): Rational static method #

      The number that multiplying leaves alone: 1.

      Doc from std.core.interfaces.Numeric.One.

    • @PanicsAtCaller Public Static Method FromDouble(value: Double): Rational static method #

      The Double exactly, as a fraction over a power of 2, so 0.1 is 3602879701896397/36028797018963968. A NaN or an infinity panics.

    • Public Static Method FromDecimal(value: Decimal): Rational static method #

      The Decimal exactly, as 0.75 is 3/4: its digits times or over a power of 10, from its text, as "-1.25E-7" and "0.75" are, so 1E+999999 doesn't go through a million digits.

    • Public Static Method Parse(text: String): Rational? static method #

      The fraction the text is: an integer, a "/", and digits, as "-3/4" is, or a Decimal's text, as "0.75" and "1e-3" are. Other text is Null, and so is a denominator of 0.

    • Public Method ToString(): String method #

      "3/4", or only the numerator when the denominator is 1, as in "-5".

    • Public Method ToDouble(): Double method #

      The Double nearest it, ties to even: an infinity past the largest Double, and 0 below the smallest.

    • @PanicsAtCaller Public Method ToDecimal(): Decimal method #

      It as a Decimal, in a Decimal's 28 digits.

    • Public Property Sign: Int property #

      -1, 0, or 1 as it's below, at, or above 0.

    • Public Method Abs(): Rational method #

      Its distance from 0: the same fraction, without its sign.

    • Public Method Truncate(): BigInt method #

      The whole number it rounds to: toward 0, down, up, or to the nearest, a half to the even one.

    • Public Method Floor(): BigInt method #

      The whole number it rounds down to.

    • Public Method Ceiling(): BigInt method #

      The whole number it rounds up to.

    • Public Method Round(): BigInt method #

      The whole number nearest it, a half to the even one.

    • Public Method Hash(): UInt64 method #

      Its hash, the same for values that are equal.

      Doc from std.core.interfaces.Hashable.Hash.

    • Operator ==(a: Rational, b: Rational): Bool operator #

      Whether a and b are equal.

      Doc from std.core.interfaces.Equatable.Operator==.

    • Operator ==(a: Rational, b: Int64): Bool operator #

      Whether a and b are equal.

    • Operator ==(a: Int64, b: Rational): Bool operator #

      Whether a and b are equal.

    • Operator <(a: Rational, b: Rational): Bool operator #

      Whether a comes before b.

      Doc from std.core.interfaces.Comparable.Operator<.

    • Operator <(a: Rational, b: Int64): Bool operator #

      Whether a comes before b.

    • Operator <(a: Int64, b: Rational): Bool operator #

      Whether a comes before b.

    • Operator >(a: Rational, b: Int64): Bool operator #

      Whether a comes after b.

    • Operator >(a: Int64, b: Rational): Bool operator #

      Whether a comes after b.

    • Operator <=(a: Rational, b: Int64): Bool operator #

      Whether a comes before b or is equal to it.

    • Operator <=(a: Int64, b: Rational): Bool operator #

      Whether a comes before b or is equal to it.

    • Operator >=(a: Rational, b: Int64): Bool operator #

      Whether a comes after b or is equal to it.

    • Operator >=(a: Int64, b: Rational): Bool operator #

      Whether a comes after b or is equal to it.

    • Operator +(a: Rational, b: Rational): Rational operator #

      a and b added up.

      Doc from std.core.interfaces.Numeric.Operator+.

    • Operator +(a: Rational, b: Int64): Rational operator #

      a plus b.

    • Operator +(a: Int64, b: Rational): Rational operator #

      a plus b.

    • Operator -(a: Rational, b: Rational): Rational operator #

      b taken away from a.

      Doc from std.core.interfaces.Numeric.Operator-.

    • Operator -(a: Rational, b: Int64): Rational operator #

      a minus b.

    • Operator -(a: Int64, b: Rational): Rational operator #

      a minus b.

    • Operator *(a: Rational, b: Rational): Rational operator #

      a and b multiplied together.

      Doc from std.core.interfaces.Numeric.Operator*.

    • Operator *(a: Rational, b: Int64): Rational operator #

      a times b.

    • Operator *(a: Int64, b: Rational): Rational operator #

      a times b.

    • @PanicsAtCaller Operator /(a: Rational, b: Rational): Rational operator #

      a divided by b.

      Doc from std.core.interfaces.Numeric.Operator/.

    • @PanicsAtCaller Operator /(a: Rational, b: Int64): Rational operator #

      a divided by b.

    • @PanicsAtCaller Operator /(a: Int64, b: Rational): Rational operator #

      a divided by b.

    • @PanicsAtCaller Operator **(a: Rational, b: Int64): Rational operator #

      To a whole power, which can be below 0, as 2/3 to -2 is 9/4. Anything to 0 is 1, and 0 to a power below 0 panics.

    • Operator -(a: Rational): Rational operator #

      a negated.

    Report an issue with this page or with FutureBlitz on GitHub.