Numbers and Precision(v2 · en)
Concept
Numeric literals carry a precise contract: hexadecimal / binary forms and _ digit grouping are writing sugar equal to their decimal counterparts; integer arithmetic inside i64 range raises a typed error on overflow instead of silently wrapping; integer literals beyond i64 are exact arbitrary-precision integers. Floats and integers are never equal, and only mixed arithmetic converts to float.
(println 0xff_ff)
(println 1_000_000)
(println 18446744073709551616)
Expected stdout:
65535
1000000
18446744073709551616
Division and modulo truncate toward zero: (mod -7 2) is -1 (C / Common Lisp rem semantics; a floor-semantics mod borrowed by name would give 1). Mixing in a float converts to float, and ( 1 1.0)= is always false — integers and floats are two value domains.
(println (/ 7 2) (mod -7 2))
(println (/ 7 2.0))
(println (= 1 1.0))
Expected stdout:
3 -1
3.5
false
The overflow boundary, run for real: adding one to the i64 upper bound produces a typed error and a non-zero exit; the program produces no value.
(println (+ 9223372036854775807 1))
Expected result (non-zero exit, stderr):
Error: integer overflow: (+ 9223372036854775807 1) is outside the 64-bit integer range at line 1, col 10
Design notes
Both numeric contracts are chosen to avoid pretending to know better. First, i64 overflow errors instead of wrapping — wrapping lets errors lurk inside data. Second, literals beyond i64 are exact bigints, not doubles that "happen not to have overflowed yet" — precision is not lost because a literal got big. The contract also states its own limits honestly: scenarios where out-of-range literals may lose precision (host numbers, serialization round trips) must not be used to fake bignum arithmetic; for exact math, take the bigint path explicitly.
Going further
Numeric representation is a classic "convenience vs correctness" battleground in language design: JavaScript's Number turns everything into a double (the famous 0.1+0.2≠0.3 accident), Python 3 eliminated a whole class of overflow bugs with arbitrary-precision integers, and Common Lisp defaults to bignums as well. Zio's position sits in the middle: small integers run at machine speed (i64), out-of-range stays exact (bigint), mixing is explicit (int ≠ float), truncation is stated (toward zero). This concept was split out of Values and Expressions at v2 — see version maps.