fable 3.1.43 → 3.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.1.43",
3
+ "version": "3.1.45",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -142,7 +142,7 @@ class FableServiceMath extends libFableServiceBase
142
142
  */
143
143
  roundPrecise(pValue, pDecimals, pRoundingMethod)
144
144
  {
145
- let tmpValue = isNaN(pValue) ? 0 : pValue;
145
+ let tmpValue = pValue === false || isNaN(pValue) ? 0 : pValue;
146
146
  let tmpDecimals = isNaN(pDecimals) ? 0 : parseInt(pDecimals, 10);
147
147
  let tmpRoundingMethod = (typeof (pRoundingMethod) === 'undefined') ? this.roundHalfUp : parseInt(pRoundingMethod, 10);
148
148
 
@@ -161,7 +161,7 @@ class FableServiceMath extends libFableServiceBase
161
161
  */
162
162
  toFixedPrecise(pValue, pDecimals, pRoundingMethod)
163
163
  {
164
- let tmpValue = isNaN(pValue) ? 0 : pValue;
164
+ let tmpValue = pValue === false || isNaN(pValue) ? 0 : pValue;
165
165
  let tmpDecimals = isNaN(pDecimals) ? 0 : parseInt(pDecimals, 10);
166
166
  let tmpRoundingMethod = (typeof (pRoundingMethod) === 'undefined') ? this.roundHalfUp : pRoundingMethod;
167
167
 
@@ -1550,17 +1550,18 @@ class FableServiceMath extends libFableServiceBase
1550
1550
  * Compute least squares regression coefficients for multivariable linear interpolation.
1551
1551
  *
1552
1552
  * @param {Array<Array<number|string>> | Array<number|string> | string} pIndependentVariableVectors - array of arrays [[x11, x12, ...], [x21, x22, ...], ...] or single array for single variable.
1553
- * @param {Array<number|string>} pDependentVariableVector - array of target values [y1, y2, ...]
1553
+ * @param {Array<number|string>|string} pDependentVariableVector - array of target values [y1, y2, ...]
1554
1554
  *
1555
1555
  * @return {Array<number|string>} - linear coefficients [b0, b1, ..., bn] where y = b0 + b1*x1 + b2*x2 + ... + bn*xn
1556
1556
  */
1557
1557
  leastSquares(pIndependentVariableVectors, pDependentVariableVector)
1558
1558
  {
1559
1559
  const tmpIndependentVariableVectors = Array.isArray(pIndependentVariableVectors) ? (Array.isArray(pIndependentVariableVectors[0]) ? this.matrixTranspose(pIndependentVariableVectors) : pIndependentVariableVectors.map(value => [value])) : [ [ pIndependentVariableVectors ] ];
1560
+ const tmpDependentVariableVector = Array.isArray(pDependentVariableVector) ? pDependentVariableVector : [ pDependentVariableVector ];
1560
1561
  if (tmpIndependentVariableVectors.length === 1)
1561
1562
  {
1562
1563
  // degenerate case: only one independent variable value, result is just a y-intercept
1563
- return [ pDependentVariableVector[0], '0.0' ];
1564
+ return [ tmpDependentVariableVector[0], '0.0' ];
1564
1565
  }
1565
1566
  // Add bias term (intercept)
1566
1567
  const tmpIndependentVariableMatrixWithBiasTerm = tmpIndependentVariableVectors.map(row => [1, ...row]);
@@ -1570,7 +1571,7 @@ class FableServiceMath extends libFableServiceBase
1570
1571
  const tmpDependentTransposeMultiplication = this.matrixMultiply(tmpIndependentTermTranpose, tmpIndependentVariableMatrixWithBiasTerm);
1571
1572
 
1572
1573
  // Compute X^T * y
1573
- const tmpIndependentTransposeMultiplication = this.matrixVectorMultiply(tmpIndependentTermTranpose, pDependentVariableVector);
1574
+ const tmpIndependentTransposeMultiplication = this.matrixVectorMultiply(tmpIndependentTermTranpose, tmpDependentVariableVector);
1574
1575
 
1575
1576
  // Solve (XtX) * beta = Xty
1576
1577
  const tmpLinearCoefficients = this.gaussianElimination(tmpDependentTransposeMultiplication, tmpIndependentTransposeMultiplication);
package/test/Math_test.js CHANGED
@@ -284,6 +284,7 @@ suite
284
284
  Expect(testFable.Math.roundPrecise(1.123456789, 14)).to.equal('1.123456789');
285
285
 
286
286
  Expect(testFable.Math.roundPrecise(undefined, 2)).to.equal('0');
287
+ Expect(testFable.Math.roundPrecise(false, 2)).to.equal('0');
287
288
 
288
289
  try
289
290
  {
@@ -369,6 +370,7 @@ suite
369
370
  Expect(testFable.Math.toFixedPrecise(1.123456789, 14)).to.equal('1.12345678900000');
370
371
 
371
372
  Expect(testFable.Math.toFixedPrecise(undefined, 2)).to.equal('0.00');
373
+ Expect(testFable.Math.toFixedPrecise(false, 2)).to.equal('0.00');
372
374
 
373
375
  try
374
376
  {