@abaplint/runtime
Version:
Transpiler - Runtime
41 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.round = round;
const _parse_1 = require("../operators/_parse");
const types_1 = require("../types");
function round(input) {
let mode = input.mode;
if (mode === undefined) {
mode = 2;
}
else if (typeof mode !== "number") {
mode = mode?.get();
}
const val = (0, _parse_1.parse)(input.val);
const dec = (0, _parse_1.parse)(input.dec);
if (dec !== 0) {
throw "round(), todo, handle decimals";
}
const ret = new types_1.Float();
switch (mode) {
case 1:
ret.set(Math.ceil(val));
break;
case 2:
ret.set(Math.round(val));
break;
case 4:
ret.set(-Math.round(-val));
break;
case 5:
ret.set(Math.trunc(val));
break;
case 6:
ret.set(Math.floor(val));
break;
default:
throw "round(), unknown mode: " + mode;
}
return ret;
}
//# sourceMappingURL=round.js.map