From 8d3d80dcee34071e5d6853f76c3cbf162289e0de Mon Sep 17 00:00:00 2001 From: borys_levytskyi Date: Mon, 30 Nov 2015 22:34:08 +0200 Subject: [PATCH] Fix bug in making operations upon really big numbers --- src/js/app/bitwise/expression.js | 9 +++------ tests/e2e/spec.js | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/js/app/bitwise/expression.js b/src/js/app/bitwise/expression.js index f979ce3..ffc70a5 100644 --- a/src/js/app/bitwise/expression.js +++ b/src/js/app/bitwise/expression.js @@ -3,7 +3,7 @@ app.set('expression', function() { var exprRegex = /^(-?(?:\d+|0x[\d,a-f]+))\s*(<<|>>|>>>|\||\&|\^)\s*(-?(?:\d+|0x[\d,a-f]+))$/; var listRegex = /^(-?(?:\d+|0x[\d,a-f]+)\s?)+$/; - var notRex = /^(~)(-?(?:\d+|0x[\d,a-f]+))$/ + var notRex = /^(~)(-?(?:\d+|0x[\d,a-f]+))$/; return { canParse: function(string) { @@ -92,12 +92,9 @@ app.set('expression', function() { this.value = parseInt(input); this.hex = toHex(this.value.toString(16)); this.dec = this.value.toString(10); - this.bin = (this.value>>>0).toString(2); + // >>> 0 makes negative numbers like -1 to be displayed as '11111111111111111111111111111111' in binary instead of -1 + this.bin = this.value < 0 ? (this.value >>> 0).toString(2) : this.value.toString(2); this.kind = this.input.indexOf('0x') > -1 ? 'hex' : 'dec'; this.other = this.kind == 'dec' ? this.hex : this.dec; } - - Operand.prototype.valueOf = function () { - return this.value; - }; }); \ No newline at end of file diff --git a/tests/e2e/spec.js b/tests/e2e/spec.js index a97d5b6..656dba1 100644 --- a/tests/e2e/spec.js +++ b/tests/e2e/spec.js @@ -106,7 +106,13 @@ describe('launch of application', function() { { label: '3', bin:'00000011', other: '0x3'}]) }); + it('should do XOR or large numbers', function() { + return assertOperation('0x0001000000003003^0x3001800400000fc1', + [{ label: '0x0001000000003003', bin:'0000000000000001000000000000000000000000000000000011000000000011', other: '281474976722947'}, + { label: '0x3001800400000fc1', bin:'0011000000000001100000000000010000000000000000000001000000000000', other: '3459186743465480000'}, + { label: '0x2003', bin:'0000000000000000000000000000000000000000000000000010000000000011', other: '8195'}]) + }); it('should do prefer hex result', function() {