Tagged Questions
0
votes
1answer
19 views
How many bits are available for JS-style “integer” math now?
While solving my previous question I faced even more funny thing.
Try integer math (yes, I know they aren't "too integer" inside) to see how much bits are available:
var n = 0xffffffff;
// loop over ...
0
votes
4answers
38 views
JavaScript integer shift safety: (n << 1) != (n * 2)
Digging JS just discovered something new to me:
n = 0xffffffff
4294967295
n
4294967295
n << 1
-2
n * 2
8589934590
(n << 1) == (n * 2)
false
n + 1
4294967296
This is console output of ...
0
votes
1answer
17 views
Having an issue with large integer addition in JavaScript
I'm just making a very simple program to convert binary numbers to decimal and vice versa. In doing the decimal to binary conversion, I realized I was running across a weird error when I try and add ...
0
votes
1answer
84 views
JavaScript integer overflow workaround
I need to perform arithmetical operations with large numbers in JS, in this particular case it is:
(1827116622 / 6) * 251772294
The expected result is 76669557221078478 but I am getting ...
0
votes
1answer
35 views
Javascript to python math translation
I have a java script function that I'm trying to replicate in python 2, and the java script is doing some kind of precision error wrap around (or something) which I'm having trouble understanding. ...
0
votes
2answers
33 views
JavaScript: Why is this causing an infinite loop?
I'm trying to find the largest number by finding the point at which the JavaScript number line wraps around. E.g., if it could only hold numbers 0, 1, 127 then I'd find 127 by using the fact that "127 ...
1
vote
3answers
44 views
What type of integral is a JavaScript array's length? Is there danger of wraparound?
Here's what I mean:
I have a function I'm writing like
function unstable_partition ( arr, piv )
{
// puts all values less than piv on the left of arr and
// all values greater than or ...
-1
votes
1answer
39 views
JavaScript numeric compare function - comparison vs subtraction
There is the possibility of integer overflow when you try to compare numbers using subtraction in Java. See Q: Java Integer compareTo() - why use comparison vs. subtraction?
But, unlike Java, ...
1
vote
1answer
45 views
Why this loop freezes my browser?
Why browser hangs executing this?
for(var i= 9007199254740993;i<9007199254740994;i++) {
console.log(i);
}
2
votes
1answer
144 views
Why does << 32 not result in 0 in javascript?
This is false:
(0xffffffff << 31 << 1) === (0xffffffff << 32)
It seems like it should be true. Adding >>> 0 anywhere does not change this.
Why is this and how can I ...
9
votes
2answers
869 views
“Simulate” a 32-bit integer overflow in JavaScript
JavaScript can handle the following Math just fine:
var result = (20000000 * 48271) % 0x7FFFFFFF;
But in some programming languages, that first int*int multiplication results in a value too large to ...
0
votes
2answers
424 views
Java, converting epoch to milliseconds
My flot graph is not displaying any lines, problem multiplying epoch by 1000 using Integer in Java?
This is my raw data, stored in a .txt file
epoch,value
1383229104,55559
1383229121,55559
1383229787,...
1
vote
3answers
1k views
Determine if conversion from string to 32-bit integer will overflow
Trying to do front-end validation on an HTML input instead of throwing an exception in the Java back-end.