◀ THE FOLD0ROOT.AI // WORLD II · GLITCH · OFF BY ONE◆ .dlw.fold
THE FOLD / GLITCH / OFF BY ONE / THE INTEGER PROMOTION

THE INTEGER PROMOTION

the truncation is the only honest part
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
JavaScript numbers are 64-bit floats until you use a bitwise operator, at which point they are silently converted to signed 32-bit integers, operated on, and converted back. The conversion is not an error and produces no warning.

LIT verified live. 1 << 31 is −2147483648: shifting a positive number left makes it negative. 1 << 32 is 1, because the shift count itself wraps at 32. And 232 | 0 is 0 — four billion becomes nothing. Of the 64 powers of two tested, 33 change value when passed through a single | 0.
2 HOW IT WAS WEAVED · AI + HUMAN
The ToInt32 conversion is specified in ECMA-262 and is the reason |0 was used as an optimisation hint for years by people who understood exactly what it truncates.

AVAN (AI) swept every power of two rather than showing the famous shift, because the interesting boundary is 230: everything at or below survives, everything above does not, and there is no diagnostic anywhere. 33 of 64 is the shape of a cliff sitting in the middle of the number line with no fence around it.
3 ONE DIMENSION
Every power of two, before and after a bitwise operator.
4 TWO DIMENSIONS · INTERACTIVE
Walk across the boundary.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: a 64-bit value passing through a 32-bit door.
AVAN’s addition (the inverse-companion): the forward reading is that bitwise operators truncate silently and that is a hazard. The inverse is that the truncation is the only honest part. A double can hold integers up to 253 and pretends to be an integer type the whole way; the bitwise operator is the single place the language admits there is a width at all. Read backwards, the surprise is not that |0 narrows — it is that everything else let you believe the number had no size.
LIT 1 << 31 is -2147483648 so shifting a positive number left makes it negative, 1 << 32 is 1 because the shift count itself wraps at 32, and 2^32 | 0 is 0 - four billion becomes nothing - while of the 64 powers of two tested, 33 change value when passed through a single | 0

FIG The ToInt32 conversion is specified in ECMA-262 and is why |0 was used as an optimisation hint for years by people who understood exactly what it truncates. AVAN swept every power of two rather than showing the famous shift, because the interesting boundary is 2^30: everything at or below survives, everything above does not, and there is no diagnostic anywhere. 33 of 64 is the shape of a cliff in the middle of the number line with no fence around it.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of OFF BY ONE · David Lee Wise (ROOT0), with AVAN