@thi.ng/math
Version:
Assorted common math functions & utilities
58 lines • 1.39 kB
TypeScript
import type { FnN2 } from "@thi.ng/api";
/**
* Iteratively computes Greatest Common Divisor of given `a` and `b`.
*
* @remarks
* Reference:
*
* - https://en.wikipedia.org/wiki/Greatest_common_divisor
*
* @param a
* @param b
*/
export declare const gcd: FnN2;
/**
* Computes Least Common Multiple for given `a` and `b`. Returns zero if either
* input is zero.
*
* @remarks
* Reference:
*
* - https://en.wikipedia.org/wiki/Least_common_multiple
*
* @param a
* @param b
*/
export declare const lcm: FnN2;
/**
* Converts given `x` to a fraction with optional `maxDenom`inator, using
* continued fractions for best possible precision.
*
* @remarks
* Reference:
*
* - https://en.wikipedia.org/wiki/Continued_fraction
*
* @example
* ```ts tangle:../export/as-fraction.ts
* import { asFraction } from "@thi.ng/math";
*
* console.log(Math.PI, asFraction(Math.PI));
* // 3.141592653589793 [1146408, 364913]
*
* // keep denominator <= 1000
* console.log(Math.PI, asFraction(Math.PI, 1000));
* // 3.141592653589793 [ 355, 113 ]
* ```
*
* @param x
* @param maxDenom
*/
export declare const asFraction: (x: number, maxDenom?: number) => number[];
/**
* Reverse op of {@link asFraction}. Converts a fraction tuple to a JS number.
*
* @param fraction
*/
export declare const asFloat: ([a, b]: [number, number]) => number;
//# sourceMappingURL=fraction.d.ts.map