How to handle arbitrarily large integers

后端 未结 7 835
南旧
南旧 2020-12-01 11:34

I\'m working on a programming language, and today I got the point where I could compile the factorial function(recursive), however due to the maximum size of an integer the

相关标签:
7条回答
  • 2020-12-01 12:09

    My prefered approach would be to use my current int type for 32-bit ints(or maybe change it to internally to be a long long or some such, so long as it can continue to use the same algorithms), then when it overflows, have it change to storing as a bignum, whether of my own creation, or using an external library. However, I feel like I'd need to be checking for overflow on every single arithmetic operation, roughly 2x overhead on arithmetic ops. How could I solve that?

    0 讨论(0)
提交回复
热议问题