pimath 0.0.89 → 0.0.90

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
@@ -475,70 +475,85 @@ class Equation {
475
475
  // -b +- coeff\sqrt{radical}
476
476
  // -------------------------
477
477
  // 2a
478
- let gcd = numeric_1.Numeric.gcd(b, 2 * a, nthDelta.coefficient);
478
+ let gcd = numeric_1.Numeric.gcd(b, 2 * a, nthDelta.coefficient), am = a / gcd, bm = b / gcd;
479
479
  nthDelta.coefficient = nthDelta.coefficient / gcd;
480
- // TODO: Can i delete the next line ?
481
- // let deltaC = nthDelta.coefficient, deltaR = nthDelta.radical;
482
- if (b !== 0) {
483
- if (2 * a / gcd === 1) {
484
- this._solutions = [
485
- {
486
- tex: `${-b / gcd} - ${nthDelta.tex}`,
487
- value: realX1,
488
- exact: false // TODO: implement exact value with nthroot
489
- },
490
- {
491
- tex: `${-b / gcd} + ${nthDelta.tex}`,
492
- value: realX2,
493
- exact: false
494
- },
495
- ];
496
- }
497
- else {
498
- this._solutions = [
499
- {
500
- tex: `\\frac{${-b / gcd} - ${nthDelta.tex} }{ ${2 * a / gcd} }`,
501
- value: realX1,
502
- exact: false
503
- },
504
- {
505
- tex: `\\frac{${-b / gcd} + ${nthDelta.tex} }{ ${2 * a / gcd} }`,
506
- value: realX2,
507
- exact: false
508
- },
509
- ];
510
- }
480
+ if (a < 0) {
481
+ am = -am;
482
+ bm = -bm;
511
483
  }
512
- else {
513
- if (2 * a / gcd === 1) {
514
- this._solutions = [
515
- {
516
- tex: `- ${nthDelta.tex}`,
517
- value: realX1,
518
- exact: false
519
- },
520
- {
521
- tex: `${nthDelta.tex}`,
522
- value: realX2,
523
- exact: false
524
- },
525
- ];
526
- }
527
- else {
528
- this._solutions = [
529
- {
530
- tex: `\\frac{- ${nthDelta.tex} }{ ${2 * a / gcd} }`,
531
- value: realX1,
532
- exact: false
533
- },
534
- {
535
- tex: `\\frac{${nthDelta.tex} }{ ${2 * a / gcd} }`,
536
- value: realX2,
537
- exact: false
538
- },
539
- ];
540
- }
484
+ let tex1 = "", tex2 = "";
485
+ tex1 = `${bm !== 0 ? ((-bm) + ' - ') : ''}${nthDelta.tex}`;
486
+ tex2 = `${bm !== 0 ? ((-bm) + ' + ') : ''}${nthDelta.tex}`;
487
+ if (am !== 1) {
488
+ tex1 = `\\frac{ ${tex1} }{ ${2 * am} }`;
489
+ tex2 = `\\frac{ ${tex2} }{ ${2 * am} }`;
541
490
  }
491
+ this._solutions = [
492
+ {
493
+ tex: tex1, value: realX1, exact: false
494
+ },
495
+ {
496
+ tex: tex2, value: realX2, exact: false
497
+ },
498
+ ];
499
+ // if (b !== 0) {
500
+ // if (2 * a / gcd === 1) {
501
+ // this._solutions = [
502
+ // {
503
+ // tex: `${-b / gcd} - ${nthDelta.tex}`,
504
+ // value: realX1,
505
+ // exact: false // TODO: implement exact value with nthroot
506
+ // },
507
+ // {
508
+ // tex: `${-b / gcd} + ${nthDelta.tex}`,
509
+ // value: realX2,
510
+ // exact: false
511
+ // },
512
+ //
513
+ // ]
514
+ // } else {
515
+ // this._solutions = [
516
+ // {
517
+ // tex: `\\frac{${-b / gcd} - ${nthDelta.tex} }{ ${2 * a / gcd} }`,
518
+ // value: realX1,
519
+ // exact: false
520
+ // },
521
+ // {
522
+ // tex: `\\frac{${-b / gcd} + ${nthDelta.tex} }{ ${2 * a / gcd} }`,
523
+ // value: realX2,
524
+ // exact: false
525
+ // },
526
+ // ]
527
+ // }
528
+ // } else {
529
+ // if (2 * a / gcd === 1) {
530
+ // this._solutions = [
531
+ // {
532
+ // tex: `- ${nthDelta.tex}`,
533
+ // value: realX1,
534
+ // exact: false
535
+ // },
536
+ // {
537
+ // tex: `${nthDelta.tex}`,
538
+ // value: realX2,
539
+ // exact: false
540
+ // },
541
+ // ]
542
+ // } else {
543
+ // this._solutions = [
544
+ // {
545
+ // tex: `\\frac{- ${nthDelta.tex} }{ ${2 * a / gcd} }`,
546
+ // value: realX1,
547
+ // exact: false
548
+ // },
549
+ // {
550
+ // tex: `\\frac{${nthDelta.tex} }{ ${2 * a / gcd} }`,
551
+ // value: realX2,
552
+ // exact: false
553
+ // },
554
+ // ]
555
+ // }
556
+ // }
542
557
  }
543
558
  else {
544
559
  // -b +- d / 2a
@@ -4113,7 +4128,7 @@ class Fraction {
4113
4128
  // The given value is a float number
4114
4129
  // Get the number of decimals after the float sign
4115
4130
  let [unit, decimal] = (value.toString()).split('.');
4116
- let p = decimal.length;
4131
+ let p = decimal ? decimal.length : 0;
4117
4132
  // Detect if the decimal part is periodic or not...
4118
4133
  // Transform the float number in two integer
4119
4134
  if (denominatorOrPeriodic === undefined) {
@@ -6559,6 +6574,10 @@ class Numeric {
6559
6574
  }
6560
6575
  return Math.abs(g);
6561
6576
  }
6577
+ static divideNumbersByGCD(...values) {
6578
+ let gcd = Numeric.gcd(...values);
6579
+ return values.map(x => x / gcd);
6580
+ }
6562
6581
  /**
6563
6582
  * Least Common Multiple
6564
6583
  * @param values: list of numbers
@@ -6606,7 +6625,6 @@ class Numeric {
6606
6625
  // New tested values.
6607
6626
  const mod = extractDecimalPart(value + epsilon, epsilonNumberOfDigits), mod0 = mod.match(/0+$/g);
6608
6627
  if (mod0 && mod0[0].length >= number_of_digits) {
6609
- // The value can be changed. Remove all zeros!
6610
6628
  return +((value + epsilon).toString().split(mod0[0])[0]);
6611
6629
  }
6612
6630
  }
@@ -6765,7 +6783,11 @@ class rndFraction extends randomCore_1.randomCore {
6765
6783
  Q.denominator = 1;
6766
6784
  }
6767
6785
  else {
6768
- Q.denominator = random_1.Random.number(1, this._config.max);
6786
+ let securityCount = 0;
6787
+ while (Q.isRelative() && securityCount < 10) {
6788
+ Q.denominator = random_1.Random.number(1, this._config.max);
6789
+ securityCount++;
6790
+ }
6769
6791
  }
6770
6792
  return this._config.reduced ? Q.reduce() : Q;
6771
6793
  };