←back to thread

setBigTimeout

(evanhahn.com)
210 points cfj | 1 comments | | HN request time: 0.221s | 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 #
arp242 ◴[] No.41881670[source]
You're correct about JS numbers. It works like this presumably because the implementation is written in C++ or the like and uses an int32 for this, because "25 days ought to be enough for everyone".
replies(1): >>41882076 #
drdaeman ◴[] No.41882076[source]
I thought most non-abandoned C/C++ projects have long switched to time_t or similar. 2038 is not that far in the future.
replies(4): >>41883127 #>>41884022 #>>41884079 #>>41884616 #
1. afavour ◴[] No.41884079[source]
Yes but JS always has backwards compatibility in mind, even if it wasn’t in the spec. Wouldn’t be surprised if more modern implementations still add an arbitrary restriction.