@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4
4
} ;
5
5
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
6
- exports . math = exports . roundCustom = exports . RoundingMethod = void 0 ;
6
+ exports . math = exports . roundCustom = exports . RoundingMethodEnum = void 0 ;
7
7
exports . numberToPrecision = numberToPrecision ;
8
8
/* eslint-disable */
9
9
const mathjs_1 = __importDefault ( require ( "mathjs" ) ) ;
@@ -20,7 +20,10 @@ const EPSILON = 1e-8;
20
20
* @param v2 Vector 2
21
21
*/
22
22
const product = ( v1 , v2 ) => {
23
- return exports . math . multiply ( v1 , exports . math . transpose ( v2 ) ) ;
23
+ if ( v1 . length !== v2 . length ) {
24
+ throw new Error ( "Vectors must be of the same length" ) ;
25
+ }
26
+ return Number ( exports . math . multiply ( v1 , exports . math . transpose ( v2 ) ) ) ;
24
27
} ;
25
28
/**
26
29
* @summary Returns length of a vector.
@@ -171,22 +174,22 @@ const roundValueToNDecimals = (value, decimals = 3) => {
171
174
return parseFloat ( value . toFixed ( decimals ) ) ;
172
175
} ;
173
176
// See: https://en.wikipedia.org/wiki/Rounding
174
- var RoundingMethod ;
175
- ( function ( RoundingMethod ) {
176
- RoundingMethod [ "Bankers" ] = "bankers" ;
177
- RoundingMethod [ "HalfAwayFromZero" ] = "halfAwayFromZero" ;
178
- } ) ( RoundingMethod || ( exports . RoundingMethod = RoundingMethod = { } ) ) ;
179
- const roundCustom = ( value , decimals = 0 , method = RoundingMethod . HalfAwayFromZero ) => {
177
+ var RoundingMethodEnum ;
178
+ ( function ( RoundingMethodEnum ) {
179
+ RoundingMethodEnum [ "Bankers" ] = "bankers" ;
180
+ RoundingMethodEnum [ "HalfAwayFromZero" ] = "halfAwayFromZero" ;
181
+ } ) ( RoundingMethodEnum || ( exports . RoundingMethodEnum = RoundingMethodEnum = { } ) ) ;
182
+ const roundCustom = ( value , decimals = 0 , method = RoundingMethodEnum . HalfAwayFromZero ) => {
180
183
const factor = Math . pow ( 10 , decimals ) ;
181
184
const scaledValue = value * factor ;
182
185
const absValue = Math . abs ( scaledValue ) ;
183
186
const sign = scaledValue < 0 ? - 1 : 1 ;
184
187
let roundedAbs ;
185
188
switch ( method ) {
186
- case RoundingMethod . HalfAwayFromZero :
189
+ case RoundingMethodEnum . HalfAwayFromZero :
187
190
roundedAbs = Math . round ( absValue ) ;
188
191
break ;
189
- case RoundingMethod . Bankers :
192
+ case RoundingMethodEnum . Bankers :
190
193
const floorValue = Math . floor ( absValue ) ;
191
194
const fractional = absValue - floorValue ;
192
195
if ( Math . abs ( fractional - 0.5 ) < Number . EPSILON ) {
@@ -261,5 +264,5 @@ exports.math = {
261
264
roundValueToNDecimals,
262
265
numberToPrecision,
263
266
roundCustom : exports . roundCustom ,
264
- RoundingMethod,
267
+ RoundingMethod : RoundingMethodEnum ,
265
268
} ;
0 commit comments