Skip to content

Commit

Permalink
'From Base' operation now supports numbers with fractional parts.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Mar 31, 2017
1 parent 3788a91 commit 7064234
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/core/operations/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

};
Expand Down
8 changes: 7 additions & 1 deletion src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

};

0 comments on commit 7064234

Please sign in to comment.