Fix bug in making operations upon really big numbers

This commit is contained in:
borys_levytskyi
2015-11-30 22:34:08 +02:00
parent 9177142e36
commit 8d3d80dcee
2 changed files with 9 additions and 6 deletions

View File

@@ -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;
};
});

View File

@@ -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() {