←back to thread

setBigTimeout

(evanhahn.com)
210 points cfj | 3 comments | | HN request time: 0.624s | source
Show context
yesco ◴[] No.41881325[source]
> In most JavaScript runtimes, this duration is represented as a 32-bit signed integer

I thought all numbers in JavaScript were basically some variation of double precision floating points, if so, why is setTimeout limited to a smaller 32bit signed integer?

If this is true, then if I pass something like "0.5", does it round the number when casting it to an integer? Or does it execute the callback after half a millisecond like you would expect it would?

replies(3): >>41881670 #>>41881685 #>>41884172 #
1. blixt ◴[] No.41881685[source]
JS numbers technically have 53 bits for integers (mantissa) but all binary operators turns it into a 32-bit signed integer. Maybe this is related somehow to the setTimeout limitation. JavaScript also has the >>> unsigned bit shift operator so you can squeeze that last bit out of it if you only care about positive values: ((2*32-1)>>>0).toString(2).length === 32
replies(1): >>41882267 #
2. tubs ◴[] No.41882267[source]
I assume by binary you mean logical? A + b certainly does not treat either side as 32bit.
replies(1): >>41882779 #
3. blixt ◴[] No.41882779[source]
Sorry, I meant bitwise operators, such as: ~ >> << >>> | &