Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Frac

import { Frac } from "https://raw.githubusercontent.com/JOTSR/Denum/master/mod.ts";
class Frac extends AbstractValue<Frac> {
constructor(num: bigint, den: bigint);
get num();
get den();
get value();
 
abs(): Frac;
add(...frac: Frac[]): Frac;
compare(compared: Frac): bigint;
divide(...frac: Frac[]): Frac;
invert(): Frac;
isBetween(
min: Frac,
max: Frac,
includeBounds?,
): boolean;
isEqual(compared: Frac): boolean;
isEven(): boolean;
isGreater(compared: Frac, ifEqual?): boolean;
isInt(): boolean;
isLesser(compared: Frac, ifEqual?): boolean;
isNull(): boolean;
multiply(...frac: Frac[]): Frac;
opposite(): Frac;
power(power: bigint): Frac;
sign(): bigint;
simplify(): Frac;
sub(...frac: Frac[]): Frac;
toFloat(decimals?): number;
toJSON(): string;
toLatex(): string;
toString(): string;
 
static fromFloat(n: number | string, repeating?): Frac;
static fromJSON(json: string | Record<string, bigint>): Frac;
static fromLatex(latex: string): Frac;
static fromString(str: string): Frac;
}

§Extends

§
AbstractValue<Frac>
[src]

§Constructors

§
new Frac(num: bigint, den: bigint)
[src]

The constructor function takes two arguments, num and den, and sets the numerator and denominator of the rational number to the absolute value of num and den, respectively, and the sign of the numerator to the sign of Frac

@param num
  • The numerator of the rational number.
@param den
  • The denominator of the rational number.

§Properties

§
num readonly
[src]

get fraction numerator

§
den readonly
[src]

get fraction denominator

§
value readonly
[src]

get fraction value {num, den}

§Methods

§
abs(): Frac
[src]

Returns a new fraction object with the absolute value of the numerator and denominator

@return

A new Frac object with the absolute value of the numerator and denominator.

§
add(...frac: Frac[]): Frac
[src]

returns a new fraction that is the sum of the current Frac and all args

@param frac
  • Frac[]
@return

The return value is a new Frac

§
compare(compared: Frac): bigint
[src]

It compares two fractions and returns 0 if they are equal, 1 if the first is greater than the second, and -1 if the first is less than the second.

@param compared
  • The fraction to compare to.
@return

The sign of the difference between the two fractions.

§
divide(...frac: Frac[]): Frac
[src]

returns a new fraction that is the quotient of the current Frac by all args

@param frac
  • Frac[]
@return

The return value is a new Frac

§
invert(): Frac
[src]

It returns the inverse of the fraction.

@return

The inverse of the fraction.

§
isBetween(min: Frac, max: Frac, includeBounds?): boolean
[src]

It checks if the fraction is between two other fractions.

@param min
  • The minimum value to compare to.
@param max
  • The maximum value of the range.
@return

A boolean value

§
isEqual(compared: Frac): boolean
[src]

Returns true if the two fractions are equal, false otherwise.

@param compared
  • The fraction to compare to.
@return

A boolean value.

§
isEven(): boolean
[src]

isEven returns true if the fraction is even, false otherwise

@return

A boolean value.

§
isGreater(compared: Frac, ifEqual?): boolean
[src]

Returns true if the current fraction is greater than the compared fraction, or if the compared fraction is equal to the current fraction and ifEqual is true.

@param compared
  • The fraction to compare to.
@return

A boolean value.

§
isInt(): boolean
[src]

If the simplified denominator is 1, then the fraction is an integer.

@return

a boolean value.

§
isLesser(compared: Frac, ifEqual?): boolean
[src]

Returns true if the current fraction is lesser than the compared fraction, or if the compared fraction is equal to the current fraction and the ifEqual parameter is true.

@param compared
  • The fraction to compare to.
@return

The return value is a boolean.

§
isNull(): boolean
[src]

It returns true if the number is 0n, and false otherwise

@return

a boolean value.

§
multiply(...frac: Frac[]): Frac
[src]

returns a new fraction that is the product of the current Frac and all args

@param frac
  • Frac[]
@return

The return value is a new Frac

§
opposite(): Frac
[src]

It returns the opposite of the fraction

@return

The opposite of the fraction.

§
power(power: bigint): Frac
[src]

It takes a bigint as an argument and returns a new Frac object with the numerator and denominator raised to the power of the argument

@param power
  • The power to raise the fraction to.
@return

A new Frac object with the numerator and denominator raised to the power of the input.

§
sign(): bigint
[src]

If the number is less than zero, return negative one, otherwise return positive one.

@return

The sign of the number.

§
simplify(): Frac
[src]

It returns a new fraction that is the same as the original fraction, but simplified

@return

The simplified fraction.

§
sub(...frac: Frac[]): Frac
[src]

returns a new fraction that is the subtraction of the current Frac by all args

@param frac
  • Frac[]
@return

The return value is a new Frac

§
toFloat(decimals?): number
[src]

If the numerator and denominator are within the range of a 32 bit float, and the denominator is not zero, return the float value of the numerator divided by the denominator

@param decimals
  • Number of significant decimals (0-16)
@return

A function that returns a float.

§
toJSON(): string
[src]

The function returns a string that is a JSON representation of the object

@return

A string representation of the object.

§
toLatex(): string
[src]

If the numerator is negative, return the fraction wrapped in parentheses. Otherwise, return the fraction as a LaTeX string

@return

A string.

§
toString(): string
[src]

It returns a evaluable string representation of the fraction.

@return

The numerator and denominator of the fraction.

§Static Methods

§
fromFloat(n: number | string, repeating?): Frac
[src]

It takes a number or string, and returns a Frac object

@param n
  • number (float or int) | string ("xxx.xxx" or "num/den")
@return

the corresponding fraction

§
fromJSON(json: string | Record<string, bigint>): Frac
[src]

It takes a JSON string or object, and returns a new Frac object

@param json
  • string | Record<string, unknown>
@return

A new instance of the Frac class.

§
fromLatex(latex: string): Frac
[src]

It takes a string in the form of a LaTeX fraction, and returns a Frac object

@param latex
  • string
@return

A new instance of the Frac class.

§
fromString(str: string): Frac
[src]

It takes a string of shape "int/int" and returns a fraction

@param str
  • string
@return

A new instance of the Frac class