-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_laibrary.js
1 lines (1 loc) · 4.49 KB
/
math_laibrary.js
1
function MATH(){let t=Object.getOwnPropertyNames(Math),n={};for(let e=0;e<t.length;e++)n[t[e]]=Math[t[e]];return Number.__proto__.isOdd=function(){return this%2!=0},Number.__proto__.isPrime=function(){if(!(this>0))throw"Require a positive number";if(2===this)return!0;if(!(this>1))return!1;for(let t=2;t<this;t++)return this%t!=0},Number.__proto__.fact=function(){let t=1;if(this>0){for(let n=1;n<=this;n++)t*=n;return t}throw"Require a positive number"},n.random=function(t=1,n=0,e=null){let r,o;return o=n+Math.random()*(t-n),r=0===e?Math.floor(o):null===e||e>=12?o:parseFloat(o.toFixed(e)),r},n.qudrt=function(t=0,n=0,e=0){let r,o,u;if(u=bN**2-4*aN*cN,u<0)throw"Require some valid number for a,b,c in qudrt function";return r=(u**.5-bN)/(2*aN),o=(-(u**.5)-bN)/(2*aN),[r,o]},n.linearEq=function(t=[0,0,0],n=[0,0,0]){t[0]&&"number"==typeof t[0]?a1=t[0]:a1=0,t[1]&&"number"==typeof t[1]?b1=t[1]:b1=0,t[2]&&"number"==typeof t[2]?c1=t[2]:c1=0,n[0]&&"number"==typeof n[0]?a2=n[0]:a2=0,n[1]&&"number"==typeof n[1]?b2=n[1]:b2=0,n[2]&&"number"==typeof n[2]?c2=n[2]:c2=0;let e={},r=!Number.isNaN((c1*b2-c2*b1)/(a1*b2-b1*a2))&&(c1*b2-c2*b1)/(a1*b2-b1*a2),o=!Number.isNaN((c1*a2-c2*a1)/(b1*a2-a1*b2))&&(c1*a2-c2*a1)/(b1*a2-a1*b2);return!1!==r&&!1!==o?(e={x:r,y:o},e):{}},n.mean=function(...t){var n=[],e=0;let r;for(let r=0;r<t.length;r++){if(n[r]="number"==typeof t[r]&&t[r],!1===n[r])throw!1===n[r]?`${r+1}no. input is not a number`:"Somthing went wrong in mean function";e+=n[r]}return r=e/n.length,r},n.logx=function(t,n){let e="number"==typeof t&&1!==t&&t>0&&t,r="number"==typeof n&&n>0&&n;if(!1!==e&&!1!==r){return Math.log10(r)/Math.log10(e)}throw!1===e?"base should be a number which is grater than 0 and not equal to 1":!1===r?"angle should be a number which is grater than 0":"Somthing went wrong in logx function"},n.rootx=function(t=0,n=1){let e="number"==typeof t?t:NaN,r="number"==typeof n&&n;if(!1===e||!1===r)throw!1===e?"base should be a number":!1===r?"power should be a number":"Somthing went wrong in rootx function";return!r.isOdd()&&t>=0||r.isOdd()&&t>=0?result=Math.pow(e,1/r):r.isOdd()&&t<0&&r>0?(e=-e,result=-Math.pow(e,1/r)):r.isOdd()&&r<0&&t<0?(e=-e,r=-r,result=-1/Math.pow(e,1/r)-1e-16):result=NaN,result},n.permut=function(t=0,n=0){let e="number"==typeof t&&t>0&&t,r="number"==typeof n&&n>=0&&n<=t&&n;if(!1!==e&&!1!==r){return e.fact()/(e-r).fact()}throw!1===e?"n should be a number which is grater than 0":!1===r?"r should be a number which is grater than 0 and less than or equal to n":"Somthing went wrong in permut function"},n.combin=function(t=0,n=0){let e="number"==typeof t?t:NaN,r="number"==typeof n&&n;if(e>=0&&r>=0){return e.fact()/(r.fact()*(e-r).fact())}throw!1===e||e<0?"n should be a number which is grater than 0":!1===e||e<=0?"r should be a number which is grater than 0":"Somthing went wrong in combin function"},n.sec=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return 1/Math.cos(n);throw"radian should be a number in sec function"},n.cosec=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return 1/Math.sin(n);throw"radian should be a number in cosec function"},n.cot=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return 1/Math.tan(n);throw"radian should be a number in cot function"},n.sinh=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return(Math.pow(Math.E,n)-Math.pow(Math.E,-n))/2;throw"radian should be a number in sinh function"},n.cosh=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return(Math.pow(Math.E,n)+Math.pow(Math.E,-n))/2;throw"radian should be a number in cosh function"},n.tanh=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return(Math.pow(Math.E,n)-Math.pow(Math.E,-n))/(Math.pow(Math.E,n)+Math.pow(Math.E,-n));throw"radian should be a number in tanh function"},n.sech=function(t=0){let e="number"==typeof t&&t;if(!1!==e)return 1/n.cosh(e);throw"radian should be a number in sech function"},n.cosech=function(t=0){let e="number"==typeof t&&t;if(!1!==e)return 1/n.sinh(e);throw"radian should be a number in cosech function"},n.coth=function(t=0){let e="number"==typeof t&&t;if(!1!==e)return 1/n.tanh(e);throw"radian should be a number in coth function"},n.acosec=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return Math.asin(1/n);throw"ratio should be a number in acosec function"},n.asec=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return Math.acos(1/n);throw"ratio should be a number in asec function"},n.acot=function(t=0){let n="number"==typeof t&&t;if(!1!==n)return 0===n?Math.PI/2:Math.atan(1/n);throw"ratio should be a number in acot function"},Math=void 0,n}export const math=MATH();