pimath 0.0.83 → 0.0.86
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 +8 -7
- 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/numexp.js +1 -0
- package/esm/maths/expressions/numexp.js.map +1 -1
- package/esm/maths/numeric.d.ts +1 -1
- package/esm/maths/numeric.js +7 -7
- package/esm/maths/numeric.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/expressions/numexp.ts +1 -0
- package/src/maths/numeric.ts +8 -12
- package/tests/numeric.test.ts +12 -0
- package/tests/numexp.test.ts +6 -0
package/dist/pi.js
CHANGED
|
@@ -4798,6 +4798,7 @@ class NumExp {
|
|
|
4798
4798
|
}
|
|
4799
4799
|
else if (element.token === '^') {
|
|
4800
4800
|
const b = stack.pop(), a = stack.pop();
|
|
4801
|
+
console.log(a, b);
|
|
4801
4802
|
if (a === undefined || b === undefined) {
|
|
4802
4803
|
this.isValid = false;
|
|
4803
4804
|
}
|
|
@@ -6574,23 +6575,23 @@ class Numeric {
|
|
|
6574
6575
|
}
|
|
6575
6576
|
return triplets;
|
|
6576
6577
|
}
|
|
6577
|
-
static numberCorrection(value) {
|
|
6578
|
+
static numberCorrection(value, epsilonDigit = 1, epsilonNumberOfDigits = 10, number_of_digits = 6) {
|
|
6578
6579
|
// Must modify the number if it's like:
|
|
6579
6580
|
// a: 3.0000000000000003
|
|
6580
6581
|
// b: 3.9999999999999994
|
|
6581
6582
|
// remove the last character
|
|
6582
6583
|
// check if around n last characters are either 0 or 9
|
|
6583
6584
|
// if it is, 'round' the number.
|
|
6584
|
-
function extractDecimalPart(valueToExtract) {
|
|
6585
|
+
function extractDecimalPart(valueToExtract, decimalLength) {
|
|
6585
6586
|
let decimal = valueToExtract.toString();
|
|
6586
6587
|
if (!decimal.includes('.')) {
|
|
6587
6588
|
return '';
|
|
6588
6589
|
}
|
|
6589
6590
|
decimal = decimal.split('.')[1];
|
|
6590
|
-
return decimal.substring(0,
|
|
6591
|
+
return decimal.substring(0, decimalLength);
|
|
6591
6592
|
}
|
|
6592
|
-
const epsilon = 0.
|
|
6593
|
-
const decimal = extractDecimalPart(value);
|
|
6593
|
+
const epsilon = Number(`0.${"0".repeat(epsilonNumberOfDigits - 1)}${epsilonDigit}`);
|
|
6594
|
+
const decimal = extractDecimalPart(value, epsilonNumberOfDigits);
|
|
6594
6595
|
if (decimal === '') {
|
|
6595
6596
|
return value;
|
|
6596
6597
|
}
|
|
@@ -6598,7 +6599,7 @@ class Numeric {
|
|
|
6598
6599
|
const n0 = decimal.match(/0+$/g);
|
|
6599
6600
|
if (n9 && n9[0].length >= number_of_digits) {
|
|
6600
6601
|
// New tested values.
|
|
6601
|
-
const mod = extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
|
|
6602
|
+
const mod = extractDecimalPart(value + epsilon, epsilonNumberOfDigits), mod0 = mod.match(/0+$/g);
|
|
6602
6603
|
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
6603
6604
|
// The value can be changed. Remove all zeros!
|
|
6604
6605
|
return +((value + epsilon).toString().split(mod0[0])[0]);
|
|
@@ -6606,7 +6607,7 @@ class Numeric {
|
|
|
6606
6607
|
}
|
|
6607
6608
|
if (n0 && n0[0].length >= number_of_digits) {
|
|
6608
6609
|
// New tested values.
|
|
6609
|
-
const mod = extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
|
|
6610
|
+
const mod = extractDecimalPart(value - epsilon, epsilonNumberOfDigits), mod9 = mod.match(/9+$/g);
|
|
6610
6611
|
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
6611
6612
|
// The value can be changed. Remove all nines!
|
|
6612
6613
|
return +(value.toString().split(n0[0])[0]);
|