How do programming languages handle huge number arithmetic

前端 未结 9 1158
清酒与你
清酒与你 2021-02-05 19:35

For a computer working with a 64 bit processor, the largest number that it can handle would be 264 = 18,446,744,073,709,551,616. How does programming languages, say J

9条回答
  •  长发绾君心
    2021-02-05 20:06

    Most languages store them as array of integers. If you add/subtract two to of these big numbers the library adds/subtracts all integer elements in the array separately and handles the carries/borrows. It's like manual addition/subtraction in school because this is how it works internally.

    Some languages use real text strings instead of integer arrays which is less efficient but simpler to transform into text representation.

提交回复
热议问题