top | item 46065442

(no title)

ape4 | 3 months ago

Perhaps nicer to avoid the comment and write:

    const C1 = 505054698555331      // floor(2^64*4/146097)
as

    constexpr int C1 = floor(2^64*4/146097);

discuss

order

aw1621107|3 months ago

std::floor was made constexpr in C++23, which is pretty recent as far as C++ standards go. It's possible the author didn't think using C++23 was worth the constraints it places on who could use the code.

CodesInChaos|3 months ago

That's a mathematical expression, not a C++ expression. And floor here isn't the C++ floor function, it's just describing the usual integer division semantics. The challenge here is that you need 128-bit integers to avoid overflowing.

glitchdout|2 months ago

    const C1 = 505054698555331      // floor(2^64*4/146097)
is faster