nix icon indicating copy to clipboard operation
nix copied to clipboard

64-bit integers are not enough

Open erin-desu opened this issue 3 months ago • 2 comments

Is your feature request related to a problem?

I am trying to create IPv6 address registry where I have a common prefix I just register suffices. As IPv6 addresses are 128-bit long, I can't even create a mask larger than 64 bits.

Proposed solution

Introduce 128-bit integers or choose the Python-like solution and allow for arbitrary-sized ones.

Alternative solutions

Cope with workarounds like storing two 64-bit integers and suffer.

Additional context

None

Checklist

  • [X] checked [latest Nix manual] ([source])
  • [X] checked [open feature issues and pull requests] for possible duplicates

erin-desu avatar Sep 20 '25 15:09 erin-desu

Nix has previously eliminated a similar yet very different such pain in the form of floating point number support. I believe that was a mistake for a reproducible language, but large integers principally don't have the kind of underspecification issues and are much more suitable for a language that boasts reproducibility (which necessitates portability and stability of its behavior over time).

In fact, native support for large numbers would be a very useful building block for building an alternative to floating point numbers

  • https://github.com/NixOS/nix/issues/13997

Instead of 128 bits, I would prefer to go directly to integers of arbitrary size. We already have those in our closure anyway, e.g. openssl.

roberth avatar Sep 21 '25 15:09 roberth

Triaged during today's meeting:

  • @edolstra Seems like a "blob" (arbitrary binary data) type would be sufficient for IPv6 case without the complication of multiplication/division.
  • @xokdvium Boost has lightweight arbitrary-precision libraries if that comes to it.
  • @edolstra Native IPv6 type could possibly be an option.
    • @xokdvium Plugin could work as well.
  • @roberth Fixing the nixpkgs library with available primitives without drastically increasing the complexity of the language sounds plausible.

Cope with workarounds like storing two 64-bit integers

@xokdvium This particular use-case doesn't have a particularly high overhead from lack of arbitrary-precision integers. Though other cases might not be so.

xokdvium avatar Nov 26 '25 21:11 xokdvium