diff --git a/src/main.js b/src/main.js index 91b9764..8801ffa 100644 --- a/src/main.js +++ b/src/main.js @@ -16,6 +16,34 @@ export function abs(a) { return (a >= _ZERO) ? a : -a; } +/** + * Maximum. max(a,b)==a if a>=b. max(a,b)==b if a<=b + * + * @param {number|bigint} a + * @param {number|bigint} b + * + * @returns {bigint} maximum of numbers a and b + */ + export function max(a, b) { + a = BigInt(a); + b = BigInt(b); + return (a >= b) ? a : b; +} + +/** + * Minimum. min(a,b)==b if a>=b. min(a,b)==a if a<=b + * + * @param {number|bigint} a + * @param {number|bigint} b + * + * @returns {bigint} minimum of numbers a and b + */ +export function min(a, b) { + a = BigInt(a); + b = BigInt(b); + return (a >= b) ? b : a; +} + /** * Returns the bitlength of a number *