You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Chapter 7 exercise 1.c, as the first 100 of fibonacci numbers will exceed 64bits numbers, you can't use Int but also Long too! See the result below(The answer here just show first 60 numbers which is OK):
val test: Long = 4660046610375530309l + 7540113804746346429l
val maxLong = Long.MaxValue
val max: BigInt = BigInt(2).pow(63) - 1
val big: BigInt = BigInt(4660046610375530309l) + BigInt(7540113804746346429l)
The output is:
test: Long = -6246583658587674878
maxLong: Long = 9223372036854775807
max: BigInt = 9223372036854775807
big: BigInt = 12200160415121876738
As we can see use BigInt will fix the overflow problem:
In Chapter 7 exercise 1.c, as the first 100 of fibonacci numbers will exceed 64bits numbers, you can't use Int but also Long too! See the result below(The answer here just show first 60 numbers which is OK):
We can verify this using the following code:
The output is:
As we can see use BigInt will fix the overflow problem:
The text was updated successfully, but these errors were encountered: