1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-14 23:37:40 +00:00

Add syntax literals for signed and unsigned 64 bit integers.

Number literals can now take an optional "representation" suffix

- Use `:n` for normal numbers (IEEE-754 doubles)
- Use `:s` for signed 64 bit integers
- Use `:u` for unsigned 64 bit integers
- Other suffix will fallthrough the usual parseing logic. This means
  that they will only possibly resolve to symbols if they start with -,
  +, or .

The syntax does not collide with any existing valid Janet and is only
enabled with JANET_INTTYPES. This also leaves open a syntax for other
number types such as bignums, ratios, decimals, etc.
This commit is contained in:
Calvin Rose
2024-07-21 09:36:23 -05:00
parent 9eab57d194
commit 872b39cc32
4 changed files with 50 additions and 0 deletions

View File

@@ -47,6 +47,14 @@
(assert (= (int/to-number (i64 9007199254740991)) 9007199254740991))
(assert (= (int/to-number (i64 -9007199254740991)) -9007199254740991))
# New parser
(assert (= (u64 "123") 123:u) "u64 parsing")
(assert (= (u64 "0") 0:u) "u64 parsing")
(assert (= (u64 "0xFFFF_FFFF_FFFF_FFFF") 0xFFFF_FFFF_FFFF_FFFF:u) "u64 parsing")
(assert (= (i64 "123") 123:s) "s64 parsing")
(assert (= (i64 "-123") -123:s) "s64 parsing")
(assert (= (i64 "0") 0:s) "s64 parsing")
(assert-error
"u64 out of bounds for safe integer"
(int/to-number (u64 "9007199254740993"))