diff --git a/src/core/operations/ToIEEEBinary.mjs b/src/core/operations/ToIEEEBinary.mjs index db93e920e..3faa7fb8a 100644 --- a/src/core/operations/ToIEEEBinary.mjs +++ b/src/core/operations/ToIEEEBinary.mjs @@ -4,6 +4,7 @@ * @license Apache-2.0 */ +import OperationError from "../errors/OperationError.mjs"; import Operation from "../Operation.mjs"; import { ToIEEE754Float64 } from "../lib/IEEEBinary.mjs"; @@ -34,13 +35,23 @@ class ToIEEEBinary extends Operation { * @param {Object[]} args * @returns {string} */ - run(input, args) { - if (!input || input.trim().length === 0) { - return ""; - } + run(input, args) { + if (input === null || input === undefined) + return ""; + input = String(input); + + if (input.trim().length === 0) + return ""; + + try { return ToIEEE754Float64(input); + } catch (err) { + throw new OperationError(err.message); + } } +} + export default ToIEEEBinary;