pimath 0.0.27 → 0.0.28

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/dev/index.html CHANGED
@@ -36,9 +36,12 @@
36
36
  <!--</div>-->
37
37
 
38
38
  <script>
39
- let ne = new Pi.NumExp('x^2-2*x+3*y-8')
39
+ // let ne = new Pi.NumExp('5/x*sin(x*x)')
40
+ let ne = new Pi.NumExp('x+3')
40
41
 
41
- console.log(ne.evaluate({x: 5, y: 3}))
42
+ console.log(5.000000000000004)
43
+ console.log(ne.evaluate({x: 5.000000000000004}))
44
+ console.log(ne.evaluate({x: 5.000000000000}))
42
45
 
43
46
  function dev () {
44
47
  let output = []
package/dev/pi.js CHANGED
@@ -4254,6 +4254,12 @@ class NumExp {
4254
4254
  this._expression = value;
4255
4255
  this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
4256
4256
  }
4257
+ get rpn() {
4258
+ return this._rpn;
4259
+ }
4260
+ get expression() {
4261
+ return this._expression;
4262
+ }
4257
4263
  _extractDecimalPart(value) {
4258
4264
  let decimal = value.toString();
4259
4265
  if (!decimal.includes('.')) {
@@ -4263,20 +4269,23 @@ class NumExp {
4263
4269
  return decimal.substring(0, decimal.length - 2);
4264
4270
  }
4265
4271
  _numberCorrection(value) {
4266
- const omega = 0.00000000000001, number_of_digits = 6;
4272
+ const epsilon = 0.00000000000001, number_of_digits = 6;
4267
4273
  let decimal = this._extractDecimalPart(value);
4274
+ if (decimal === '') {
4275
+ return value;
4276
+ }
4268
4277
  const n9 = decimal.match(/9+$/g);
4269
4278
  const n0 = decimal.match(/0+$/g);
4270
4279
  if (n9 && n9[0].length >= number_of_digits) {
4271
- let mod = this._extractDecimalPart(value + omega), mod0 = mod.match(/0+$/g);
4280
+ let mod = this._extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
4272
4281
  if (mod0 && mod0[0].length >= number_of_digits) {
4273
- return +((value + omega).toString().split(mod0[0])[0]);
4282
+ return +((value + epsilon).toString().split(mod0[0])[0]);
4274
4283
  }
4275
4284
  }
4276
4285
  if (n0 && n0[0].length >= number_of_digits) {
4277
- let mod = this._extractDecimalPart(value - omega), mod9 = mod.match(/9+$/g);
4286
+ let mod = this._extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
4278
4287
  if (mod9 && mod9[0].length >= number_of_digits) {
4279
- return +((value - omega).toString().split(mod9[0])[0]);
4288
+ return +(value.toString().split(n0[0])[0]);
4280
4289
  }
4281
4290
  }
4282
4291
  return value;