struct MyBigInt
::Symbol
sign::Int
base::Vector{Int64}
digitsend
= MyBigInt(:+, 1000, Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0])) p1
# example value in Julia's Base.BigInt
::BigInt = 1234567890
n
# some functions to test my implementation
function to_base_big(n::MyBigInt)
::BigInt = 0
retfor i in 1:length(n.digits)
+= BigInt(n.digits[i]) * n.base ^ (i - 1)
ret end
return ret
end
function from_base_big(n::BigInt; base::Int64 = 1000)
::MyBigInt = MyBigInt(:+, base, [])
retwhile n > 0
push!(ret.digits, mod(n, ret.base))
= div(n, ret.base)
n end
return ret
end
# round trip test
to_base_big(from_base_big(n))
1234567890
div(n, 1000)
1234567
1234567890
from_base_big(n)
MyBigInt(:+, 1000, [890, 567, 234, 1])
::BigInt = 0
retfor i in 1:length(n.digits)
+= BigInt(n.digits[end - i]) * n.base * (i - 1)
ret end
ErrorException: type BigInt has no field digits
for i in 10:-1:1
println(i)
end
10
9
8
7
6
5
4
3
2
1