r/cpp • Boost author • Aug 05 '26

Boost.Int128 has been accepted

Boost.Int128 from Matt Borland has been accepted into Boost. Arnaud Becheler managed the review.

126 Upvotes

50 comments sorted by

View all comments

5

u/wiesemensch Aug 05 '26

Nice work but do any of you actually use 128bit ints and if so, for what application?

15

u/Firm-Survey-31 Aug 05 '26

Averaging many int64s for example? For time stamps in nanoseconds overflow can be an issue

-3

u/serviscope_minor Aug 07 '26

I guess... but you may as well use doubles at that point. You're unlikely to exceed the precision of a 48 bit mantissa.

10

u/Potential_Soup_8054 Aug 05 '26

Science.

3

u/serviscope_minor Aug 07 '26

What science though? I have done plenty of science and haven't used 128 bit ints. I am curious because I assume it wasn't added just for giggles.

1

u/Potential_Soup_8054 Aug 07 '26

Data science, physics simulation, orbital mechanics simulations, cryptography, astrophysics, any sort of extremely complex calculations like averaging a bunch of 64bit integers. Very big numbers are useful

1

u/serviscope_minor Aug 07 '26

Data science, physics simulation, orbital mechanics simulations, cryptography, astrophysics, any sort of extremely complex calculations like averaging a bunch of 64bit integers.

To what end? I mean I've done some data science, done simulations, no cryptography (I can see the use there more) and I have never encountered a problem which would have benefited from 128 bit ints.

64 bits in a double is an awful lot of precision for anything physical.

ETA: sure with very long term simulation of a chaotic system like orbits but with chaos deviations rise exponentially, so if you run out of space in 48 or 64 bits, it's only a few more steps to 128. Surely you'd need much wider arbitrary precision for that. Though with that said, we have nothing like 48 bits of precision on the velocities anyway.

4

u/[deleted] Aug 05 '26

[removed] — view removed comment

2

u/fdwr fdwr@github 🔍 Aug 08 '26

That was just the case I was thinking of, the proposed widening_clmul and std::wide_result in P3642, as I've needed that double-wide result for rescaling back down (but if the top bits are all chopped off, it's hard to get the right result).

1

u/ack_error Aug 06 '26

Precomputed reciprocal for a divide/modulus that is not known at compile time but relatively stable at runtime, such as a hash table modulus.

1

u/friedkeenan Aug 06 '26

std::views::iota is allowed to use it for its difference type when the difference between two iterators could be otherwise unrepresentable by smaller-width types: https://godbolt.org/z/4Y65GME6r