Max(a,b) and Min(a,b) functions

This commit is contained in:
Aisse-258 2019-07-14 11:56:58 +03:00
parent 24b2677bfd
commit b38087c9a9
1 changed files with 28 additions and 0 deletions

View File

@ -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
*