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