10 examples of 'multiply in javascript' in JavaScript

Every line of 'multiply in javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
3function multiply(a, b) {
4 return a * b;
5}
42export function multiply(a, b) {
43 const a00 = a[0], a01 = a[1], a02 = a[2];
44 const a10 = a[3], a11 = a[4], a12 = a[5];
45 const a20 = a[6], a21 = a[7], a22 = a[8];
46
47 const b00 = b[0], b01 = b[1], b02 = b[2];
48 const b10 = b[3], b11 = b[4], b12 = b[5];
49 const b20 = b[6], b21 = b[7], b22 = b[8];
50
51 a[0] = b00 * a00 + b01 * a10 + b02 * a20;
52 a[1] = b00 * a01 + b01 * a11 + b02 * a21;
53 a[2] = b00 * a02 + b01 * a12 + b02 * a22;
54
55 a[3] = b10 * a00 + b11 * a10 + b12 * a20;
56 a[4] = b10 * a01 + b11 * a11 + b12 * a21;
57 a[5] = b10 * a02 + b11 * a12 + b12 * a22;
58
59 a[6] = b20 * a00 + b21 * a10 + b22 * a20;
60 a[7] = b20 * a01 + b21 * a11 + b22 * a21;
61 a[8] = b20 * a02 + b21 * a12 + b22 * a22;
62
63 return a;
64}
12function multiply (a: [ number, number ], b: [ number, number ]): [ number, number ] {
13 return [ ((a[0] * b[0]) - (a[1] * b[1])), ((a[0] * b[1]) + (a[1] * b[0])) ];
14}
41export function multiply(a, b) {
42 return [
43 a[0] * b[0] + a[1] * b[3] + a[2] * b[6],
44 a[0] * b[1] + a[1] * b[4] + a[2] * b[7],
45 a[0] * b[2] + a[1] * b[5] + a[2] * b[8],
46 a[3] * b[0] + a[4] * b[3] + a[5] * b[6],
47 a[3] * b[1] + a[4] * b[4] + a[5] * b[7],
48 a[3] * b[2] + a[4] * b[5] + a[5] * b[8],
49 a[6] * b[0] + a[7] * b[3] + a[8] * b[6],
50 a[6] * b[1] + a[7] * b[4] + a[8] * b[7],
51 a[6] * b[2] + a[7] * b[5] + a[8] * b[8]
52 ];
53}
46function multiply( C, A, B ){
47 var i=0,j=0,k=0;
48 var Ap=0,pA=0,pB=0,p_B=0,Cp=0;
49 var ncols=A.cols,nrows=A.rows,mcols=B.cols;
50 var ad=A.data,bd=B.data,cd=C.data;
51 var sum=0.0;
52
53 for (; i < nrows; Ap += ncols, i++) {
54 for (p_B = 0, j = 0; j < mcols; Cp++, p_B++, j++) {
55 pB = p_B;
56 pA = Ap;
57 sum = 0.0;
58 for (k = 0; k < ncols; pA++, pB += mcols, k++) {
59 sum += ad[pA] * bd[pB];
60 }
61 cd[Cp] = sum;
62 }
63 }
64}
44export function multiply (C: Matrix, A: Matrix, B: Matrix) {
45 let i = 0
46 let j = 0
47 let k = 0
48 let Ap = 0
49 let pA = 0
50 let pB = 0
51 let _pB = 0
52 let Cp = 0
53 const ncols = A.cols
54 const nrows = A.rows
55 const mcols = B.cols
56 const ad = A.data
57 const bd = B.data
58 const cd = C.data
59 let sum = 0.0
60
61 for (; i < nrows; Ap += ncols, i++) {
62 for (_pB = 0, j = 0; j < mcols; Cp++, _pB++, j++) {
63 pB = _pB
64 pA = Ap
65 sum = 0.0
66 for (k = 0; k < ncols; pA++, pB += mcols, k++) {
67 sum += ad[pA] * bd[pB]
68 }
69 cd[Cp] = sum
70 }
71 }
72}
1091function multiply(out, a, b) {
1092 var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
1093 a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
1094 a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
1095 a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
1096
1097 // Cache only the current line of the second matrix
1098 var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
1099 out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
1100 out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
1101 out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
1102 out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
1103
1104 b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
1105 out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
1106 out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
1107 out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
1108 out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
1109
1110 b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
1111 out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
1112 out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
1113 out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
1114 out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
1115
1116 b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
1117 out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
1118 out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
1119 out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
1120 out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
1121 return out;
1122};
26export function multiply(
27 a: Vector,
28 b: Vector | number
29): Vector | number {
30 return math.multiply(a, b) as Vector | number;
31}
3function mult (num) {
4 return num + dep4.multiplier;
5}
9function multiply(a, b) {
10 return (a * b) || 0;
11}

Related snippets