pimath 0.0.76 → 0.0.77
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/dist/pi.js +40 -0
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/esm/maths/expressions/ExpressionTree.d.ts +17 -0
- package/esm/maths/expressions/ExpressionTree.js +150 -0
- package/esm/maths/expressions/ExpressionTree.js.map +1 -0
- package/esm/maths/numeric.d.ts +1 -0
- package/esm/maths/numeric.js +40 -0
- package/esm/maths/numeric.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/expressions/ExpressionTree.ts +172 -0
- package/src/maths/numeric.ts +55 -0
- package/tests/expressions/expressiontree.test.ts +11 -0
- package/tests/numexp.test.ts +5 -4
package/dist/pi.js
CHANGED
|
@@ -6523,6 +6523,46 @@ class Numeric {
|
|
|
6523
6523
|
}
|
|
6524
6524
|
return triplets;
|
|
6525
6525
|
}
|
|
6526
|
+
static numberCorrection(value) {
|
|
6527
|
+
// Must modify the number if it's like:
|
|
6528
|
+
// a: 3.0000000000000003
|
|
6529
|
+
// b: 3.9999999999999994
|
|
6530
|
+
// remove the last character
|
|
6531
|
+
// check if around n last characters are either 0 or 9
|
|
6532
|
+
// if it is, 'round' the number.
|
|
6533
|
+
function extractDecimalPart(valueToExtract) {
|
|
6534
|
+
let decimal = valueToExtract.toString();
|
|
6535
|
+
if (!decimal.includes('.')) {
|
|
6536
|
+
return '';
|
|
6537
|
+
}
|
|
6538
|
+
decimal = decimal.split('.')[1];
|
|
6539
|
+
return decimal.substring(0, decimal.length - 2);
|
|
6540
|
+
}
|
|
6541
|
+
const epsilon = 0.00000000000001, number_of_digits = 6;
|
|
6542
|
+
const decimal = extractDecimalPart(value);
|
|
6543
|
+
if (decimal === '') {
|
|
6544
|
+
return value;
|
|
6545
|
+
}
|
|
6546
|
+
const n9 = decimal.match(/9+$/g);
|
|
6547
|
+
const n0 = decimal.match(/0+$/g);
|
|
6548
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
6549
|
+
// New tested values.
|
|
6550
|
+
const mod = extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
|
|
6551
|
+
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
6552
|
+
// The value can be changed. Remove all zeros!
|
|
6553
|
+
return +((value + epsilon).toString().split(mod0[0])[0]);
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
6557
|
+
// New tested values.
|
|
6558
|
+
const mod = extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
|
|
6559
|
+
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
6560
|
+
// The value can be changed. Remove all nines!
|
|
6561
|
+
return +(value.toString().split(n0[0])[0]);
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6564
|
+
return value;
|
|
6565
|
+
}
|
|
6526
6566
|
}
|
|
6527
6567
|
exports.Numeric = Numeric;
|
|
6528
6568
|
|