Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save 10^19 in Julia without an overflow

Tags:

julia

I am trying to save the number 10^19 in a variable in Julia.

I know it is overflowing, but I figured that doing something like BigInt(10^19) or Int128(10^19) would solve the problem but it doesn't.

Any thoughts?

See overflow behavior for Julia

like image 597
logankilpatrick Avatar asked Jan 29 '20 01:01

logankilpatrick


1 Answers

Julia does Int64 arithmetic by default, so the 10^19 overflows as the default Int64 before the surrounding parentheses casting to a bigger type are encountered. Try

Int128(10)^20 == BigInt(10)^20 == big"10"^20
like image 74
Bill Avatar answered Jan 03 '23 04:01

Bill