I am trying to take the sum of a very "big" vector, I know the big()
function can be used for calculating large number,
which I even used down below (and it works). However, if I try to use it in a sum it doesn't work.
I tried both big(sum(test, dims=1))
and sum(big(test), dims=1))
but I recieve following error:
InexactError: Int64(-3331427209747016990720)
test = Tuple{Int, Int}[]
N = 80
Iterations = 60
for i in 1:10000
push!(test, (big(largeNumber1(N, Iterations)) * big(largeNumber2(N, Iterations)), 0))
end
# this just transforms test into a vector
test = hcat(first.(test), last.(test)) * [1, 0]
sum(test, dims=1) # here is where the code "breaks"
<output> 1-element Vector{Int64}:
-5233167026984513820
Most likely I am using big()
wrong
You did not show the code for largeNumber1(), but it seems that you are putting the big integer numbers into an Int64-tuple vector before you sum it. Try
test = Tuple{BigInt, BigInt}[]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.