From b38087c9a94b51b11eec4c4904db57cf050e260a Mon Sep 17 00:00:00 2001 From: Aisse-258 Date: Sun, 14 Jul 2019 11:56:58 +0300 Subject: [PATCH] Max(a,b) and Min(a,b) functions --- src/main.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 *