BigInteger or not BigInteger?

前端 未结 3 1519
北恋
北恋 2021-01-17 13:31

In Java, most of the primitive types are signed (one bit is used to represent the +/-), and therefore when I exceed the limits of the type, I can get unexpected results, lik

3条回答
  •  旧时难觅i
    2021-01-17 14:15

    No, there is not a better solution. If you are working with values that cannot fit into a long or a double then you will need to use a reference type like BigInteger, and Java does not support operator overloading.

    Technically, I suppose you could have some mapping between signed and unsigned values, but if your goal is clean and simple code then this is not at all the way to go.

提交回复
热议问题