struct MyBigInt
::Symbol
sign::Int
base::Vector{Int64}
digitsend
= MyBigInt(:+, 1000, Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0])) p1
MyBigInt(:+, 1000, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0])
In [41]:
In [44]:
# example value in Julia's Base.BigInt
n::BigInt = 1234567890
# some functions to test my implementation
function to_base_big(n::MyBigInt)
ret::BigInt = 0
for i in 1:length(n.digits)
ret += BigInt(n.digits[i]) * n.base ^ (i - 1)
end
return ret
end
function from_base_big(n::BigInt; base::Int64 = 1000)
ret::MyBigInt = MyBigInt(:+, base, [])
while n > 0
push!(ret.digits, mod(n, ret.base))
n = div(n, ret.base)
end
return ret
end
# round trip test
to_base_big(from_base_big(n))
1234567890
In [38]:
1234567890
In [40]:
1234567890
In [12]: