Import std.math.big.rational
std.math.big.rational
Exact fractions of BigInts.
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.
Examples
Local sum = Rational(1, 3) + Rational(1, 6)
Expect(sum == Rational(1, 2))
Expect(sum.Numerator == BigInt(1) && sum.Denominator == BigInt(2))
Expect(Rational(7, 2).Floor() == BigInt(3))
Expect(Rational(2, -4) == Rational(-1, 2))std/math/big/rational.fb, line 29
-
Its numerator, which has its sign.
-
Its denominator, which is above 0.
-
The fraction in lowest terms, with its denominator above 0, so Rational(2, -4) is -1/2. A
denominatorof 0 panics. -
The fraction
numeratoroverdenominator, in lowest terms. A denominator of 0 panics. -
The BigInt, over 1.
-
The zero Rational, 0, which adding leaves alone.
-
The Rational 1, which multiplying leaves alone.
-
The Double exactly, as a fraction over a power of 2, so 0.1 is 3602879701896397/36028797018963968. A NaN or an infinity panics.
-
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.
-
The fraction the
textis: an integer, a "/", and digits, as "-3/4" is, or a Decimal'stext, as "0.75" and "1e-3" are. Other text is Null, and so is a denominator of 0. -
"3/4", or only the numerator when the denominator is 1, as in "-5".
-
The Double nearest it, ties to even: an infinity past the largest Double, and 0 below the smallest.
-
It as a Decimal, in a Decimal's 28 digits.
-
-1, 0, or 1 as it's below, at, or above 0.
-
Its distance from 0: the same fraction, without its sign.
-
The whole number it rounds to: toward 0, down, up, or to the nearest, a half to the even one.
-
The whole number it rounds down to.
-
The whole number it rounds up to.
-
The whole number nearest it, a half to the even one.
-
A hash of its numerator and denominator, which Rationals that are equal share.
-
Whether
aandbare the same fraction. -
Whether
aandbare equal. -
Whether
aandbare equal. -
Whether
ais less thanb. -
Whether
acomes beforeb. -
Whether
acomes beforeb. -
Whether
acomes afterb. -
Whether
acomes afterb. -
Whether
acomes beforebor is equal to it. -
Whether
acomes beforebor is equal to it. -
Whether
acomes afterbor is equal to it. -
Whether
acomes afterbor is equal to it. -
aplusb, exactly, in lowest terms. -
aplusb. -
aplusb. -
aminusb, exactly, in lowest terms. -
aminusb. -
aminusb. -
atimesb, exactly, in lowest terms. -
atimesb. -
atimesb. -
adivided byb, exactly, in lowest terms. Abof 0 panics. -
adivided byb. -
adivided byb. -
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.
-
anegated.
Report an issue with this page or with FutureBlitz on GitHub.