@abaplint/runtime 2.8.2 → 2.8.4

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.
@@ -7,8 +7,11 @@ function mod(left, right) {
7
7
  if (left instanceof types_1.Integer8 || right instanceof types_1.Integer8) {
8
8
  const l = left instanceof types_1.Integer8 ? left.get() : BigInt((0, _parse_1.parse)(left));
9
9
  const r = right instanceof types_1.Integer8 ? right.get() : BigInt((0, _parse_1.parse)(right));
10
- // todo, is this correct?
11
- return new types_1.Integer8().set(l % r);
10
+ let val = ((l % r) + r) % r;
11
+ if (val < 0) {
12
+ val = val * -1n;
13
+ }
14
+ return new types_1.Integer8().set(val);
12
15
  }
13
16
  const l = (0, _parse_1.parse)(left);
14
17
  const r = (0, _parse_1.parse)(right);
@@ -5,6 +5,9 @@ const throw_error_1 = require("../throw_error");
5
5
  const float_1 = require("./float");
6
6
  const hex_1 = require("./hex");
7
7
  const xstring_1 = require("./xstring");
8
+ const integer_1 = require("./integer");
9
+ const get_bit_1 = require("../statements/get_bit");
10
+ const character_1 = require("./character");
8
11
  const digits = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
9
12
  class Integer8 {
10
13
  constructor(input) {
@@ -37,16 +40,21 @@ class Integer8 {
37
40
  this.set(Math.round(value.getRaw()));
38
41
  }
39
42
  else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
40
- // todo, can BigInt("0x" + value.get()); be used?
41
- let num = parseInt(value.get(), 16);
42
- // handle two complement,
43
- if (value instanceof hex_1.Hex && value.getLength() >= 4) {
44
- const maxVal = Math.pow(2, value.get().length / 2 * 8);
45
- if (num > maxVal / 2 - 1) {
46
- num = num - maxVal;
43
+ if (value.get().length === 16) {
44
+ const lv_bit = new character_1.Character();
45
+ (0, get_bit_1.getBit)(new integer_1.Integer().set(1), value, lv_bit);
46
+ if (lv_bit.get() === "1") {
47
+ const val = BigInt("0x" + value.get());
48
+ this.value = val - BigInt("0x10000000000000000");
47
49
  }
50
+ else {
51
+ this.value = BigInt("0x" + value.get());
52
+ }
53
+ }
54
+ else {
55
+ // todo, what if the input is longer than 16 bytes?
56
+ this.value = BigInt("0x" + value.get());
48
57
  }
49
- this.set(num);
50
58
  }
51
59
  else {
52
60
  this.set(value.get());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.8.2",
3
+ "version": "2.8.4",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",