Socket
Socket
Sign inDemoInstall

@thi.ng/math

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/math - npm Package Compare versions

Comparing version 3.4.0 to 4.0.0

libc.d.ts

31

CHANGELOG.md

@@ -6,2 +6,25 @@ # Change Log

# [4.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@3.4.0...@thi.ng/math@4.0.0) (2021-04-24)
### Features
* **math:** add libc math fns ([28b41a8](https://github.com/thi-ng/umbrella/commit/28b41a824758b83cea09c29f48e6f14f56368c40))
* **math:** add/update modulo functions ([be7b02b](https://github.com/thi-ng/umbrella/commit/be7b02beaf4ab1ab1030597a5f4eb94d43e1469b))
### BREAKING CHANGES
* **math:** Introduction of standard libc math functions causes
behavior change of existing `fmod()` function...
- rename `fmod()` => `mod()` to align w/ GLSL counterpart
- add new `fmod()` w/ standard libc behavior (same as JS % op)
- add `remainder()` w/ standard libc behavior
- update doc strings
# [3.4.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@3.3.0...@thi.ng/math@3.4.0) (2021-04-03)

@@ -39,10 +62,2 @@

## [3.2.5](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@3.2.4...@thi.ng/math@3.2.5) (2021-03-12)
**Note:** Version bump only for package @thi.ng/math
# [3.2.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/math@3.1.0...@thi.ng/math@3.2.0) (2021-02-20)

@@ -49,0 +64,0 @@

@@ -10,2 +10,3 @@ export * from "./api";

export * from "./interval";
export * from "./libc";
export * from "./min-error";

@@ -12,0 +13,0 @@ export * from "./mix";

@@ -10,2 +10,3 @@ export * from "./api";

export * from "./interval";
export * from "./libc";
export * from "./min-error";

@@ -12,0 +13,0 @@ export * from "./mix";

@@ -261,2 +261,26 @@ 'use strict';

const copysign = (x, y) => Math.sign(y) * Math.abs(x);
const exp2 = (x) => 2 ** x;
const fdim = (x, y) => Math.max(x - y, 0);
const fma = (x, y, z) => x * y + z;
const fmod = (x, y) => x % y;
const frexp = (x) => {
if (x === 0 || !isFinite(x))
return [x, 0];
const abs = Math.abs(x);
let exp = Math.max(-1023, Math.floor(Math.log2(abs)) + 1);
let y = abs * 2 ** -exp;
while (y < 0.5) {
y *= 2;
exp--;
}
while (y >= 1) {
y *= 0.5;
exp++;
}
return [x < 0 ? -y : y, exp];
};
const ldexp = (x, exp) => x * 2 ** exp;
const remainder = (x, y) => x - y * Math.round(x / y);
const minError = (fn, error, q, res = 16, iter = 8, start = 0, end = 1, eps = EPS) => {

@@ -365,3 +389,3 @@ if (iter <= 0)

const fmod = (a, b) => a - b * Math.floor(a / b);
const mod = (a, b) => a - b * Math.floor(a / b);
const fract = (x) => x - Math.floor(x);

@@ -502,2 +526,3 @@ const trunc = (x) => (x < 0 ? Math.ceil(x) : Math.floor(x));

exports.classifyCrossing = classifyCrossing;
exports.copysign = copysign;
exports.cosine = cosine;

@@ -521,2 +546,3 @@ exports.cossin = cossin;

exports.eqDeltaScaled = eqDeltaScaled;
exports.exp2 = exp2;
exports.expFactor = expFactor;

@@ -526,2 +552,3 @@ exports.expStep = expStep;

exports.fastSin = fastSin;
exports.fdim = fdim;
exports.fit = fit;

@@ -533,5 +560,7 @@ exports.fit01 = fit01;

exports.floorTo = floorTo;
exports.fma = fma;
exports.fmod = fmod;
exports.foldback = foldback;
exports.fract = fract;
exports.frexp = frexp;
exports.gain = gain;

@@ -548,2 +577,3 @@ exports.gaussian = gaussian;

exports.lanczos = lanczos;
exports.ldexp = ldexp;
exports.lens = lens;

@@ -578,2 +608,3 @@ exports.loc = loc;

exports.mixQuadratic = mixQuadratic;
exports.mod = mod;
exports.muli16 = muli16;

@@ -602,2 +633,3 @@ exports.muli32 = muli32;

exports.rad = rad;
exports.remainder = remainder;
exports.roundEps = roundEps;

@@ -604,0 +636,0 @@ exports.roundTo = roundTo;

@@ -1,1 +0,1 @@

!function(t,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a(((t="undefined"!=typeof globalThis?globalThis:t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.math={}))}(this,(function(t){"use strict";const a=Math.PI,i=2*a,n=a/2,s=a/3,e=a/4,r=a/6,o=1/a,u=1/i,h=1/n,c=a/180,l=180/a,M=(1+Math.sqrt(5))/2,d=Math.SQRT2,f=Math.sqrt(3),m=d/2,b=f/2;let p=1e-6;const x=t=>(t%=i)<0?i+t:t,g=t=>(t=Math.abs(t))>a?i-t:t,I=t=>{const a=t*t;return.99940307+a*(.03679168*a-.49558072)},T=t=>{switch((t%=i)<0&&(t=-t),t*h|0){case 0:return I(t);case 1:return-I(a-t);case 2:return-I(t-a);default:return I(i-t)}},v=Math.abs,R=Math.max,q=(t,a,i=p)=>v(t-a)<=i,D=q,P=(t,a,i,n)=>t<i&&a>n,S=(t,a,i,n)=>t>i&&a<n,_=(t,a,i)=>t>a&&a<i,C=(t,a,i)=>t<a&&a>i,w=(t,a,i=0,n=a.length)=>{n--;for(let s=i+1;s<n;s++)if(t(a[s-1],a[s],a[s+1]))return s;return-1},H=(t,a=0,i=t.length)=>w(_,t,a,i);function*A(t,a,i=0,n=a.length){for(;i<n;){const s=t(a,i,n);if(s<0)return;yield s,i=s+1}}const y=t=>t<0?0:t>1?1:t,E=t=>t<-1?-1:t>1?1:t,Q=(t,a)=>0!==t?0!==a?Math.min(t,a):t:a,N=(t,a,i)=>F(t,a,-i),F=(t,a,i)=>{const n=Math.exp(t*i),s=Math.exp(a*i);return(t*n+a*s)/(n+s)},O=(t,a,i)=>i!==a?(t-a)/(i-a):0,U=255,L=65535,V=t=>128&(t&=U)?t|~U:t,j=t=>32768&(t&=L)?t|~L:t,k=(t,a,i,n=16,s=8,e=0,r=1,o=p)=>{if(s<=0)return(e+r)/2;const u=(r-e)/n;let h=e,c=1/0;for(let s=0;s<=n;s++){const n=e+s*u,r=a(i,t(n));if(r<c){if(r<=o)return n;c=r,h=n}}return k(t,a,i,n,s-1,Math.max(h-u,0),Math.min(h+u,1))},z=(t,a,i)=>t+(a-t)*i,B=(t,a,i,n,s)=>{const e=s*s;return s*e*(-.5*t+1.5*a-1.5*i+(n*=.5))+e*(t-2.5*a+2*i-n)+s*(-.5*t+.5*i)+a},G=t=>(t=1-t,Math.sqrt(1-t*t)),X=t=>1-G(1-t),Z=t=>0!==t?Math.sin(t)/t:1,W=(t,a,i)=>i!=t?1/(1+Math.exp(-a*(i-t))):.5,J=t=>t-Math.floor(t),K=(t,a)=>0!==a?t/a:0;t.DEG2RAD=c,t.EPS=p,t.HALF_PI=n,t.INV_HALF_PI=h,t.INV_PI=o,t.INV_TAU=u,t.PHI=M,t.PI=a,t.QUARTER_PI=e,t.RAD2DEG=l,t.SIXTH=1/6,t.SIXTH_PI=r,t.SQRT2=d,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=f,t.TAU=i,t.THIRD=1/3,t.THIRD_PI=s,t.TWO_THIRD=2/3,t.absDiff=(t,a)=>Math.abs(t-a),t.absInnerAngle=g,t.absMax=(t,a)=>Math.abs(t)>Math.abs(a)?t:a,t.absMin=(t,a)=>Math.abs(t)<Math.abs(a)?t:a,t.absTheta=x,t.addi16=(t,a)=>j((0|t)+(0|a)),t.addi32=(t,a)=>(0|t)+(0|a)|0,t.addi8=(t,a)=>V((0|t)+(0|a)),t.addu16=(t,a)=>(t&L)+(a&L)&L,t.addu32=(t,a)=>(t>>>0)+(a>>>0)>>>0,t.addu8=(t,a)=>(t&U)+(a&U)&U,t.andi16=(t,a)=>j((0|t)&(0|a)),t.andi32=(t,a)=>(0|t)&(0|a),t.andi8=(t,a)=>V((0|t)&(0|a)),t.andu16=(t,a)=>t&L&a&L&L,t.andu32=(t,a)=>(t>>>0&a>>>0)>>>0,t.andu8=(t,a)=>t&U&a&U&U,t.angleDist=(t,a)=>g(x(a%i-t%i)),t.atan2Abs=(t,a)=>x(Math.atan2(t,a)),t.bounce=(t,a,i)=>{const s=i*t;return 1-a*Math.sin(s)/s*Math.cos(i*n)},t.ceilTo=(t,a=1)=>Math.ceil(t/a)*a,t.circular=G,t.clamp=(t,a,i)=>t<a?a:t>i?i:t,t.clamp0=t=>t>0?t:0,t.clamp01=y,t.clamp05=t=>t<0?0:t>.5?.5:t,t.clamp11=E,t.classifyCrossing=(t,a,i,n,s=p)=>q(t,i,s)&&q(a,n,s)?q(t,n,s)?"flat":"equal":P(t,a,i,n)?"over":S(t,a,i,n)?"under":"other",t.cosine=t=>1-(.5*Math.cos(t*a)+.5),t.cossin=(t,a=1)=>[Math.cos(t)*a,Math.sin(t)*a],t.cot=t=>1/Math.tan(t),t.csc=t=>1/Math.sin(t),t.cubicPulse=(t,a,i)=>(i=Math.abs(i-a))>t?0:1-(i/=t)*i*(3-2*i),t.decimated=(t,a)=>Math.floor(a*t)/t,t.deg=t=>t*l,t.derivative=(t,a=p)=>i=>(t(i+a)-t(i))/a,t.divi16=(t,a)=>j((0|t)/(0|a)),t.divi32=(t,a)=>(0|t)/(0|a)|0,t.divi8=(t,a)=>V((0|t)/(0|a)),t.divu16=(t,a)=>(t&L)/(a&L)&L,t.divu32=(t,a)=>(t>>>0)/(a>>>0)>>>0,t.divu8=(t,a)=>(t&U)/(a&U)&U,t.ease=(t,a)=>Math.pow(a,t),t.eqDelta=q,t.eqDeltaFixed=D,t.eqDeltaScaled=(t,a,i=p)=>v(t-a)<=i*R(1,v(t),v(a)),t.expFactor=(t,a,i)=>(a/t)**(1/i),t.expStep=(t,a,i)=>1-Math.exp(-t*Math.pow(i,a)),t.fastCos=T,t.fastSin=t=>T(n-t),t.fit=(t,a,i,n,s)=>n+(s-n)*O(t,a,i),t.fit01=(t,a,i)=>a+(i-a)*y(t),t.fit10=(t,a,i)=>i+(a-i)*y(t),t.fit11=(t,a,i)=>a+(i-a)*(.5+.5*E(t)),t.fitClamped=(t,a,i,n,s)=>n+(s-n)*y(O(t,a,i)),t.floorTo=(t,a=1)=>Math.floor(t/a)*a,t.fmod=(t,a)=>t-a*Math.floor(t/a),t.foldback=(t,a)=>a<-t||a>t?Math.abs(Math.abs((a-t)%(4*t))-2*t)-t:a,t.fract=J,t.gain=(t,a)=>a<.5?.5*Math.pow(2*a,t):1-.5*Math.pow(2-2*a,t),t.gaussian=(t,a,i)=>Math.exp(-((i-t)**2)/(2*a*a)),t.impulse=(t,a)=>{const i=t*a;return i*Math.exp(1-i)},t.inOpenRange=(t,a,i)=>t>a&&t<i,t.inRange=(t,a,i)=>t>=a&&t<=i,t.invCircular=X,t.isCrossOver=P,t.isCrossUnder=S,t.isMaxima=C,t.isMinima=_,t.lanczos=(t,i)=>0!==i?-t<i&&i<t?Z(a*i)*Z(a*i/t):0:1,t.lens=(t,a,i)=>{const n=a>0?X:G,s=1-t,e=i<=t?n(i/t)*t:1-n((1-i)/s)*s;return z(i,e,Math.abs(a))},t.loc=(t,a,i)=>Math.sqrt(t*t+a*a-2*t*a*Math.cos(i)),t.lshifti16=(t,a)=>j((0|t)<<(0|a)),t.lshifti32=(t,a)=>(0|t)<<(0|a),t.lshifti8=(t,a)=>V((0|t)<<(0|a)),t.lshiftu16=(t,a)=>(t&L)<<(a&L)&L,t.lshiftu32=(t,a)=>t>>>0<<(a>>>0)>>>0,t.lshiftu8=(t,a)=>(t&U)<<(a&U)&U,t.max2id=(t,a)=>t>=a?0:1,t.max3id=(t,a,i)=>t>=a?t>=i?0:2:a>=i?1:2,t.max4id=(t,a,i,n)=>t>=a?t>=i?t>=n?0:3:i>=n?2:3:a>=i?a>=n?1:3:i>=n?2:3,t.maximaIndex=(t,a=0,i=t.length)=>w(C,t,a,i),t.maximaIndices=(t,a=0,i=t.length)=>A(H,t,a,i),t.min2id=(t,a)=>t<=a?0:1,t.min3id=(t,a,i)=>t<=a?t<=i?0:2:a<=i?1:2,t.min4id=(t,a,i,n)=>t<=a?t<=i?t<=n?0:3:i<=n?2:3:a<=i?a<=n?1:3:i<=n?2:3,t.minError=k,t.minNonZero2=Q,t.minNonZero3=(t,a,i)=>Q(Q(t,a),i),t.minimaIndex=H,t.minimaIndices=(t,a=0,i=t.length)=>A(H,t,a,i),t.mix=z,t.mixBicubic=(t,a,i,n,s,e,r,o,u,h,c,l,M,d,f,m,b,p)=>B(B(t,a,i,n,b),B(s,e,r,o,b),B(u,h,c,l,b),B(M,d,f,m,b),p),t.mixBilinear=(t,a,i,n,s,e)=>{const r=1-s,o=1-e;return t*r*o+a*s*o+i*r*e+n*s*e},t.mixCubic=(t,a,i,n,s)=>{const e=s*s,r=1-s,o=r*r;return t*o*r+3*a*o*s+3*i*e*r+n*e*s},t.mixCubicHermite=(t,a,i,n,s)=>{const e=s-1,r=s*s,o=e*e;return(1+2*s)*o*t+s*o*a+r*(3-2*s)*i+r*e*n},t.mixCubicHermiteFromPoints=B,t.mixHermite=(t,a,i,n,s)=>{const e=.5*(i-t),r=1.5*(a-i)+.5*(n-t);return((r*s+t-a+e-r)*s+e)*s+a},t.mixQuadratic=(t,a,i,n)=>{const s=1-n;return t*s*s+2*a*s*n+i*n*n},t.muli16=(t,a)=>j((0|t)*(0|a)),t.muli32=(t,a)=>(0|t)*(0|a)|0,t.muli8=(t,a)=>V((0|t)*(0|a)),t.mulu16=(t,a)=>(t&L)*(a&L)&L,t.mulu32=(t,a)=>(t>>>0)*(a>>>0)>>>0,t.mulu8=(t,a)=>(t&U)*(a&U)&U,t.norm=O,t.normCos=t=>{const a=t*t;return 1+a*(2*a-4)},t.noti16=t=>j(~t),t.noti32=t=>~t,t.noti8=t=>V(~t),t.notu16=t=>~t&L,t.notu32=t=>~t>>>0,t.notu8=t=>~t&U,t.ori16=(t,a)=>j(0|t|a),t.ori32=(t,a)=>0|t|a,t.ori8=(t,a)=>V(0|t|a),t.oru16=(t,a)=>(t&L|a&L)&L,t.oru32=(t,a)=>(t>>>0|a>>>0)>>>0,t.oru8=(t,a)=>(t&U|a&U)&U,t.parabola=(t,a)=>Math.pow(4*a*(1-a),t),t.quadrant=t=>x(t)*h|0,t.rad=t=>t*c,t.roundEps=(t,a=p)=>{const i=J(t);return i<=a||i>=1-a?Math.round(t):t},t.roundTo=(t,a=1)=>Math.round(t/a)*a,t.rshifti16=(t,a)=>j((0|t)>>(0|a)),t.rshifti32=(t,a)=>(0|t)>>(0|a),t.rshifti8=(t,a)=>V((0|t)>>(0|a)),t.rshiftu16=(t,a)=>(t&L)>>>(a&L)&L,t.rshiftu32=(t,a)=>t>>>0>>>(a>>>0)>>>0,t.rshiftu8=(t,a)=>(t&U)>>>(a&U)&U,t.safeDiv=K,t.schlick=(t,a,i)=>i<=a?a*i/(i+t*(a-i)+p):(1-a)*(i-1)/(1-i-t*(a-i)+p)+1,t.sclamp=(t,a,i,n)=>N(F(t,a,n),i,n),t.sec=t=>1/Math.cos(t),t.sigmoid=W,t.sigmoid01=(t,a)=>W(.5,t,a),t.sigmoid11=(t,a)=>W(0,t,a),t.sign=(t,a=p)=>t>a?1:t<-a?-1:0,t.signExtend16=j,t.signExtend8=V,t.simplifyRatio=(t,a)=>{let i=Math.abs(t),n=Math.abs(a);for(;;){if(i<n){const t=i;i=n,n=t}const s=i%n;if(!s)return[t/n,a/n];i=s}},t.sinc=Z,t.sincNormalized=(t,i)=>Z(a*t*i),t.sincos=(t,a=1)=>[Math.sin(t)*a,Math.cos(t)*a],t.smax=F,t.smin=N,t.smoothStep=(t,a,i)=>(3-2*(i=y((i-t)/(a-t))))*i*i,t.smootherStep=(t,a,i)=>(i=y((i-t)/(a-t)))*i*i*(i*(6*i-15)+10),t.solveCubic=(t,a,i,n,s=1e-9)=>{const e=t*t,r=a*a,o=a/(3*t),u=(3*t*i-r)/(3*e),h=(2*r*a-9*t*a*i+27*e*n)/(27*e*t);if(Math.abs(u)<s)return[Math.cbrt(-h)-o];if(Math.abs(h)<s)return u<0?[-Math.sqrt(-u)-o,-o,Math.sqrt(-u)-o]:[-o];{const t=h*h/4+u*u*u/27;if(Math.abs(t)<s)return[-1.5*h/u-o,3*h/u-o];if(t>0){const a=Math.cbrt(-h/2-Math.sqrt(t));return[a-u/(3*a)-o]}{const t=2*Math.sqrt(-u/3),a=Math.acos(3*h/u/t)/3,i=2*Math.PI/3;return[t*Math.cos(a)-o,t*Math.cos(a-i)-o,t*Math.cos(a-2*i)-o]}}},t.solveLinear=(t,a)=>K(-a,t),t.solveQuadratic=(t,a,i,n=1e-9)=>{const s=2*t;let e=a*a-4*t*i;return e<0?[]:e<n?[-a/s]:(e=Math.sqrt(e),[(-a-e)/s,(-a+e)/s])},t.step=(t,a)=>a<t?0:1,t.subi16=(t,a)=>j((0|t)-(0|a)),t.subi32=(t,a)=>(0|t)-(0|a)|0,t.subi8=(t,a)=>V((0|t)-(0|a)),t.subu16=(t,a)=>(t&L)-(a&L)&L,t.subu32=(t,a)=>(t>>>0)-(a>>>0)>>>0,t.subu8=(t,a)=>(t&U)-(a&U)&U,t.tangentCardinal=(t,a,i=.5,n=0,s=2)=>i*((a-t)/(s-n)),t.tangentDiff3=(t,a,i,n=0,s=1,e=2)=>.5*((i-a)/(e-s)+(a-t)/(s-n)),t.trunc=t=>t<0?Math.ceil(t):Math.floor(t),t.tween=(t,a,i)=>n=>z(a,i,t(n)),t.wrap=(t,a,i)=>{if(a===i)return a;if(t>i){const n=i-a;(t-=n)>i&&(t-=n*((t-a)/n|0))}else if(t<a){const n=i-a;(t+=n)<a&&(t+=n*((a-t)/n+1|0))}return t},t.wrap01=t=>t<0?t+1:t>1?t-1:t,t.wrap11=t=>t<-1?t+2:t>1?t-2:t,t.wrapOnce=(t,a,i)=>t<a?t-a+i:t>i?t-i+a:t,t.xori16=(t,a)=>j((0|t)^(0|a)),t.xori32=(t,a)=>(0|t)^(0|a),t.xori8=(t,a)=>V((0|t)^(0|a)),t.xoru16=(t,a)=>(t&L^a&L)&L,t.xoru32=(t,a)=>(t>>>0^a>>>0)>>>0,t.xoru8=(t,a)=>(t&U^a&U)&U,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a(((t="undefined"!=typeof globalThis?globalThis:t||self).thi=t.thi||{},t.thi.ng=t.thi.ng||{},t.thi.ng.math={}))}(this,(function(t){"use strict";const a=Math.PI,i=2*a,n=a/2,e=a/3,s=a/4,r=a/6,o=1/a,h=1/i,u=1/n,c=a/180,M=180/a,l=(1+Math.sqrt(5))/2,d=Math.SQRT2,f=Math.sqrt(3),m=d/2,b=f/2;let p=1e-6;const x=t=>(t%=i)<0?i+t:t,g=t=>(t=Math.abs(t))>a?i-t:t,I=t=>{const a=t*t;return.99940307+a*(.03679168*a-.49558072)},T=t=>{switch((t%=i)<0&&(t=-t),t*u|0){case 0:return I(t);case 1:return-I(a-t);case 2:return-I(t-a);default:return I(i-t)}},v=Math.abs,R=Math.max,q=(t,a,i=p)=>v(t-a)<=i,D=q,P=(t,a,i,n)=>t<i&&a>n,S=(t,a,i,n)=>t>i&&a<n,_=(t,a,i)=>t>a&&a<i,C=(t,a,i)=>t<a&&a>i,w=(t,a,i=0,n=a.length)=>{n--;for(let e=i+1;e<n;e++)if(t(a[e-1],a[e],a[e+1]))return e;return-1},H=(t,a=0,i=t.length)=>w(_,t,a,i);function*y(t,a,i=0,n=a.length){for(;i<n;){const e=t(a,i,n);if(e<0)return;yield e,i=e+1}}const A=t=>t<0?0:t>1?1:t,E=t=>t<-1?-1:t>1?1:t,Q=(t,a)=>0!==t?0!==a?Math.min(t,a):t:a,F=(t,a,i)=>N(t,a,-i),N=(t,a,i)=>{const n=Math.exp(t*i),e=Math.exp(a*i);return(t*n+a*e)/(n+e)},O=(t,a,i)=>i!==a?(t-a)/(i-a):0,U=255,L=65535,V=t=>128&(t&=U)?t|~U:t,j=t=>32768&(t&=L)?t|~L:t,k=(t,a,i,n=16,e=8,s=0,r=1,o=p)=>{if(e<=0)return(s+r)/2;const h=(r-s)/n;let u=s,c=1/0;for(let e=0;e<=n;e++){const n=s+e*h,r=a(i,t(n));if(r<c){if(r<=o)return n;c=r,u=n}}return k(t,a,i,n,e-1,Math.max(u-h,0),Math.min(u+h,1))},z=(t,a,i)=>t+(a-t)*i,B=(t,a,i,n,e)=>{const s=e*e;return e*s*(-.5*t+1.5*a-1.5*i+(n*=.5))+s*(t-2.5*a+2*i-n)+e*(-.5*t+.5*i)+a},G=t=>(t=1-t,Math.sqrt(1-t*t)),X=t=>1-G(1-t),Z=t=>0!==t?Math.sin(t)/t:1,W=(t,a,i)=>i!=t?1/(1+Math.exp(-a*(i-t))):.5,J=t=>t-Math.floor(t),K=(t,a)=>0!==a?t/a:0;t.DEG2RAD=c,t.EPS=p,t.HALF_PI=n,t.INV_HALF_PI=u,t.INV_PI=o,t.INV_TAU=h,t.PHI=l,t.PI=a,t.QUARTER_PI=s,t.RAD2DEG=M,t.SIXTH=1/6,t.SIXTH_PI=r,t.SQRT2=d,t.SQRT2_2=m,t.SQRT2_3=b,t.SQRT3=f,t.TAU=i,t.THIRD=1/3,t.THIRD_PI=e,t.TWO_THIRD=2/3,t.absDiff=(t,a)=>Math.abs(t-a),t.absInnerAngle=g,t.absMax=(t,a)=>Math.abs(t)>Math.abs(a)?t:a,t.absMin=(t,a)=>Math.abs(t)<Math.abs(a)?t:a,t.absTheta=x,t.addi16=(t,a)=>j((0|t)+(0|a)),t.addi32=(t,a)=>(0|t)+(0|a)|0,t.addi8=(t,a)=>V((0|t)+(0|a)),t.addu16=(t,a)=>(t&L)+(a&L)&L,t.addu32=(t,a)=>(t>>>0)+(a>>>0)>>>0,t.addu8=(t,a)=>(t&U)+(a&U)&U,t.andi16=(t,a)=>j((0|t)&(0|a)),t.andi32=(t,a)=>(0|t)&(0|a),t.andi8=(t,a)=>V((0|t)&(0|a)),t.andu16=(t,a)=>t&L&a&L&L,t.andu32=(t,a)=>(t>>>0&a>>>0)>>>0,t.andu8=(t,a)=>t&U&a&U&U,t.angleDist=(t,a)=>g(x(a%i-t%i)),t.atan2Abs=(t,a)=>x(Math.atan2(t,a)),t.bounce=(t,a,i)=>{const e=i*t;return 1-a*Math.sin(e)/e*Math.cos(i*n)},t.ceilTo=(t,a=1)=>Math.ceil(t/a)*a,t.circular=G,t.clamp=(t,a,i)=>t<a?a:t>i?i:t,t.clamp0=t=>t>0?t:0,t.clamp01=A,t.clamp05=t=>t<0?0:t>.5?.5:t,t.clamp11=E,t.classifyCrossing=(t,a,i,n,e=p)=>q(t,i,e)&&q(a,n,e)?q(t,n,e)?"flat":"equal":P(t,a,i,n)?"over":S(t,a,i,n)?"under":"other",t.copysign=(t,a)=>Math.sign(a)*Math.abs(t),t.cosine=t=>1-(.5*Math.cos(t*a)+.5),t.cossin=(t,a=1)=>[Math.cos(t)*a,Math.sin(t)*a],t.cot=t=>1/Math.tan(t),t.csc=t=>1/Math.sin(t),t.cubicPulse=(t,a,i)=>(i=Math.abs(i-a))>t?0:1-(i/=t)*i*(3-2*i),t.decimated=(t,a)=>Math.floor(a*t)/t,t.deg=t=>t*M,t.derivative=(t,a=p)=>i=>(t(i+a)-t(i))/a,t.divi16=(t,a)=>j((0|t)/(0|a)),t.divi32=(t,a)=>(0|t)/(0|a)|0,t.divi8=(t,a)=>V((0|t)/(0|a)),t.divu16=(t,a)=>(t&L)/(a&L)&L,t.divu32=(t,a)=>(t>>>0)/(a>>>0)>>>0,t.divu8=(t,a)=>(t&U)/(a&U)&U,t.ease=(t,a)=>Math.pow(a,t),t.eqDelta=q,t.eqDeltaFixed=D,t.eqDeltaScaled=(t,a,i=p)=>v(t-a)<=i*R(1,v(t),v(a)),t.exp2=t=>2**t,t.expFactor=(t,a,i)=>(a/t)**(1/i),t.expStep=(t,a,i)=>1-Math.exp(-t*Math.pow(i,a)),t.fastCos=T,t.fastSin=t=>T(n-t),t.fdim=(t,a)=>Math.max(t-a,0),t.fit=(t,a,i,n,e)=>n+(e-n)*O(t,a,i),t.fit01=(t,a,i)=>a+(i-a)*A(t),t.fit10=(t,a,i)=>i+(a-i)*A(t),t.fit11=(t,a,i)=>a+(i-a)*(.5+.5*E(t)),t.fitClamped=(t,a,i,n,e)=>n+(e-n)*A(O(t,a,i)),t.floorTo=(t,a=1)=>Math.floor(t/a)*a,t.fma=(t,a,i)=>t*a+i,t.fmod=(t,a)=>t%a,t.foldback=(t,a)=>a<-t||a>t?Math.abs(Math.abs((a-t)%(4*t))-2*t)-t:a,t.fract=J,t.frexp=t=>{if(0===t||!isFinite(t))return[t,0];const a=Math.abs(t);let i=Math.max(-1023,Math.floor(Math.log2(a))+1),n=a*2**-i;for(;n<.5;)n*=2,i--;for(;n>=1;)n*=.5,i++;return[t<0?-n:n,i]},t.gain=(t,a)=>a<.5?.5*Math.pow(2*a,t):1-.5*Math.pow(2-2*a,t),t.gaussian=(t,a,i)=>Math.exp(-((i-t)**2)/(2*a*a)),t.impulse=(t,a)=>{const i=t*a;return i*Math.exp(1-i)},t.inOpenRange=(t,a,i)=>t>a&&t<i,t.inRange=(t,a,i)=>t>=a&&t<=i,t.invCircular=X,t.isCrossOver=P,t.isCrossUnder=S,t.isMaxima=C,t.isMinima=_,t.lanczos=(t,i)=>0!==i?-t<i&&i<t?Z(a*i)*Z(a*i/t):0:1,t.ldexp=(t,a)=>t*2**a,t.lens=(t,a,i)=>{const n=a>0?X:G,e=1-t,s=i<=t?n(i/t)*t:1-n((1-i)/e)*e;return z(i,s,Math.abs(a))},t.loc=(t,a,i)=>Math.sqrt(t*t+a*a-2*t*a*Math.cos(i)),t.lshifti16=(t,a)=>j((0|t)<<(0|a)),t.lshifti32=(t,a)=>(0|t)<<(0|a),t.lshifti8=(t,a)=>V((0|t)<<(0|a)),t.lshiftu16=(t,a)=>(t&L)<<(a&L)&L,t.lshiftu32=(t,a)=>t>>>0<<(a>>>0)>>>0,t.lshiftu8=(t,a)=>(t&U)<<(a&U)&U,t.max2id=(t,a)=>t>=a?0:1,t.max3id=(t,a,i)=>t>=a?t>=i?0:2:a>=i?1:2,t.max4id=(t,a,i,n)=>t>=a?t>=i?t>=n?0:3:i>=n?2:3:a>=i?a>=n?1:3:i>=n?2:3,t.maximaIndex=(t,a=0,i=t.length)=>w(C,t,a,i),t.maximaIndices=(t,a=0,i=t.length)=>y(H,t,a,i),t.min2id=(t,a)=>t<=a?0:1,t.min3id=(t,a,i)=>t<=a?t<=i?0:2:a<=i?1:2,t.min4id=(t,a,i,n)=>t<=a?t<=i?t<=n?0:3:i<=n?2:3:a<=i?a<=n?1:3:i<=n?2:3,t.minError=k,t.minNonZero2=Q,t.minNonZero3=(t,a,i)=>Q(Q(t,a),i),t.minimaIndex=H,t.minimaIndices=(t,a=0,i=t.length)=>y(H,t,a,i),t.mix=z,t.mixBicubic=(t,a,i,n,e,s,r,o,h,u,c,M,l,d,f,m,b,p)=>B(B(t,a,i,n,b),B(e,s,r,o,b),B(h,u,c,M,b),B(l,d,f,m,b),p),t.mixBilinear=(t,a,i,n,e,s)=>{const r=1-e,o=1-s;return t*r*o+a*e*o+i*r*s+n*e*s},t.mixCubic=(t,a,i,n,e)=>{const s=e*e,r=1-e,o=r*r;return t*o*r+3*a*o*e+3*i*s*r+n*s*e},t.mixCubicHermite=(t,a,i,n,e)=>{const s=e-1,r=e*e,o=s*s;return(1+2*e)*o*t+e*o*a+r*(3-2*e)*i+r*s*n},t.mixCubicHermiteFromPoints=B,t.mixHermite=(t,a,i,n,e)=>{const s=.5*(i-t),r=1.5*(a-i)+.5*(n-t);return((r*e+t-a+s-r)*e+s)*e+a},t.mixQuadratic=(t,a,i,n)=>{const e=1-n;return t*e*e+2*a*e*n+i*n*n},t.mod=(t,a)=>t-a*Math.floor(t/a),t.muli16=(t,a)=>j((0|t)*(0|a)),t.muli32=(t,a)=>(0|t)*(0|a)|0,t.muli8=(t,a)=>V((0|t)*(0|a)),t.mulu16=(t,a)=>(t&L)*(a&L)&L,t.mulu32=(t,a)=>(t>>>0)*(a>>>0)>>>0,t.mulu8=(t,a)=>(t&U)*(a&U)&U,t.norm=O,t.normCos=t=>{const a=t*t;return 1+a*(2*a-4)},t.noti16=t=>j(~t),t.noti32=t=>~t,t.noti8=t=>V(~t),t.notu16=t=>~t&L,t.notu32=t=>~t>>>0,t.notu8=t=>~t&U,t.ori16=(t,a)=>j(0|t|a),t.ori32=(t,a)=>0|t|a,t.ori8=(t,a)=>V(0|t|a),t.oru16=(t,a)=>(t&L|a&L)&L,t.oru32=(t,a)=>(t>>>0|a>>>0)>>>0,t.oru8=(t,a)=>(t&U|a&U)&U,t.parabola=(t,a)=>Math.pow(4*a*(1-a),t),t.quadrant=t=>x(t)*u|0,t.rad=t=>t*c,t.remainder=(t,a)=>t-a*Math.round(t/a),t.roundEps=(t,a=p)=>{const i=J(t);return i<=a||i>=1-a?Math.round(t):t},t.roundTo=(t,a=1)=>Math.round(t/a)*a,t.rshifti16=(t,a)=>j((0|t)>>(0|a)),t.rshifti32=(t,a)=>(0|t)>>(0|a),t.rshifti8=(t,a)=>V((0|t)>>(0|a)),t.rshiftu16=(t,a)=>(t&L)>>>(a&L)&L,t.rshiftu32=(t,a)=>t>>>0>>>(a>>>0)>>>0,t.rshiftu8=(t,a)=>(t&U)>>>(a&U)&U,t.safeDiv=K,t.schlick=(t,a,i)=>i<=a?a*i/(i+t*(a-i)+p):(1-a)*(i-1)/(1-i-t*(a-i)+p)+1,t.sclamp=(t,a,i,n)=>F(N(t,a,n),i,n),t.sec=t=>1/Math.cos(t),t.sigmoid=W,t.sigmoid01=(t,a)=>W(.5,t,a),t.sigmoid11=(t,a)=>W(0,t,a),t.sign=(t,a=p)=>t>a?1:t<-a?-1:0,t.signExtend16=j,t.signExtend8=V,t.simplifyRatio=(t,a)=>{let i=Math.abs(t),n=Math.abs(a);for(;;){if(i<n){const t=i;i=n,n=t}const e=i%n;if(!e)return[t/n,a/n];i=e}},t.sinc=Z,t.sincNormalized=(t,i)=>Z(a*t*i),t.sincos=(t,a=1)=>[Math.sin(t)*a,Math.cos(t)*a],t.smax=N,t.smin=F,t.smoothStep=(t,a,i)=>(3-2*(i=A((i-t)/(a-t))))*i*i,t.smootherStep=(t,a,i)=>(i=A((i-t)/(a-t)))*i*i*(i*(6*i-15)+10),t.solveCubic=(t,a,i,n,e=1e-9)=>{const s=t*t,r=a*a,o=a/(3*t),h=(3*t*i-r)/(3*s),u=(2*r*a-9*t*a*i+27*s*n)/(27*s*t);if(Math.abs(h)<e)return[Math.cbrt(-u)-o];if(Math.abs(u)<e)return h<0?[-Math.sqrt(-h)-o,-o,Math.sqrt(-h)-o]:[-o];{const t=u*u/4+h*h*h/27;if(Math.abs(t)<e)return[-1.5*u/h-o,3*u/h-o];if(t>0){const a=Math.cbrt(-u/2-Math.sqrt(t));return[a-h/(3*a)-o]}{const t=2*Math.sqrt(-h/3),a=Math.acos(3*u/h/t)/3,i=2*Math.PI/3;return[t*Math.cos(a)-o,t*Math.cos(a-i)-o,t*Math.cos(a-2*i)-o]}}},t.solveLinear=(t,a)=>K(-a,t),t.solveQuadratic=(t,a,i,n=1e-9)=>{const e=2*t;let s=a*a-4*t*i;return s<0?[]:s<n?[-a/e]:(s=Math.sqrt(s),[(-a-s)/e,(-a+s)/e])},t.step=(t,a)=>a<t?0:1,t.subi16=(t,a)=>j((0|t)-(0|a)),t.subi32=(t,a)=>(0|t)-(0|a)|0,t.subi8=(t,a)=>V((0|t)-(0|a)),t.subu16=(t,a)=>(t&L)-(a&L)&L,t.subu32=(t,a)=>(t>>>0)-(a>>>0)>>>0,t.subu8=(t,a)=>(t&U)-(a&U)&U,t.tangentCardinal=(t,a,i=.5,n=0,e=2)=>i*((a-t)/(e-n)),t.tangentDiff3=(t,a,i,n=0,e=1,s=2)=>.5*((i-a)/(s-e)+(a-t)/(e-n)),t.trunc=t=>t<0?Math.ceil(t):Math.floor(t),t.tween=(t,a,i)=>n=>z(a,i,t(n)),t.wrap=(t,a,i)=>{if(a===i)return a;if(t>i){const n=i-a;(t-=n)>i&&(t-=n*((t-a)/n|0))}else if(t<a){const n=i-a;(t+=n)<a&&(t+=n*((a-t)/n+1|0))}return t},t.wrap01=t=>t<0?t+1:t>1?t-1:t,t.wrap11=t=>t<-1?t+2:t>1?t-2:t,t.wrapOnce=(t,a,i)=>t<a?t-a+i:t>i?t-i+a:t,t.xori16=(t,a)=>j((0|t)^(0|a)),t.xori32=(t,a)=>(0|t)^(0|a),t.xori8=(t,a)=>V((0|t)^(0|a)),t.xoru16=(t,a)=>(t&L^a&L)&L,t.xoru32=(t,a)=>(t>>>0^a>>>0)>>>0,t.xoru8=(t,a)=>(t&U^a&U)&U,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@thi.ng/math",
"version": "3.4.0",
"version": "4.0.0",
"description": "Assorted common math functions & utilities",

@@ -81,3 +81,3 @@ "module": "./index.js",

},
"gitHead": "452a679a1c40e0708ac9007b25a45e209af78e59"
"gitHead": "8fcf77133e53fe5871ea12030b9b079cca315d2d"
}
import type { FnN, FnN2 } from "@thi.ng/api";
/**
* Returns `a - b * floor(a/b)`
* Similar to {@link fmod}, {@link remainder}. Returns `a - b * floor(a / b)`
* (same as GLSL `mod(a, b)`)
*
* @remarks
* **Caution:** Due to the introduction of libc math functions in v4.0.0 and the
* resulting name/behavior clashes between the modulo logic in JS, C & GLSL,
* this function previously _was_ called `fmod`, but going forward has been
* renamed to align w/ its GLSL version and exhibits a different behavior to the
* current {@link fmod} function.
*
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mod.xhtml
*
* @param a -
* @param b -
*/
export declare const fmod: FnN2;
export declare const mod: FnN2;
export declare const fract: FnN;

@@ -10,0 +20,0 @@ export declare const trunc: FnN;

import { EPS } from "./api";
/**
* Returns `a - b * floor(a/b)`
* Similar to {@link fmod}, {@link remainder}. Returns `a - b * floor(a / b)`
* (same as GLSL `mod(a, b)`)
*
* @remarks
* **Caution:** Due to the introduction of libc math functions in v4.0.0 and the
* resulting name/behavior clashes between the modulo logic in JS, C & GLSL,
* this function previously _was_ called `fmod`, but going forward has been
* renamed to align w/ its GLSL version and exhibits a different behavior to the
* current {@link fmod} function.
*
* https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/mod.xhtml
*
* @param a -
* @param b -
*/
export const fmod = (a, b) => a - b * Math.floor(a / b);
export const mod = (a, b) => a - b * Math.floor(a / b);
export const fract = (x) => x - Math.floor(x);

@@ -10,0 +20,0 @@ export const trunc = (x) => (x < 0 ? Math.ceil(x) : Math.floor(x));

@@ -16,2 +16,3 @@ <!-- This file is generated - DO NOT EDIT! -->

- [Status](#status)
- [Breaking changes in v4.0.0](#breaking-changes-in-v400)
- [Installation](#installation)

@@ -41,2 +42,12 @@ - [Dependencies](#dependencies)

### Breaking changes in v4.0.0
The introduction of several [standard libc math
functions](https://www.cplusplus.com/reference/cmath/) causes a behavior change
of the existing `fmod()` function...
- rename `fmod()` => `mod()` to align w/ GLSL counterpart
- add new `fmod()` w/ standard libc behavior (same as JS % op)
- add `remainder()` w/ standard libc behavior
## Installation

@@ -56,3 +67,3 @@

Package sizes (gzipped, pre-treeshake): ESM: 3.71 KB / CJS: 4.30 KB / UMD: 3.54 KB
Package sizes (gzipped, pre-treeshake): ESM: 3.94 KB / CJS: 4.55 KB / UMD: 3.75 KB

@@ -59,0 +70,0 @@ ## Dependencies

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc