HN user

minimize

13 karma
Posts0
Comments3
View on HN
No posts found.

For maximum efficiency you'd avoid addc like hell, because it blocks internal precomputation, and use guarantees like he did, avoiding overflow better.

Whether that is the case depends on the CPU. I hit memory bandwidth limits before adc becomes a problem. But I concede that you have a valid point and that there are definitely cases where leaving sufficient space for carries is the better strategy.

Anyway, we can probably both agree that "% 1000000000" is not the best way to do it.

For maximum efficiency, you should work in binary instead of base 10. Handling carries becomes more straightforward with the right primitives, for example __builtin_addc with GCC: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins...

You can also implement it in C if you want a more portable solution: https://github.com/983/bigint/blob/ee0834c65a27d18fa628e6c52...

If you scroll around, you can also find my implementations for multiplication and such.

Not sure if it has been mentioned yet, but I think the main reason why this title failed is the title. Most people probably never heard of "yerba mate", so to them, the title sounds like some kind of weird mating simulator.

You can verify this by comparing the sales by country to the number of searches for the term "yerba mate" by country: https://trends.google.com/trends/explore?q=yerba%20mate The distributions are very similar.