pimath 0.0.84 → 0.0.87

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 CHANGED
@@ -6574,22 +6574,23 @@ class Numeric {
6574
6574
  }
6575
6575
  return triplets;
6576
6576
  }
6577
- static numberCorrection(value, epsilon = 0.00000000000005, number_of_digits = 6) {
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, decimal.length - 2);
6590
+ return decimal.substring(0, decimalLength);
6591
6591
  }
6592
- const decimal = extractDecimalPart(value);
6592
+ const epsilon = Number(`0.${"0".repeat(epsilonNumberOfDigits - 1)}${epsilonDigit}`);
6593
+ const decimal = extractDecimalPart(value, epsilonNumberOfDigits);
6593
6594
  if (decimal === '') {
6594
6595
  return value;
6595
6596
  }
@@ -6597,7 +6598,7 @@ class Numeric {
6597
6598
  const n0 = decimal.match(/0+$/g);
6598
6599
  if (n9 && n9[0].length >= number_of_digits) {
6599
6600
  // New tested values.
6600
- const mod = extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
6601
+ const mod = extractDecimalPart(value + epsilon, epsilonNumberOfDigits), mod0 = mod.match(/0+$/g);
6601
6602
  if (mod0 && mod0[0].length >= number_of_digits) {
6602
6603
  // The value can be changed. Remove all zeros!
6603
6604
  return +((value + epsilon).toString().split(mod0[0])[0]);
@@ -6605,7 +6606,7 @@ class Numeric {
6605
6606
  }
6606
6607
  if (n0 && n0[0].length >= number_of_digits) {
6607
6608
  // New tested values.
6608
- const mod = extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
6609
+ const mod = extractDecimalPart(value - epsilon, epsilonNumberOfDigits), mod9 = mod.match(/9+$/g);
6609
6610
  if (mod9 && mod9[0].length >= number_of_digits) {
6610
6611
  // The value can be changed. Remove all nines!
6611
6612
  return +(value.toString().split(n0[0])[0]);