From 53eba2337c4ad39129e65ac1219a98de66b83d6d Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 5 Jan 2018 18:38:23 +0000 Subject: [PATCH] BCD operations now support BigNumbers --- src/core/config/OperationConfig.js | 4 ++-- src/core/operations/BCD.js | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 273b6c76..8b3b61ff 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3750,7 +3750,7 @@ const OperationConfig = { module: "Default", description: "Binary-Coded Decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four or eight. Special bit patterns are sometimes used for a sign.", inputType: "string", - outputType: "number", + outputType: "BigNumber", args: [ { name: "Scheme", @@ -3778,7 +3778,7 @@ const OperationConfig = { "To BCD": { module: "Default", description: "Binary-Coded Decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four or eight. Special bit patterns are sometimes used for a sign", - inputType: "number", + inputType: "BigNumber", outputType: "string", args: [ { diff --git a/src/core/operations/BCD.js b/src/core/operations/BCD.js index d3efbc71..7d29f4e5 100755 --- a/src/core/operations/BCD.js +++ b/src/core/operations/BCD.js @@ -1,4 +1,5 @@ import Utils from "../Utils.js"; +import BigNumber from "bignumber.js"; /** @@ -61,14 +62,14 @@ const BCD = { /** * To BCD operation. * - * @param {number} input + * @param {BigNumber} input * @param {Object[]} args * @returns {string} */ runToBCD: function(input, args) { - if (isNaN(input)) + if (input.isNaN()) return "Invalid input"; - if (Math.floor(input) !== input) + if (!input.floor().equals(input)) return "Fractional values are not supported by BCD"; const encoding = BCD.ENCODING_LOOKUP[args[0]], @@ -77,7 +78,7 @@ const BCD = { outputFormat = args[3]; // Split input number up into separate digits - const digits = input.toString().split(""); + const digits = input.toFixed().split(""); if (digits[0] === "-" || digits[0] === "+") { digits.shift(); @@ -152,7 +153,7 @@ const BCD = { * * @param {string} input * @param {Object[]} args - * @returns {number} + * @returns {BigNumber} */ runFromBCD: function(input, args) { const encoding = BCD.ENCODING_LOOKUP[args[0]], @@ -206,7 +207,7 @@ const BCD = { output += val.toString(); }); - return parseInt(output, 10); + return new BigNumber(output); }, };