UNPKG

@jplorg/jpl

Version:
40 lines (39 loc) 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.trunc = exports.tan = exports.sqrt = exports.sin = exports.round = exports.pow = exports.log10 = exports.log = exports.floor = exports.exp = exports.cos = exports.ceil = exports.atan = exports.asin = exports.acos = exports.abs = void 0; var _library = require("../library"); function unwrapNumber(runtime, v) { const t = runtime.type(v); const u = runtime.unwrapValue(v); if (t !== 'number') { throw new _library.JPLTypeError('%s (%*<100v) cannot be used for mathematical operations', t, u); } return u; } function funcMath(alter) { return async function builtin(runtime, signal, next, input, ...args) { const t = runtime.type(input); if (t !== 'number') { throw new _library.JPLTypeError('%s (%*<100v) cannot be used for mathematical operations', t, runtime.unwrapValue(input)); } return next(await runtime.alterValue(input, value => alter(runtime, value, ...args))); }; } const pow = exports.pow = funcMath((runtime, value, arg0) => value ** unwrapNumber(runtime, arg0 ?? null)); const sqrt = exports.sqrt = funcMath((runtime, value) => Math.sqrt(value)); const exp = exports.exp = funcMath((runtime, value) => Math.exp(value)); const log = exports.log = funcMath((runtime, value) => Math.log(value)); const log10 = exports.log10 = funcMath((runtime, value) => Math.log10(value)); const sin = exports.sin = funcMath((runtime, value) => Math.sin(value)); const cos = exports.cos = funcMath((runtime, value) => Math.cos(value)); const tan = exports.tan = funcMath((runtime, value) => Math.tan(value)); const asin = exports.asin = funcMath((runtime, value) => Math.asin(value)); const acos = exports.acos = funcMath((runtime, value) => Math.acos(value)); const atan = exports.atan = funcMath((runtime, value) => Math.atan(value)); const ceil = exports.ceil = funcMath((runtime, value) => Math.ceil(value)); const floor = exports.floor = funcMath((runtime, value) => Math.floor(value)); const round = exports.round = funcMath((runtime, value) => Math.round(value)); const trunc = exports.trunc = funcMath((runtime, value) => Math.trunc(value)); const abs = exports.abs = funcMath((runtime, value) => Math.abs(value));