More math operations for bigint
Today I was surprised to learn that in jrsonnet you cannot divide bigints, you cannot multiply them with regular numbers, and changing the order of the operands can break everything. This PR brings order to the basic operations (except for bitwise operations) and makes the following changes:
- BigInt can now be compared with regular numbers.
- BigInt can now be added to regular numbers.
- BigInt can now be subtracted from regular numbers.
- BigInt can now be divided, and got the remainder.
- Strings can now be multiplied by BigInt. Also, the bug with
number * str(instead ofstr * number) has been fixed.
All operations are now in separate functions. The changes were tested using the tests.zip scripts.
Ideally, we should also have binary operations for bigint and strict comparison between regular numbers and bigint. But this is not a big problem right now, and I will leave it for other PRs.
r? @CertainLach
BigInt can now be compared with regular numbers. BigInt can now be added to regular numbers. BigInt can now be subtracted from regular numbers.
This was done on purpose, such conversions should be explicit (via std.bigint), otherwise it may lead to silent precision loss. It is implemented the same way in JS (implicit conversions are disallowed), for the exception of bigint literal support (12n === BigInt(12))
Strings can now be multiplied by BigInt
String by number multiplication does not exist in upstream jsonnet, and I would prefer to remove it completely, instead of adding another out-of-spec feature