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:
@@ -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"))
|
||||
|
Reference in New Issue
Block a user