What were the thoughts of doing what Lean 4 does and natively supporting arbitrary-precision.
Nat is optimized. Small natural numbers (i.e., < 2^63 in a 64-bit machine) are represented by a single machine word. Big numbers are implemented using GMP numbers." This is a nice built-in feature, while also having access to USize if I want to be the size of a memory address.
we've talked about it before - basically my thinking is:
I128 lets you represent numbers in the undecillionsI128 is literally multiple orders of magnitude faster than arbitrary-sized integers, because they can live entirely in CPU registers instead of requiring heap allocations or chasing pointersI'm very skeptical, but always open to the possibility I'm missing something! :big_smile:
Side question to add in:
How important is native support vs having a library implementation? I get the rare need for big buns, but given they are rare, I tend to think they fit best in a library.
Honestly, there isn't a rock solid reason that would improve the language for most people, just a bunch of niche ones (i.e usually scientific/math computing related). But it is nice to know that I can't overflow and not have to look to some library. However, having people constantly write USize instead of Nat might make it not worth it for other use cases beyond math/scientific computing.
It’s somewhat common for me to want larger numbers than that, but that’s when I’m doing problems for fun (e.g. Project Euler problems). I don’t know of any common situations where you would actually need them
As a note, currently the plan is for nat to go away. Just use u64 instead.
fwiw overflow is still possible with arbitrary ints (memory is finite!) just less likely. Which again comes back to how much overflow is worth worrying about with 128-bit integers! :big_smile:
Yes you can technically still overflow, but for the use cases where it's commonly used usually result in a question of whether your computer can actually compute such a large result before you reach memory limits.
So death by lock up do to gigantic compute instead of death by overflow. Still represents a broken/unusable program
Well only death by gigantic compute because you're intentionally trying to annihilate your RAM haha. But the use cases are limited, I personally was interested for cryptography where U128 wouldn't be close to enough. But other than math/scientific computing related, not sure if there are any solid use cases where it just makes things way nicer to deal with.
huh, interesting! I haven't heard of cryptography uses that need more than U128 - can you say more about the use case?
A lot of algorithms have intermediate computations that are 100's to 1000's of bits large. RSA-4096 for example but also ECC. Although for some specific cases there are tricks to reduce it, but generally you need at a minimum 100's of bits
interesting! I've never looked at the implementations of one of those...is it common to implement things like RSA-4096 using arbitrary-sized integers?
for performance, I'd have guessed there'd be some preferred other way to do it without heap allocations
I am not super familiar with the implementation optimizations done today, but you definitely need arbitrary-sized integers just for the key itself. But looking at the crypto-bigint crate for rust, they determine the size and do the computations at compile time (const fn).
Another thing, this wouldn't be to support rigorous implementations (usually done in C++/Rust and with more security considerations), but there are other math algorithms/applications where it's typical to have arbitrary-precision. However, I think that maybe it's best in a library. It does make those use cases where you are building something that needs it easier (e.g like a CAS, or anything below world class security RSA) and I think it does make sense because its the closest thing to the concept of a natural number. But beyond those niches it doesn't really do much and roc isn't necessarily targeting to be a math/science oriented language. Which makes sense why Julia/Lean natively have it.
gotcha, very good to know!
Jacob has marked this topic as resolved.
Last updated: Jun 16 2026 at 16:19 UTC