@abaplint/runtime 2.0.67 → 2.0.68

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.
@@ -17,7 +17,15 @@ function parse(val) {
17
17
  if (val.get() === "") {
18
18
  return 0;
19
19
  }
20
- return parseInt(val.get(), 16);
20
+ let num = parseInt(val.get(), 16);
21
+ // handle two complement,
22
+ if (val instanceof types_1.Hex && val.getLength() >= 4) {
23
+ const maxVal = Math.pow(2, val.get().length / 2 * 8);
24
+ if (num > maxVal / 2 - 1) {
25
+ num = num - maxVal;
26
+ }
27
+ }
28
+ return num;
21
29
  }
22
30
  else if (val instanceof types_1.Time || val instanceof types_1.Date) {
23
31
  return val.getNumeric();
@@ -4,7 +4,10 @@ exports.div = void 0;
4
4
  const types_1 = require("../types");
5
5
  const _parse_1 = require("./_parse");
6
6
  function div(left, right) {
7
- return new types_1.Integer().set(Math.floor((0, _parse_1.parse)(left) / (0, _parse_1.parse)(right)));
7
+ const l = (0, _parse_1.parse)(left);
8
+ const r = (0, _parse_1.parse)(right);
9
+ const ret = new types_1.Integer().set(Math.floor(l / r));
10
+ return ret;
8
11
  }
9
12
  exports.div = div;
10
13
  //# sourceMappingURL=div.js.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Hex = void 0;
4
- const operators_1 = require("../operators");
5
4
  const float_1 = require("./float");
6
5
  const xstring_1 = require("./xstring");
7
6
  class Hex {
@@ -15,26 +14,22 @@ class Hex {
15
14
  }
16
15
  else if (typeof value === "number") {
17
16
  if (value < 0) {
18
- this.value = "F".repeat(this.length * 2);
19
- this.set((0, operators_1.minus)(this, Math.abs(value) - 1));
20
- return;
17
+ const maxVal = Math.pow(2, this.length * 8);
18
+ this.value = Math.round(value + maxVal).toString(16);
19
+ }
20
+ else {
21
+ this.value = Math.round(value).toString(16);
21
22
  }
22
- this.value = Math.round(value).toString(16);
23
23
  this.value = this.value.padStart(this.length * 2, "0");
24
24
  }
25
25
  else {
26
26
  let v = value.get();
27
27
  if (value instanceof float_1.Float) {
28
28
  v = value.getRaw();
29
- if (v < 0) {
30
- this.value = "F".repeat(this.length * 2);
31
- this.set((0, operators_1.minus)(this, Math.abs(v) - 1));
32
- return;
33
- }
29
+ this.set(v);
34
30
  }
35
31
  if (typeof v === "number") {
36
- this.value = Math.round(v).toString(16);
37
- this.value = this.value.padStart(this.length * 2, "0");
32
+ this.set(v);
38
33
  }
39
34
  else {
40
35
  this.value = v;
@@ -32,7 +32,15 @@ class Integer {
32
32
  this.set(Math.round(value.getRaw()));
33
33
  }
34
34
  else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
35
- this.set(parseInt(value.get(), 16));
35
+ let num = parseInt(value.get(), 16);
36
+ // handle two complement,
37
+ if (value instanceof hex_1.Hex && value.getLength() >= 4) {
38
+ const maxVal = Math.pow(2, value.get().length / 2 * 8);
39
+ if (num > maxVal / 2 - 1) {
40
+ num = num - maxVal;
41
+ }
42
+ }
43
+ this.set(num);
36
44
  }
37
45
  else {
38
46
  this.set(value.get());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.0.67",
3
+ "version": "2.0.68",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",