1
0
mirror of synced 2025-01-19 08:07:56 +01:00

'From Base' operation now supports numbers with fractional parts.

This commit is contained in:
n1474335 2017-03-31 16:00:23 +00:00
parent 3788a9161a
commit 706423462d
2 changed files with 20 additions and 2 deletions

View File

@ -46,7 +46,19 @@ const Base = {
if (radix < 2 || radix > 36) {
throw "Error: Radix argument must be between 2 and 36";
}
return parseInt(input.replace(/\s/g, ""), radix);
var number = input.replace(/\s/g, "").split("."),
result = parseInt(number[0], radix) || 0;
if (number.length === 1) return result;
// Fractional part
for (var i = 0; i < number[1].length; i++) {
var digit = parseInt(number[1][i], radix);
result += digit / Math.pow(radix, i+1);
}
return result;
},
};

View File

@ -13,7 +13,13 @@ const CyberChef = module.exports = {
bake: function(input, recipeConfig) {
this.chef = new Chef();
return this.chef.bake(input, recipeConfig, {}, 0, false);
return this.chef.bake(
input,
recipeConfig,
{},
0,
false
);
}
};