Does BigInteger ever overflows?

前端 未结 5 417
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 13:25

The API docs says

All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the r

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 14:23

    You read it right, it will never overflow. Although, it won't create more RAM for you :)

    Semantics of arithmetic operations exactly mimic those of Java's integer arithmetic operators, as defined in The Java Language Specification. For example, division by zero throws an ArithmeticException, and division of a negative by a positive yields a negative (or zero) remainder. All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the results of an operation.

提交回复
热议问题