UNPKG

@abaplint/runtime

Version:
35 lines 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.divide = divide; const throw_error_1 = require("../throw_error"); const types_1 = require("../types"); const _parse_1 = require("./_parse"); // todo, this will only work when the target value is an integer? function divide(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"); } } return new types_1.Integer8().set(l / r); } const r = (0, _parse_1.parse)(right); const l = (0, _parse_1.parse)(left); if (r === 0) { if (l === 0) { return new types_1.Integer().set(0); } else { (0, throw_error_1.throwError)("CX_SY_ZERODIVIDE"); } } const val = l / r; return new types_1.Float().set(val); } //# sourceMappingURL=divide.js.map