| 1 | /**
|
|---|
| 2 | * Interface representing a fraction with numerator and denominator.
|
|---|
| 3 | */
|
|---|
| 4 | export interface NumeratorDenominator {
|
|---|
| 5 | n: number | bigint;
|
|---|
| 6 | d: number | bigint;
|
|---|
| 7 | }
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * Type for handling multiple types of input for Fraction operations.
|
|---|
| 11 | */
|
|---|
| 12 | export type FractionInput =
|
|---|
| 13 | | Fraction
|
|---|
| 14 | | number
|
|---|
| 15 | | bigint
|
|---|
| 16 | | string
|
|---|
| 17 | | [number | bigint | string, number | bigint | string]
|
|---|
| 18 | | NumeratorDenominator;
|
|---|
| 19 |
|
|---|
| 20 | /**
|
|---|
| 21 | * Function signature for Fraction operations like add, sub, mul, etc.
|
|---|
| 22 | */
|
|---|
| 23 | export type FractionParam = {
|
|---|
| 24 | (numerator: number | bigint, denominator: number | bigint): Fraction;
|
|---|
| 25 | (num: FractionInput): Fraction;
|
|---|
| 26 | };
|
|---|
| 27 |
|
|---|
| 28 | /**
|
|---|
| 29 | * Fraction class representing a rational number with numerator and denominator.
|
|---|
| 30 | */
|
|---|
| 31 | declare class Fraction {
|
|---|
| 32 | constructor();
|
|---|
| 33 | constructor(num: FractionInput);
|
|---|
| 34 | constructor(numerator: number | bigint, denominator: number | bigint);
|
|---|
| 35 |
|
|---|
| 36 | s: bigint;
|
|---|
| 37 | n: bigint;
|
|---|
| 38 | d: bigint;
|
|---|
| 39 |
|
|---|
| 40 | abs(): Fraction;
|
|---|
| 41 | neg(): Fraction;
|
|---|
| 42 |
|
|---|
| 43 | add: FractionParam;
|
|---|
| 44 | sub: FractionParam;
|
|---|
| 45 | mul: FractionParam;
|
|---|
| 46 | div: FractionParam;
|
|---|
| 47 | pow: FractionParam;
|
|---|
| 48 | log: FractionParam;
|
|---|
| 49 | gcd: FractionParam;
|
|---|
| 50 | lcm: FractionParam;
|
|---|
| 51 |
|
|---|
| 52 | mod(): Fraction;
|
|---|
| 53 | mod(num: FractionInput): Fraction;
|
|---|
| 54 |
|
|---|
| 55 | ceil(places?: number): Fraction;
|
|---|
| 56 | floor(places?: number): Fraction;
|
|---|
| 57 | round(places?: number): Fraction;
|
|---|
| 58 | roundTo: FractionParam;
|
|---|
| 59 |
|
|---|
| 60 | inverse(): Fraction;
|
|---|
| 61 | simplify(eps?: number): Fraction;
|
|---|
| 62 |
|
|---|
| 63 | equals(num: FractionInput): boolean;
|
|---|
| 64 | lt(num: FractionInput): boolean;
|
|---|
| 65 | lte(num: FractionInput): boolean;
|
|---|
| 66 | gt(num: FractionInput): boolean;
|
|---|
| 67 | gte(num: FractionInput): boolean;
|
|---|
| 68 | compare(num: FractionInput): number;
|
|---|
| 69 | divisible(num: FractionInput): boolean;
|
|---|
| 70 |
|
|---|
| 71 | valueOf(): number;
|
|---|
| 72 | toString(decimalPlaces?: number): string;
|
|---|
| 73 | toLatex(showMixed?: boolean): string;
|
|---|
| 74 | toFraction(showMixed?: boolean): string;
|
|---|
| 75 | toContinued(): bigint[];
|
|---|
| 76 | clone(): Fraction;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | export { Fraction as default, Fraction }; |
|---|