@abaplint/runtime 2.13.90 → 2.13.92

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.
@@ -16,14 +16,13 @@ function div(left, right) {
16
16
  (0, throw_error_1.throwError)("CX_SY_ZERODIVIDE");
17
17
  }
18
18
  }
19
+ // DIV leaves a remainder that is never negative, 0 <= l - r * div < |r|,
20
+ // so a truncated quotient moves down for a positive divisor and up for
21
+ // a negative one: 7 DIV -2 = -3, -7 DIV -2 = 4
19
22
  const remainder = l % r;
20
23
  let div = l / r;
21
- if (remainder !== 0n) {
22
- const sign1 = l < 0n;
23
- const sign2 = r < 0n;
24
- if (sign1 !== sign2) {
25
- div = div - 1n;
26
- }
24
+ if (remainder < 0n) {
25
+ div = r > 0n ? div - 1n : div + 1n;
27
26
  }
28
27
  return new types_1.Integer8().set(div);
29
28
  }
@@ -38,7 +37,9 @@ function div(left, right) {
38
37
  }
39
38
  }
40
39
  else {
41
- return new types_1.Integer().set(Math.floor(l / r));
40
+ // floor only for a positive divisor; for a negative one the quotient
41
+ // rounds up, so that the remainder a - b * ( a DIV b ) is not negative
42
+ return new types_1.Integer().set(r > 0 ? Math.floor(l / r) : -Math.floor(l / -r));
42
43
  }
43
44
  }
44
45
  //# sourceMappingURL=div.js.map
@@ -16,9 +16,12 @@ function mod(left, right) {
16
16
  (0, throw_error_1.throwError)("CX_SY_ZERODIVIDE");
17
17
  }
18
18
  }
19
- let val = ((l % r) + r) % r;
20
- if (val < 0) {
21
- val = val * -1n;
19
+ // the remainder is never negative and below |r|, whatever the signs:
20
+ // 7 MOD -3 = 1, -7 MOD -3 = 2
21
+ const a = r < 0n ? -r : r;
22
+ let val = l % a;
23
+ if (val < 0n) {
24
+ val = val + a;
22
25
  }
23
26
  return new types_1.Integer8().set(val);
24
27
  }
@@ -32,9 +35,14 @@ function mod(left, right) {
32
35
  (0, throw_error_1.throwError)("CX_SY_ZERODIVIDE");
33
36
  }
34
37
  }
35
- let val = ((l % r) + r) % r;
36
- if (val < 0) {
37
- val = val * -1;
38
+ // a MOD r = a - r * ( a DIV r ), with the quotient rule of DIV:
39
+ // 7 MOD -3 = 1, -7 MOD -3 = 2, 7.5 MOD -2 = 1.5. For f this is also what a
40
+ // system computes in double precision, 0.5 MOD 0.1 = 0 there, where a
41
+ // remainder by % gives 0.09999999999999998
42
+ const q = r > 0 ? Math.floor(l / r) : -Math.floor(l / -r);
43
+ let val = l - r * q;
44
+ if (val === 0) {
45
+ val = 0; // not -0
38
46
  }
39
47
  // the calculation type of the operands decides: with a float operand the
40
48
  // remainder is a float, 2.75 MOD 1 is 0.75 and not 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.13.90",
3
+ "version": "2.13.92",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",