precision - C: Exponentiation over 256bit integers -
i dealing algorithm operates on unsigned 256-bit integers, , need write function computes value of given formula
uint256 compute(uint16 x) { return floor(exp2(x / 256)) - 1; }
we can see equation preserves variable bounds (compute(0) == 0
, compute(65535) == 1<<255
). division should treated division of rational numbers, not integers.
the presented syntax pseudo-c, i'm looking general algorithmic aproach used in other languages.
thank , time.
you can precompute , tabulate 256-bit values of function x
in [65280, 65535]
(i.e. 255 x 256 + i
); lookup table 8 least significant bits of argument. take 8kb of storage.
for lower values of argument, shift tabulated value right 255 - (x >> 8)
.
if want sheer speed , can afford 64kb of storage, can precompute shifts 0 7, , perform larger shifts copying right byte offset.
alternatively, can consider cordic method exponentials, don't think faster or require less storage.
Comments
Post a Comment