pimath 0.0.89 → 0.0.91

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/.idea/php.xml CHANGED
@@ -1,4 +1,19 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
+ <component name="MessDetectorOptionsConfiguration">
4
+ <option name="transferred" value="true" />
5
+ </component>
6
+ <component name="PHPCSFixerOptionsConfiguration">
7
+ <option name="transferred" value="true" />
8
+ </component>
9
+ <component name="PHPCodeSnifferOptionsConfiguration">
10
+ <option name="transferred" value="true" />
11
+ </component>
3
12
  <component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
13
+ <component name="PhpStanOptionsConfiguration">
14
+ <option name="transferred" value="true" />
15
+ </component>
16
+ <component name="PsalmOptionsConfiguration">
17
+ <option name="transferred" value="true" />
18
+ </component>
4
19
  </project>
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) {
@@ -5719,6 +5734,21 @@ class Line {
5719
5734
  parametric: `${point_1.Point.pmatrix('x', 'y')} = ${point_1.Point.pmatrix(this._OA.x, this._OA.y)} + k\\cdot ${point_1.Point.pmatrix(this._d.x, this._d.y)}`
5720
5735
  };
5721
5736
  }
5737
+ get display() {
5738
+ // canonical => ax + by + c = 0
5739
+ // mxh => y = -a/b x - c/b
5740
+ // parametric => (xy) = OA + k*d // not relevant in display mode.
5741
+ let canonical = this.equation;
5742
+ // Make sur the first item is positive.
5743
+ if (this._a.isNegative()) {
5744
+ canonical.multiply(-1);
5745
+ }
5746
+ return {
5747
+ canonical: canonical.display,
5748
+ mxh: this.slope.isInfinity() ? 'x=' + this.OA.x.display : 'y=' + new polynom_1.Polynom().parse('x', this.slope, this.height).display,
5749
+ parametric: ""
5750
+ };
5751
+ }
5722
5752
  get a() {
5723
5753
  return this._a;
5724
5754
  }
@@ -6559,6 +6589,10 @@ class Numeric {
6559
6589
  }
6560
6590
  return Math.abs(g);
6561
6591
  }
6592
+ static divideNumbersByGCD(...values) {
6593
+ let gcd = Numeric.gcd(...values);
6594
+ return values.map(x => x / gcd);
6595
+ }
6562
6596
  /**
6563
6597
  * Least Common Multiple
6564
6598
  * @param values: list of numbers
@@ -6606,7 +6640,6 @@ class Numeric {
6606
6640
  // New tested values.
6607
6641
  const mod = extractDecimalPart(value + epsilon, epsilonNumberOfDigits), mod0 = mod.match(/0+$/g);
6608
6642
  if (mod0 && mod0[0].length >= number_of_digits) {
6609
- // The value can be changed. Remove all zeros!
6610
6643
  return +((value + epsilon).toString().split(mod0[0])[0]);
6611
6644
  }
6612
6645
  }
@@ -6765,7 +6798,11 @@ class rndFraction extends randomCore_1.randomCore {
6765
6798
  Q.denominator = 1;
6766
6799
  }
6767
6800
  else {
6768
- Q.denominator = random_1.Random.number(1, this._config.max);
6801
+ let securityCount = 0;
6802
+ while (Q.isRelative() && securityCount < 10) {
6803
+ Q.denominator = random_1.Random.number(1, this._config.max);
6804
+ securityCount++;
6805
+ }
6769
6806
  }
6770
6807
  return this._config.reduced ? Q.reduce() : Q;
6771
6808
  };