number/rational#
Classes#
Rational#
Defined in: number/rational.ts:52
An exact fraction with a positive denominator, in lowest terms.
Properties#
denominator#
readonlydenominator:bigint
Defined in: number/rational.ts:54
numerator#
readonlynumerator:bigint
Defined in: number/rational.ts:53
Methods#
add()#
add(
other):Rational
Defined in: number/rational.ts:91
Parameters#
other#
Returns#
compare()#
compare(
other):-1|0|1
Defined in: number/rational.ts:129
-1, 0 or 1 as this value is below, equal to or above other.
Parameters#
other#
Returns#
-1 | 0 | 1
divide()#
divide(
other):Rational
Defined in: number/rational.ts:113
Parameters#
other#
Returns#
Throws#
if other is zero.
equals()#
equals(
other):boolean
Defined in: number/rational.ts:134
Parameters#
other#
Returns#
boolean
floor()#
floor():
bigint
Defined in: number/rational.ts:121
The largest integer not above this value.
Returns#
bigint
multiply()#
multiply(
other):Rational
Defined in: number/rational.ts:105
Parameters#
other#
Returns#
subtract()#
subtract(
other):Rational
Defined in: number/rational.ts:98
Parameters#
other#
Returns#
toFraction()#
toFraction(): readonly [
bigint,bigint]
Defined in: number/rational.ts:139
The Fraction pair [numerator, denominator].
Returns#
readonly [bigint, bigint]
toString()#
toString():
string
Defined in: number/rational.ts:143
Returns#
string
fromParts()#
staticfromParts(numerator,denominator):Rational
Defined in: number/rational.ts:84
Normalize a numerator and denominator.
Parameters#
numerator#
bigint
denominator#
bigint
Returns#
of()#
staticof(value):Rational
Defined in: number/rational.ts:68
Build a normalized rational from a Fraction pair, an integer or a decimal integer string.
Parameters#
value#
Returns#
Throws#
if a component is a JavaScript number that is not a safe integer, or the string is not a decimal integer.
Throws#
if the denominator is zero.
Type Aliases#
IntegerInput#
IntegerInput =
bigint|number
Defined in: number/rational.ts:10
An integer a Rational may be built from: a bigint or a safe integer.
RationalInput#
RationalInput =
IntegerInput|string| readonly [IntegerInput,IntegerInput] |Rational
Defined in: number/rational.ts:13
Anything a Rational may be built from.
Functions#
gcd()#
gcd(
left,right):bigint
Defined in: number/rational.ts:44
The greatest common divisor of two integers, never negative; 0 for two zeros.
Parameters#
left#
bigint
right#
bigint
Returns#
bigint
roundHalfEven()#
roundHalfEven(
numerator,denominator):bigint
Defined in: number/rational.ts:34
The integer nearest to numerator / denominator, a tie going to the even
one, as Python’s round.
Parameters#
numerator#
bigint
denominator#
bigint
Returns#
bigint
Throws#
if denominator is not positive.
toBigInt()#
toBigInt(
value):bigint
Defined in: number/rational.ts:22
Read an integer, refusing every number that is not a safe integer.
Parameters#
value#
Returns#
bigint