math-base
Version:
MATH BASE: A tiny math library for node.js, deno.js & JavaScript on browser
1,493 lines (1,492 loc) • 53.8 kB
JavaScript
'use strict';
/**
* @package : Math Base
* @author : Montasir Mirghani
* @npm : https://www.npmjs.com/~dr-montasir
* @gitHub : https://github.com/dr-montasir
*/
/**
* @license MIT License
* @copyright Copyright (c) 2020 - 2022 Montasir Mirghani
* @text Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
/**
* @name MathBase ERRORS
*/
const ERRORS = {
MB_0_1: 'MathBase ERROR No. 00 : 01: This function only accepts numbers',
MB_0_2: 'MathBase ERROR No. 00 : 02: fact() argument must be natural number (ℕ0) between 0 and 170',
MB_1_1: 'MathBase ERROR No. 01 : 01: This function accepting either a number or an array. In the case of an array, all elements must be a number',
MB_1_2: 'MathBase ERROR No. 01 : 02: This function accepting either a string or an array. In the case of an array, all elements must be a string',
MB_1_3:
'MathBase ERROR No. 01 : 03: This function accepting two arguments of numbers, arrays, or one of them must be a number, and the other must be an array; In the case of arrays, all elements must be a number, the length of arrays must be equal',
MB_1_4: 'MathBase ERROR No. 01 : 04: The first parameter accepting either a number or an array. In the case of an array, all elements must be a number. The second parameter must be between 0 and 100',
MB_1_5: 'MathBase ERROR No. 01 : 05: This function accepts numeric arguments or one numeric array argument. (num1, num2, ..., num) => {} or ([num1, num2, ..., num]) => {}',
MB_1_6:
'MathBase ERROR No. 01 : 06: This function accepting two arguments. The first argument should be one (numeric or empty) array and the second should be a number. All next examples are valid: sum([num1, num2, ..., num_x]); sum([]); sum([num1, num2, ..., num_x], num); sum([], num)',
MB_2_1: 'MathBase ERROR No. 02 : 01: The step parameter should not be: 1/ null 2/ equal or less than zero. 3/ greater than the absolute difference between the first and second parameter',
MB_2_2: 'MathBase ERROR No. 02 : 02: All parameters must be a number. The first and the second parameter should not be equal',
MB_3_1: 'MathBase ERROR No. 03 : 01: The monolist function should take two numeric parameters (value: number, size: natural number & greater than zero)',
MB_4_1:
'MathBase ERROR No. 04 : 01: This function accepts three arguments. The first argument should be a number or one (numeric or empty) array. The second and third arguments must be a number. What does the function do? f(x, y, z): Replace x (number or numeric array element) with z if x is ',
MB_4_1_SUB_1: 'equal to y',
MB_4_1_SUB_2: 'not equal to y',
MB_4_1_SUB_3: 'greater than y',
MB_4_1_SUB_4: 'less than y',
MB_4_1_SUB_5: 'greater than or equal to y',
MB_4_1_SUB_6: 'less than or equal to y',
MB_5_1:
'MathBase ERROR No. 05 : 01: This function accepts two arguments. The first argument should be a number or one (numeric or empty) array. The second argument must be a number. What does the function do? f(x, y): Replace x (number or numeric array element) with y if x is ',
MB_5_1_SUB_1: 'finity num',
MB_5_1_SUB_2: 'infinity',
MB_5_1_SUB_3: 'plus infinity',
MB_5_1_SUB_4: 'minus infinity',
MB_5_1_SUB_5: 'NAN'
},
/**
* Mathematical constants
*/
/**
* @name The Number e (Euler's number) @section Mathematical constants
* @origin Math.E
*/
E = 2.718281828459045,
/**
* @name The Number Pi @section Mathematical constants
* @origin (21.991148575128552 / 7) = 3.141592653589793 = Math.PI
*/
PI = 3.141592653589793,
/**
* @name The Golden Ratio (Phi) @section Mathematical constants
* @origin 1.618033988749895
*/
PHI = Number(((1 + Math.sqrt(5)) / 2).toFixed(15)),
/**
* @name The tau constant @section Mathematical constants
* @description The circle constant representing the ratio between circumference and radius
*/
TAU = Number((2 * PI).toFixed(15)),
/**
* @name The natural logarithm of 2 @section Mathematical constants
*/
LN2 = Number(Math.LN2.toFixed(15)),
/**
* @name The natural logarithm of 10 @section Mathematical constants
*/
LN10 = Number(Math.LN10.toFixed(15)),
/**
* @name The base 2 logarithm of E @section Mathematical constants
*/
LOG2E = Number(Math.LOG2E.toFixed(15)),
/**
* @name The base 10 logarithm of E @section Mathematical constants
*/
LOG10E = Number(Math.LOG10E.toFixed(15)),
/**
* The base functions
*/
/**
* @name abs0 function
* @description abs0 is the base function use to generate abs and sine functions
* @example abs0(-1, 0) => 1
*/
// abs0 = (r: number, e: number) => (r > e ? r - e : e - r),
abs0 = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return r > e ? r - e : e - r;
throw new Error(ERRORS.MB_0_1);
},
/**
* @name signx function
* @description signx is the base function use to generate sign function
* @example signx(9) => 1, signx(-9) => -1, signx(0) => 0, signx(NaN) => NaN
*/
signx = (r) => {
if ('number' != typeof r) throw new Error(ERRORS.MB_0_1);
return 0 === r || isNaN(r) ? r : r > 0 ? 1 : -1;
},
/**
* @name Factorial Function
* @description The fact base function use to generate base sine function
* @example fact(4) => 24, 4! = 4 × 3 × 2 × 1 = 24
*/
fact = (r) => {
if (0 === r) return 1;
if (r > 0 && r % 1 == 0) return r * fact(r - 1);
throw new Error(ERRORS.MB_0_2);
},
/**
* @name degToRad
* @rule never fix or round
*/
degToRad = (r) => {
return (r * PI) / 180;
},
/**
* @name radToDeg
* @rule fix and round (fround)
* @why check (Math.PI) / (x=1, .., 3, 6, 12) * 180 / Math.PI => 180, .., 59.99999999999999, .., ..
* @correction check Math.fround((Math.PI) / (x=1,2,3) * 180 / Math.PI)
*/
radToDeg = (r) => {
return Math.fround((r * 180) / PI);
},
/**
* @name Sine function
* @description sine is the base function use to generate (sin, cos, tan, ..) functions
*/
sine = (r) => {
let eps = 1e-17,
n = 2,
v1 = r,
v2 = v1 - Math.pow(r, 3) / fact(3);
while (abs0(v1, v2) >= eps) (v1 = v2), (v2 += (Math.pow(-1, n) * Math.pow(r, 2 * n + 1)) / fact(2 * n + 1)), (n += 1);
return v2;
},
/**
* @name sineRad
* @rule (0 < r < π/2), (π/2 < r < π), (2π < r < 3π/2), (3π/2 < r < 2π) => +, +, -, -
*/
sineRad = (r) => {
// determine the sign of r (+ or -)
let sign = signx(r);
// convert any +r or -r angle to +r value from 0 to 2π. Ex. (2π + π/6 = π/6) => ((2π + π/6) % 2π = π/6)
r = abs0(r % (2 * PI), 0);
// limit r value from 0 to π/2 and save the rule of sign sine
r >= 0 && r <= 0.5 * PI ? r : r > 0.5 * PI && r <= PI ? (r = PI - r) : r > PI && r < 1.5 * PI ? (r = -1 * (r - PI)) : (r = -1 * (2 * PI - r));
// return the sign of r
r = sign * r;
// use the fround method to avoid the fractions of js operations
return Math.fround(sine(r));
},
/**
* @name sineDeg
* @rule (0 < r < 90), (90 < r < 180), (180 < r < 270), (270 < r < 360) => +, +, -, -
*/
sineDeg = (r) => {
// determine the sign of r (+ or -)
let sign = signx(r);
// convert any +r or -r angle to +r value from 0 to 360. Ex. (390deg = 30deg) => (390 % 360 = 30)
r = abs0(r % 360, 0);
// limit r value from 0 to 90 and save the rule of sign sine
r >= 0 && r <= 90 ? r : r > 90 && r <= 180 ? (r = 180 - r) : r > 180 && r < 270 ? (r = -1 * (r - 180)) : (r = -1 * (360 - r));
// return the sign of r
r = (sign * (r * PI)) / 180;
// use the fround method to avoid the fractions of js operations
return Math.fround(sine(r));
},
/**
* @name asine
*/
asine = (r) => {
return Math.asin(r);
},
/**
* @name asineRad
*/
asineRad = (r) => {
return Math.fround(asine(r));
},
/**
* @name asineDeg
*/
asineDeg = (r) => {
return radToDeg(Math.fround(asine(r)));
},
/**
* @name Hyperbolic sine (sineh)
*/
sineh = (r) => {
return (Math.pow(E, r) - Math.pow(E, -r)) / 2;
},
/**
* @name Hyperbolic sine (sinehRad)
*/
sinehRad = (r) => {
return Math.fround(sineh(r));
},
/**
* @name Hyperbolic sineDeg (sinehDeg)
*/
sinehDeg = (r) => {
return Math.fround(sineh(degToRad(r)));
},
/**
* @name Inverse hyperbolic sine (asineh)
*/
asineh = (r) => {
return Math.log(r + Math.sqrt(r * r + 1));
},
/**
* @name Inverse hyperbolic sine (asinehRad)
*/
asinehRad = (r) => {
return Math.fround(asineh(r));
},
/**
* @name Inverse hyperbolic sineDeg (asinehDeg)
*/
asinehDeg = (r) => {
return radToDeg(Math.fround(asineh(r)));
},
/**
* @name cosine
*/
cosine = (r) => {
return Math.sqrt(1 - Math.pow(sine(r), 2));
},
/**
* @name cosineRad
*/
cosineRad = (r) => {
return Math.fround(cosine(r));
},
/**
* @name cosineDeg
*/
cosineDeg = (r) => {
return Math.fround(cosine(degToRad(r)));
},
/**
* @name acosine
*/
acosine = (r) => {
return Math.acos(r);
},
/**
* @name acosineRad
*/
acosineRad = (r) => {
return Math.fround(acosine(r));
},
/**
* @name acosineDeg
*/
acosineDeg = (r) => {
return radToDeg(Math.fround(acosine(r)));
},
/**
* @name Hyperbolic cosine (cosineh)
*/
cosineh = (r) => {
return (Math.pow(E, r) + Math.pow(E, -r)) / 2;
},
/**
* @name Hyperbolic cosine (cosinehRad)
*/
cosinehRad = (r) => {
return Math.fround(cosineh(r));
},
/**
* @name Hyperbolic cosineDeg (cosinehDeg)
*/
cosinehDeg = (r) => {
return Math.fround(cosineh(degToRad(r)));
},
/**
* @name Inverse hyperbolic cosine (acosineh)
*/
acosineh = (r) => {
return Math.log(r + Math.sqrt(r * r - 1));
},
/**
* @name Inverse hyperbolic cosine (acosinehRad)
*/
acosinehRad = (r) => {
return Math.fround(acosineh(r));
},
/**
* @name Inverse hyperbolic cosine (acosinehDeg)
*/
acosinehDeg = (r) => {
return radToDeg(Math.fround(acosineh(r)));
},
/**
* @name tangentRad
*/
tangentRad = (r) => {
return Math.fround(sineRad(r) / cosineRad(r));
},
/**
* @name tangentDeg
*/
tangentDeg = (r) => {
return Math.fround(sineDeg(r) / cosineDeg(r));
},
/**
* @name atangent
*/
atangent = (r) => {
return Math.atan(r);
},
/**
* @name atangentRad
*/
atangentRad = (r) => {
return Math.fround(atangent(r));
},
/**
* @name atangentDeg
*/
atangentDeg = (r) => {
return radToDeg(Math.fround(atangent(r)));
},
/**
* @name Hyperbolic tangent (tangenth)
*/
tangenth = (r) => {
return (Math.pow(E, r) - Math.pow(E, -r)) / (Math.pow(E, r) + Math.pow(E, -r));
},
/**
* @name Hyperbolic tangent (tangenthRad)
*/
tangenthRad = (r) => {
return Math.fround(tangenth(r));
},
/**
* @name Hyperbolic tangentDeg (tangenthDeg)
*/
tangenthDeg = (r) => {
return Math.fround(tangenth(degToRad(r)));
},
/**
* @name Inverse hyperbolic tangent (atangenth)
*/
atangenth = (r) => {
return 0.5 * Math.log((1 + r) / (1 - r));
},
/**
* @name Inverse hyperbolic tangent (atangenthRad)
*/
atangenthRad = (r) => {
return Math.fround(atangenth(r));
},
/**
* @name Inverse hyperbolic tangent (atangenthDeg)
*/
atangenthDeg = (r) => {
return radToDeg(Math.fround(atangenth(r)));
},
/**
* @name cotangentRad
*/
cotangentRad = (r) => {
return Math.fround(cosineRad(r) / sineRad(r));
},
/**
* @name cotangentDeg
*/
cotangentDeg = (r) => {
return Math.fround(cosineDeg(r) / sineDeg(r));
},
/**
* @name acotangent
*/
acotangent = (r) => {
return atangent(1 / r);
},
/**
* @name acotangentRad
*/
acotangentRad = (r) => {
return Math.fround(acotangent(r));
},
/**
* @name acotangentDeg
*/
acotangentDeg = (r) => {
return radToDeg(Math.fround(acotangent(r)));
},
/**
* @name Hyperbolic cotangent (cotangenth)
*/
cotangenth = (r) => {
return (Math.pow(E, r) + Math.pow(E, -r)) / (Math.pow(E, r) - Math.pow(E, -r));
},
/**
* @name Hyperbolic cotangent (cotangenthRad)
*/
cotangenthRad = (r) => {
return Math.fround(cotangenth(r));
},
/**
* @name Hyperbolic cotangentDeg (cotangenthDeg)
*/
cotangenthDeg = (r) => {
return Math.fround(cotangenth(degToRad(r)));
},
/**
* @name Inverse hyperbolic cotangent (acotangenth)
*/
acotangenth = (r) => {
return 0.5 * Math.log((r + 1) / (r - 1));
},
/**
* @name Inverse hyperbolic cotangent (acotangenthRad)
*/
acotangenthRad = (r) => {
return Math.fround(acotangenth(r));
},
/**
* @name Inverse hyperbolic cotangent (acotangenthDeg)
*/
acotangenthDeg = (r) => {
return radToDeg(Math.fround(acotangenth(r)));
},
/**
* @name secant
*/
secant = (r) => {
return 1 / cosine(r);
},
/**
* @name secantRad
*/
secantRad = (r) => {
return Math.fround(secant(r));
},
/**
* @name secantDeg
*/
secantDeg = (r) => {
return Math.fround(secant(degToRad(r)));
},
/**
* @name asecant
*/
asecant = (r) => {
return Math.acos(1 / r);
},
/**
* @name asecantRad
*/
asecantRad = (r) => {
return Math.fround(asecant(r));
},
/**
* @name asecantDeg
*/
asecantDeg = (r) => {
return radToDeg(Math.fround(asecant(r)));
},
/**
* @name Hyperbolic secant (secanth)
*/
secanth = (r) => {
return 2 / (Math.pow(E, r) + Math.pow(E, -r));
},
/**
* @name Hyperbolic secant (secanthRad)
*/
secanthRad = (r) => {
return Math.fround(secanth(r));
},
/**
* @name Hyperbolic secantDeg (secanthDeg)
*/
secanthDeg = (r) => {
return Math.fround(secanth(degToRad(r)));
},
/**
* @name Inverse hyperbolic secant (asecanth)
*/
asecanth = (r) => {
return Math.log(1 / r + Math.sqrt(1 / (r * r) - 1));
},
/**
* @name Inverse hyperbolic secant (asecanthRad)
*/
asecanthRad = (r) => {
return Math.fround(asecanth(r));
},
/**
* @name Inverse hyperbolic secant (asecanthDeg)
*/
asecanthDeg = (r) => {
return radToDeg(Math.fround(asecanth(r)));
},
/**
* @name cosecant
*/
cosecant = (r) => {
return 1 / sineRad(r);
},
/**
* @name cosecantRad
*/
cosecantRad = (r) => {
return Math.fround(cosecant(r));
},
/**
* @name cosecantDeg
*/
cosecantDeg = (r) => {
return Math.fround(cosecant(degToRad(r)));
},
/**
* @name acosecant
*/
acosecant = (r) => {
return Math.asin(1 / r);
},
/**
* @name acosecantRad
*/
acosecantRad = (r) => {
return Math.fround(acosecant(r));
},
/**
* @name acosecantDeg
*/
acosecantDeg = (r) => {
return radToDeg(Math.fround(acosecant(r)));
},
/**
* @name Hyperbolic cosecant (cosecanth)
*/
cosecanth = (r) => {
return 2 / (Math.pow(E, r) - Math.pow(E, -r));
},
/**
* @name Hyperbolic cosecant (cosecanthRad)
*/
cosecanthRad = (r) => {
return Math.fround(cosecanth(r));
},
/**
* @name Hyperbolic cosecantDeg (cosecanthDeg)
*/
cosecanthDeg = (r) => {
return Math.fround(cosecanth(degToRad(r)));
},
/**
* @name Inverse hyperbolic cosecant (acosecanth)
*/
acosecanth = (r) => {
return Math.log(1 / r + Math.sqrt(1 / (r * r) + 1));
},
/**
* @name Inverse hyperbolic cosecant (acosecanthRad)
*/
acosecanthRad = (r) => {
return Math.fround(acosecanth(r));
},
/**
* @name Inverse hyperbolic secant (acosecanthDeg)
*/
acosecanthDeg = (r) => {
return radToDeg(Math.fround(acosecanth(r)));
},
/**
* All math base functions
*/
/**
* @name The abs function |-x| = x
*/
abs = (r) => {
if ('number' == typeof r) return abs0(r, 0);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => abs0(r, 0));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name The sign function
*/
sign = (r) => {
if ('number' == typeof r) return signx(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => signx(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name The Range Function @section Matrices
* @usage range(start, end, step) => number[]
* @example range(0, 10, 2.5) => [0, 2.5, 5, 7.5, 10]
* range(10, 0, 2.5) => [10, 7.5, 5, 2.5, 0]
*/
range = (r, e, t) => {
let n = [];
if (t <= 0 || t > Math.abs(r - e)) throw new Error(ERRORS.MB_2_1);
if ((t || (t = 1), 'number' == typeof r && 'number' == typeof e && 'number' == typeof t && r < e)) {
for (let o = r; o <= e; o += t) n.push(Number(o.toFixed(7)));
return n;
}
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t && r > e) {
for (let o = r; o >= e; o -= t) n.push(Number(o.toFixed(7)));
return n;
}
throw new Error(ERRORS.MB_2_2);
},
/**
* @name The MonoList Function @section Matrices
* @usage monolist(value, size) => number[]
* @example monolist(0.1, 3) => [0.1, 0.1, 0.1]
* monolist(-1, 4) => [-1, -1, -1, -1]
*/
monolist = (r, e) => {
if (!r || !e || 'number' != typeof r || 'number' != typeof e || 0 === r || e < 1 || e % 1 != 0) throw new Error(ERRORS.MB_3_1);
let n = Array(e).fill(r);
return n;
},
/**
* @name Degree to Radian @section Mathematical units conversion
* @description Degree to Radian conversion. (x = angle in degrees). Result in radians
*/
dtr = (r) => {
if ('number' == typeof r) return degToRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => degToRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name Radian to Degree @section Mathematical units conversion
* @description Radians to Degrees conversion. (x = angle in radians). Result in degrees
*/
rtd = (r) => {
if ('number' == typeof r) return radToDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => radToDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name Number to String. Result as string
*/
nts = (r) => {
if ('number' == typeof r) return String(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => String(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name String to Number. Result as number
*/
stn = (r) => {
if ('string' == typeof r) return Number(r);
if (Array.isArray(r) && r.every((r) => 'string' == typeof r)) return r.map((r) => Number(r));
throw new Error(ERRORS.MB_1_2);
},
/**
* @name zeros. Add fraction digits
*/
zeros = (r, e) => {
if ('number' == typeof r && 'number' == typeof e && e >= 0 && e <= 100) return r.toLocaleString('en', { minimumFractionDigits: e });
if ('number' == typeof e && e >= 0 && e <= 100 && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => r.toLocaleString('en', { minimumFractionDigits: e }));
throw new Error(ERRORS.MB_1_4);
},
/**
* @name The change function
* @description change(x, y, z): Replace x (number or numeric array element) with z if x = y
* @example change(1, 1, 0) => 0
* change([0, NaN, 1, 2], 2, 0) => [0, NaN, 1, 0]
*/
change = (r, e, t) => {
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t) return (r = r === e ? t : r);
if ('number' == typeof e && 'number' == typeof t && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r === e ? t : r));
throw new Error(ERRORS.MB_4_1 + ERRORS.MB_4_1_SUB_1);
},
/**
* @name The change.isNotEqual function
* @description change.isNotEqual(x, y, z): Replace x (number or numeric array element) with z if x is not equal to y
*/
isNotEqual = (r, e, t) => {
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t) return (r = r !== e ? t : r);
if ('number' == typeof e && 'number' == typeof t && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r !== e ? t : r));
throw new Error(ERRORS.MB_4_1 + ERRORS.MB_4_1_SUB_2);
},
/**
* @name The change.isGreater function
* @description change.isGreater(x, y, z): Replace x (number or numeric array element) with z if x is greater than y
*/
isGreater = (r, e, t) => {
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t) return (r = r > e ? t : r);
if ('number' == typeof e && 'number' == typeof t && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r > e ? t : r));
throw new Error(ERRORS.MB_4_1 + ERRORS.MB_4_1_SUB_3);
},
/**
* @name The change.isLess function
* @description change.isLess(x, y, z): Replace x (number or numeric array element) with z if x is less than y
*/
isLess = (r, e, t) => {
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t) return (r = r < e ? t : r);
if ('number' == typeof e && 'number' == typeof t && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r < e ? t : r));
throw new Error(ERRORS.MB_4_1 + ERRORS.MB_4_1_SUB_4);
},
/**
* @name The change.isGreaterOrEqual function
* @description change.isGreaterOrEqual(x, y, z): Replace x (number or numeric array element) with z if x is greater than or equal y
*/
isGreaterOrEqual = (r, e, t) => {
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t) return (r = r >= e ? t : r);
if ('number' == typeof e && 'number' == typeof t && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r >= e ? t : r));
throw new Error(ERRORS.MB_4_1 + ERRORS.MB_4_1_SUB_5);
},
/**
* @name The change.isLessOrEqual function
* @description change.isLessOrEqual(x, y, z): Replace x (number or numeric array element) with z if x is less than or equal y
*/
isLessOrEqual = (r, e, t) => {
if ('number' == typeof r && 'number' == typeof e && 'number' == typeof t) return (r = r <= e ? t : r);
if ('number' == typeof e && 'number' == typeof t && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r <= e ? t : r));
throw new Error(ERRORS.MB_4_1 + ERRORS.MB_4_1_SUB_6);
},
/**
* @name The change.isFiniteNum function
* @description change.isFiniteNum(x, y): Replace x with y if x is finity number.
*/
isFiniteNum = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return (r = !0 === isFinite(r) ? e : r);
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = !0 === isFinite(r) ? e : r));
throw new Error(ERRORS.MB_5_1 + ERRORS.MB_5_1_SUB_1);
},
/**
* @name The change.isInfinity function
* @description change.isInfinity(x, y): Replace x with y if x is infinity number.
*/
isInfinity = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return (r = r === 1 / 0 || r === -1 / 0 ? e : r);
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r === 1 / 0 || r === -1 / 0 ? e : r));
throw new Error(ERRORS.MB_5_1 + ERRORS.MB_5_1_SUB_2);
},
/**
* @name The change.isPlusInfinity function
* @description change.isPlusInfinity(x, y): Replace x with y if x is (+infinity) number.
*/
isPlusInfinity = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return (r = r === 1 / 0 ? e : r);
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r === 1 / 0 ? e : r));
throw new Error(ERRORS.MB_5_1 + ERRORS.MB_5_1_SUB_3);
},
/**
* @name The change.isMinusInfinity function
* @description change.isMinusInfinity(x, y): Replace x with y if x is (-infinity) number.
*/
isMinusInfinity = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return (r = r === -1 / 0 ? e : r);
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = r === -1 / 0 ? e : r));
throw new Error(ERRORS.MB_5_1 + ERRORS.MB_5_1_SUB_4);
},
/**
* @name The change.isNAN function
* @description change.isNAN(x, y): Replace x with y if x is NAN.
*/
isNAN = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return (r = !0 === isNaN(r) ? e : r);
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => (r = !0 === isNaN(r) ? e : r));
throw new Error(ERRORS.MB_5_1 + ERRORS.MB_5_1_SUB_5);
},
/**
* @name Addition Operation @section Mathematical operations
*/
add = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number((r + e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number((r + e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r + e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r)) return r.map((r, t) => Number((r + e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name Cube Function
*/
cube = (r) => {
if ('number' == typeof r) return Number((r * r * r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r * r * r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name Cube Root Function
*/
cbrt = (r) => {
if ('number' == typeof r) return Number(Math.cbrt(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.cbrt(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name Division Function. (r = numerator, e = denominator)
*/
divi = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number((r / e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number((r / e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r / e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r)) return r.map((r, t) => Number((r / e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
*
*/
fix = (r, e) => {
if ('number' == typeof r && 'number' == typeof e && e >= 0 && e <= 100) return Number(r.toFixed(e));
if ('number' == typeof e && e >= 0 && e <= 100 && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(r.toFixed(e)));
throw new Error(ERRORS.MB_1_4);
},
/**
* @name The hypot function
*/
hypot = (...r) => {
if (r.length > 0 && r.every((r) => 'number' == typeof r)) return Number(Math.hypot(...r).toFixed(15));
if (1 === r.length && r[0].length > 0 && Array.isArray(r[0]) && r[0].every((r) => 'number' == typeof r)) return Number(Math.hypot(...r[0]).toFixed(15));
throw new Error(ERRORS.MB_1_5);
},
/**
* @name inv
*/
inv = (r) => {
if ('number' == typeof r) return Number((1 / r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((1 / r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name log
*/
log = (r) => {
if ('number' == typeof r) return Number(Math.log(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.log(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name log2
*/
log2 = (r) => {
if ('number' == typeof r) return Number(Math.log2(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.log2(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name log10
*/
log10 = (r) => {
if ('number' == typeof r) return Number(Math.log10(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.log10(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name log1p
*/
log1p = (r) => {
if ('number' == typeof r) return Number(Math.log1p(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.log1p(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name max
*/
max = (...r) => {
if (r.length > 0 && r.every((r) => 'number' == typeof r)) return Math.max(...r);
if (1 === r.length && r[0].length > 0 && Array.isArray(r[0]) && r[0].every((r) => 'number' == typeof r)) return Math.max(...r[0]);
throw new Error(ERRORS.MB_1_5);
},
/**
* @name min
*/
min = (...r) => {
if (r.length > 0 && r.every((r) => 'number' == typeof r)) return Math.min(...r);
if (1 === r.length && r[0].length > 0 && Array.isArray(r[0]) && r[0].every((r) => 'number' == typeof r)) return Math.min(...r[0]);
throw new Error(ERRORS.MB_1_5);
},
/**
* @name sum
*/
sum = (r, e) => {
if (Array.isArray(r) && r.every((r) => 'number' == typeof r) && ((e && 'number' == typeof e) || !e)) {
return r.reduce((r, e) => Number((r + e).toFixed(15)), (e = e || 0));
}
throw new Error(ERRORS.MB_1_6);
},
/**
* @name mult
*/
mult = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number((r * e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number((r * e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r * e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r)) return r.map((r, t) => Number((r * e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name nrt
*/
nrt = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number(Math.pow(r, 1 / e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number(Math.pow(r, 1 / e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.pow(r, 1 / e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r))
return r.map((r, t) => Number(Math.pow(r, 1 / e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name pow
*/
pow = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number(Math.pow(r, e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number(Math.pow(r, e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.pow(r, e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r))
return r.map((r, t) => Number(Math.pow(r, e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name sqr
*/
sqr = (r) => {
if ('number' == typeof r) return Number((r * r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r * r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sqrt
*/
sqrt = (r) => {
if ('number' == typeof r) return Number(Math.sqrt(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.sqrt(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name subt
*/
subt = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number((r - e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number((r - e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r - e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r)) return r.map((r, t) => Number((r - e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name exp
*/
exp = (r) => {
if ('number' == typeof r) return Number(Math.pow(E, r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.pow(E, r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name expm1
*/
expm1 = (r) => {
if ('number' == typeof r) return Number(Math.expm1(r).toFixed(15));
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.expm1(r).toFixed(15)));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name trunc
*/
trunc = (r) => {
if ('number' == typeof r) return Math.trunc(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Math.trunc(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name
*/
imul = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number(Math.imul(r, e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number(Math.imul(r, e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.imul(r, e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r))
return r.map((r, t) => Number(Math.imul(r, e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name round
*/
round = (r) => {
if ('number' == typeof r) return Math.round(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Math.round(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name fround
*/
fround = (r) => {
if ('number' == typeof r) return Math.fround(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Math.fround(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name floor
*/
floor = (r) => {
if ('number' == typeof r) return Math.floor(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Math.floor(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name rib
*/
rib = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number(Math.floor(Math.random() * (e + 1 - r) + r).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number(Math.floor(Math.random() * (e + 1 - r) + r).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number(Math.floor(Math.random() * (e + 1 - r) + r).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r))
return r.map((r, t) => Number(Math.floor(Math.random() * (e[t] + 1 - r) + r).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name rem
*/
rem = (r, e) => {
if ('number' == typeof r && 'number' == typeof e) return Number((r - Math.floor(r / e) * e).toFixed(15));
if ('number' == typeof r && Array.isArray(e) && e.every((r) => 'number' == typeof r)) return e.map((e) => Number((r - Math.floor(r / e) * e).toFixed(15)));
if ('number' == typeof e && Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Number((r - Math.floor(r / e) * e).toFixed(15)));
if (Array.isArray(r) && Array.isArray(e) && r.length === e.length && r.every((r) => 'number' == typeof r) && e.every((r) => 'number' == typeof r))
return r.map((r, t) => Number((r - Math.floor(r / e[t]) * e[t]).toFixed(15)));
throw new Error(ERRORS.MB_1_3);
},
/**
* @name ceil
*/
ceil = (r) => {
if ('number' == typeof r) return Math.ceil(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => Math.ceil(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sin
* @example math.sin(0.523598775598299) = 0.5
*/
sin = (r) => {
if ('number' == typeof r) return sineRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => sineRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sinDeg
* @example math.sin.deg(30) = 0.5
*/
sinDeg = (r) => {
if ('number' == typeof r) return sineDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => sineDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asin
*/
asin = (r) => {
if ('number' == typeof r) return asineRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asineRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asin.deg
*/
asinDeg = (r) => {
if ('number' == typeof r) return asineDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asineDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sinh
*/
sinh = (r) => {
if ('number' == typeof r) return sinehRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => sinehRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sinh.deg
*/
sinhDeg = (r) => {
if ('number' == typeof r) return sinehDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => sinehDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asinh
*/
asinh = (r) => {
if ('number' == typeof r) return asinehRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asinehRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asinh.deg
*/
asinhDeg = (r) => {
if ('number' == typeof r) return asinehDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asinehDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name cos
* @example math.cos(1.047197551196598) = 0.5
*/
cos = (r) => {
if ('number' == typeof r) return cosineRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosineRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name cos.deg
* @example math.cos.deg(60) = 0.5
*/
cosDeg = (r) => {
if ('number' == typeof r) return cosineDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosineDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acos
*/
acos = (r) => {
if ('number' == typeof r) return acosineRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosineRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acos.deg
*/
acosDeg = (r) => {
if ('number' == typeof r) return acosineDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosineDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name cosh
*/
cosh = (r) => {
if ('number' == typeof r) return cosinehRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosinehRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name cosh.deg
*/
coshDeg = (r) => {
if ('number' == typeof r) return cosinehDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosinehDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acosh
*/
acosh = (r) => {
if ('number' == typeof r) return acosinehRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosinehRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acosh.deg
*/
acoshDeg = (r) => {
if ('number' == typeof r) return acosinehDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosinehDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name tan
*/
tan = (r) => {
if ('number' == typeof r) return tangentRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => tangentRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name tan.deg
*/
tanDeg = (r) => {
if ('number' == typeof r) return tangentDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => tangentDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name atan
*/
atan = (r) => {
if ('number' == typeof r) return atangentRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => atangentRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name atan.deg
*/
atanDeg = (r) => {
if ('number' == typeof r) return atangentDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => atangentDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name tanh
*/
tanh = (r) => {
if ('number' == typeof r) return tangenthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => tangenthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name tanh.deg
*/
tanhDeg = (r) => {
if ('number' == typeof r) return tangenthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => tangenthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name atanh
*/
atanh = (r) => {
if ('number' == typeof r) return atangenthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => atangenthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name atanh.deg
*/
atanhDeg = (r) => {
if ('number' == typeof r) return atangenthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => atangenthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name cot
*/
cot = (r) => {
if ('number' == typeof r) return cotangentRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cotangentRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name cot.deg
*/
cotDeg = (r) => {
if ('number' == typeof r) return cotangentDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cotangentDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acot
*/
acot = (r) => {
if ('number' == typeof r) return acotangentRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acotangentRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acot.deg
*/
acotDeg = (r) => {
if ('number' == typeof r) return acotangentDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acotangentDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name coth
*/
coth = (r) => {
if ('number' == typeof r) return cotangenthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cotangenthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name coth.deg
*/
cothDeg = (r) => {
if ('number' == typeof r) return cotangenthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cotangenthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acoth
*/
acoth = (r) => {
if ('number' == typeof r) return acotangenthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acotangenthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acoth.deg
*/
acothDeg = (r) => {
if ('number' == typeof r) return acotangenthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acotangenthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sec
*/
sec = (r) => {
if ('number' == typeof r) return secantRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => secantRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sec.deg
*/
secDeg = (r) => {
if ('number' == typeof r) return secantDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => secantDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asec
*/
asec = (r) => {
if ('number' == typeof r) return asecantRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asecantRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asec.deg
*/
asecDeg = (r) => {
if ('number' == typeof r) return asecantDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asecantDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sech
*/
sech = (r) => {
if ('number' == typeof r) return secanthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => secanthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name sech.deg
*/
sechDeg = (r) => {
if ('number' == typeof r) return secanthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => secanthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asech
*/
asech = (r) => {
if ('number' == typeof r) return asecanthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asecanthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name asech.deg
*/
asechDeg = (r) => {
if ('number' == typeof r) return asecanthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => asecanthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name csc
*/
csc = (r) => {
if ('number' == typeof r) return cosecantRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosecantRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name csc.deg
*/
cscDeg = (r) => {
if ('number' == typeof r) return cosecantDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosecantDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acsc
*/
acsc = (r) => {
if ('number' == typeof r) return acosecantRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosecantRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acsc.deg
*/
acscDeg = (r) => {
if ('number' == typeof r) return acosecantDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosecantDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name csch
*/
csch = (r) => {
if ('number' == typeof r) return cosecanthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosecanthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name csch.deg
*/
cschDeg = (r) => {
if ('number' == typeof r) return cosecanthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => cosecanthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acsch
*/
acsch = (r) => {
if ('number' == typeof r) return acosecanthRad(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosecanthRad(r));
throw new Error(ERRORS.MB_1_1);
},
/**
* @name acsch.deg
*/
acschDeg = (r) => {
if ('number' == typeof r) return acosecanthDeg(r);
if (Array.isArray(r) && r.every((r) => 'number' == typeof r)) return r.map((r) => acosecanthDeg(r));
throw new Error(ERRORS.MB_1_1);
},
useMB = () => {
let r = {};
return (
(r.e = E),
(r.pi = PI),
(r.phi = PHI),
(r.tau = TAU),
(r.ln2 = LN2),
(r.ln10 = LN10),
(r.log2e = LOG2E),
(r.log10e = LOG10E),
(r.abs0 = abs0),
(r.signx = signx),
(r.fact = fact),
(r.degToRad = degToRad),
(r.radToDeg = radToDeg),
(r.sine = sine),
(r.sineRad = sineRad),
(r.sineDeg = sineDeg),
(r.asine = asine),
(r.asineRad = asineRad),
(r.asineDeg = asineDeg),
(r.sineh = sineh),
(r.sinehRad = sinehRad),
(r.sinehDeg = sinehDeg),
(r.asineh = asineh),
(r.asinehRad = asinehRad),
(r.asinehDeg = asinehDeg),
(r.cosine = cosine),
(r.cosineRad = cosineRad),
(r.cosineDeg = cosineDeg),
(r.acosine = acosine),
(r.acosineRad = acosineRad),
(r.acosineDeg = acosineDeg),
(r.cosineh = cosineh),
(r.cosinehRad = cosinehRad),
(r.cosinehDeg = cosinehDeg),
(r.acosineh = acosineh),
(r.acosinehRad = acosinehRad),
(r.acosinehDeg = acosinehDeg),
(r.tangentRad = tangentRad),
(r.tangentDeg = tangentDeg),
(r.atangent = atangent),
(r.atangentRad = atangentRad),
(r.atangentDeg = atangentDeg),
(r.tangenth = tangenth),
(r.tangenthRad = tangenthRad),
(r.tangenthDeg = tangenthDeg),
(r.atangenth = atangenth),
(r.atangenthRad = atangenthRad),
(r.atangenthDeg = atangenthDeg),
(r.cotangentRad = cotangentRad),
(r.cotangentDeg = cotangentDeg),
(r.acotangent = acotangent),
(r.acotangentRad = acotangentRad),
(r.acotangentDeg = acotangentDeg),
(r.cotangenth = cotangenth),
(r.cotangenthRad = cotangenthRad),
(r.cotangenthDeg = cotangenthDeg),
(r.acotangenth = acotangenth),
(r.acotangenthRad = acotangenthRad),
(r.acotangenthDeg = acotangenthDeg),
(r.secant = secant),
(r.secantRad = secantRad),
(r.secantDeg = secantDeg),
(r.asecant = asecant),
(r.asecantRad = asecantRad),