BigInteger coming to JavaScript CodeGen

Support for BigInteger type in SmartPascal is being added in the DWScript repository, it is mapped to the new BigInt JavaScript type which is now supported by the major browsers.

This is going to be a work in progress over a few weeks. In part because the JS implementation is rather bare-bones with few support functions, and in part because with the BigInt type, the JS designers did away with some automated and implicit casting (uh?).

Classic JavaScript Number type is essentially a double-precision floating point with some 32bit integer hackery thrown-in for some bitwise operator. Conversions back and forth between integer and floats are silent and potentially lossy.

With the BigInt type, some strictness is reintroduced, and adding a BigInt to a Number will result in a type error:

a = 1;

b = 1n + a; // Type error !
b = 1n + 1; // Type error here as well

b = 1n + BigInt(a); // Explicit cast required

This is a non-existent problem in Pascal as Integer and Float types were separated back in the last millennia, but it is a novelty for JavaScript.

Besides obvious use cases in cryptography and Maths applications, the BigInt type means JavaScript can now handle 64bit integers somewhat efficiently, and can now also be used for accounting (fixed precision maths).