I’m reading the Julia documentation following this link: https://fredrikekre.github.io/stdlib/Random.html
and I encounter this one line of code:
rand(big(1:6))
Somehow I can not find out this big(1:6)
? Could anyone tell me what is this?
It’s not valid anymore, it used to mean what we write now big.(1:6)
, or big(1):big(6)
.
Note that this is corrected in the official docs, maybe you should read that instead?
julia> big(1)
1julia> typeof(ans)
BigIntjulia> big(1.0)
1.0julia> typeof(ans)
BigFloat
I checked the big function, it looks like this function will return the big counterpart of the input parameter. I guess the main difference between Int and BigInt is that, BigInt has a big interval?
BigInt
represents arbitrary precision integers, basically limited only by the RAM of the computer.
Very good explanations. Is there a way to print out this BigInt
representation of, say the number 1?
Yes, though its unlikely to be of any help. BigInts are powered by a C library (GMP).
julia> BigInt(1)
1
julia> dump(BigInt(1))
BigInt
alloc: Int32 1
size: Int32 1
d: Ptr{UInt64} @0x0000000030cac110
Thank you. I guess this @0x0000000030cac110
means the number 1 is stored at this memory location?
It means that the GMP library internal structure for this 1 is stored there.
The alloc
and size
fields are also part of the representation.
julia> a = BigInt(1)
1
julia> b = BigInt(1)
1
julia> dump(a)
BigInt
alloc: Int32 1
size: Int32 1
d: Ptr{UInt64} @0x000000000af3bcb0
julia> dump(b)
BigInt
alloc: Int32 1
size: Int32 1
d: Ptr{UInt64} @0x000000000af3bf60
The pointers are different.