Why doesn't my processor have built-in BigInt support?

后端 未结 8 1794
执笔经年
执笔经年 2021-02-20 13:20

As far as I understood it, BigInts are usually implemented in most programming languages as arrays containing digits, where, eg.: when adding two of them, each digit is added on

8条回答
  •  天命终不由人
    2021-02-20 14:15

    There are simply too many issues that require the processor to deal with a ton of stuff which isn't its job.

    Suppose that the processor DID have that feature. We can work out a system where we know how many bytes are used by a given BigInt - just use the same principle as most string libraries and record the length.

    But what would happen if the result of a BigInt operation exceeded the amount of space reserved?

    There are two options:

    1. It'll wrap around inside the space it does have or
    2. It'll use more memory.

    The thing is, if it did 1), then it's useless - you'd have to know how much space was required beforehand, and that's part of the reason you'd want to use a BigInt - so you're not limited by those things.

    If it did 2), then it'll have to allocate that memory somehow. Memory allocation is not done in the same way across OSes, but even if it were, it would still have to update all pointers to the old value. How would it know what were pointers to the value, and what were simply integer values containing the same value as the memory address in question?

提交回复
热议问题