Conversion operations now support BigNumbers

This commit is contained in:
n1474335 2018-01-05 18:14:03 +00:00
parent 3f3e7a78eb
commit 7992a540ae
2 changed files with 30 additions and 31 deletions

View File

@ -2515,8 +2515,8 @@ const OperationConfig = {
"Convert distance": {
module: "Default",
description: "Converts a unit of distance to another format.",
inputType: "number",
outputType: "number",
inputType: "BigNumber",
outputType: "BigNumber",
args: [
{
name: "Input units",
@ -2533,8 +2533,8 @@ const OperationConfig = {
"Convert area": {
module: "Default",
description: "Converts a unit of area to another format.",
inputType: "number",
outputType: "number",
inputType: "BigNumber",
outputType: "BigNumber",
args: [
{
name: "Input units",
@ -2551,8 +2551,8 @@ const OperationConfig = {
"Convert mass": {
module: "Default",
description: "Converts a unit of mass to another format.",
inputType: "number",
outputType: "number",
inputType: "BigNumber",
outputType: "BigNumber",
args: [
{
name: "Input units",
@ -2569,8 +2569,8 @@ const OperationConfig = {
"Convert speed": {
module: "Default",
description: "Converts a unit of speed to another format.",
inputType: "number",
outputType: "number",
inputType: "BigNumber",
outputType: "BigNumber",
args: [
{
name: "Input units",
@ -2587,8 +2587,8 @@ const OperationConfig = {
"Convert data units": {
module: "Default",
description: "Converts a unit of data to another format.",
inputType: "number",
outputType: "number",
inputType: "BigNumber",
outputType: "BigNumber",
args: [
{
name: "Input units",

View File

@ -60,17 +60,16 @@ const Convert = {
/**
* Convert distance operation.
*
* @param {number} input
* @param {BigNumber} input
* @param {Object[]} args
* @returns {number}
* @returns {BigNumber}
*/
runDistance: function (input, args) {
let inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.DISTANCE_FACTOR[inputUnits];
return input / Convert.DISTANCE_FACTOR[outputUnits];
// TODO Remove rounding errors (e.g. 1.000000000001)
input = input.mul(Convert.DISTANCE_FACTOR[inputUnits]);
return input.div(Convert.DISTANCE_FACTOR[outputUnits]);
},
@ -141,16 +140,16 @@ const Convert = {
/**
* Convert data units operation.
*
* @param {number} input
* @param {BigNumber} input
* @param {Object[]} args
* @returns {number}
* @returns {BigNumber}
*/
runDataSize: function (input, args) {
let inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.DATA_FACTOR[inputUnits];
return input / Convert.DATA_FACTOR[outputUnits];
input = input.mul(Convert.DATA_FACTOR[inputUnits]);
return input.div(Convert.DATA_FACTOR[outputUnits]);
},
@ -221,16 +220,16 @@ const Convert = {
/**
* Convert area operation.
*
* @param {number} input
* @param {BigNumber} input
* @param {Object[]} args
* @returns {number}
* @returns {BigNumber}
*/
runArea: function (input, args) {
let inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.AREA_FACTOR[inputUnits];
return input / Convert.AREA_FACTOR[outputUnits];
input = input.mul(Convert.AREA_FACTOR[inputUnits]);
return input.div(Convert.AREA_FACTOR[outputUnits]);
},
@ -332,16 +331,16 @@ const Convert = {
/**
* Convert mass operation.
*
* @param {number} input
* @param {BigNumber} input
* @param {Object[]} args
* @returns {number}
* @returns {BigNumber}
*/
runMass: function (input, args) {
let inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.MASS_FACTOR[inputUnits];
return input / Convert.MASS_FACTOR[outputUnits];
input = input.mul(Convert.MASS_FACTOR[inputUnits]);
return input.div(Convert.MASS_FACTOR[outputUnits]);
},
@ -397,16 +396,16 @@ const Convert = {
/**
* Convert speed operation.
*
* @param {number} input
* @param {BigNumber} input
* @param {Object[]} args
* @returns {number}
* @returns {BigNumber}
*/
runSpeed: function (input, args) {
let inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.SPEED_FACTOR[inputUnits];
return input / Convert.SPEED_FACTOR[outputUnits];
input = input.mul(Convert.SPEED_FACTOR[inputUnits]);
return input.div(Convert.SPEED_FACTOR[outputUnits]);
},
};