@abaplint/runtime
Version:
Transpiler - Runtime
44 lines • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.div = div;
const throw_error_1 = require("../throw_error");
const types_1 = require("../types");
const _parse_1 = require("./_parse");
function div(left, right) {
if (left instanceof types_1.Integer8 || right instanceof types_1.Integer8) {
const l = left instanceof types_1.Integer8 ? left.get() : BigInt((0, _parse_1.parse)(left));
const r = right instanceof types_1.Integer8 ? right.get() : BigInt((0, _parse_1.parse)(right));
if (r === 0n) {
if (l === 0n) {
return new types_1.Integer8().set(0n);
}
else {
(0, throw_error_1.throwError)("CX_SY_ZERODIVIDE");
}
}
const remainder = l % r;
let div = l / r;
if (remainder !== 0n) {
const sign1 = l < 0n;
const sign2 = r < 0n;
if (sign1 !== sign2) {
div = div - 1n;
}
}
return new types_1.Integer8().set(div);
}
const l = (0, _parse_1.parse)(left);
const r = (0, _parse_1.parse)(right);
if (r === 0) {
if (l === 0) {
return new types_1.Integer().set(0);
}
else {
(0, throw_error_1.throwError)("CX_SY_ZERODIVIDE");
}
}
else {
return new types_1.Integer().set(Math.floor(l / r));
}
}
//# sourceMappingURL=div.js.map