What is rand(big(1:6))?

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).

1 Like

Note that this is corrected in the official docs, maybe you should read that instead?

2 Likes

julia> big(1)
1

julia> typeof(ans)
BigInt

julia> big(1.0)
1.0

julia> 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.

1 Like

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
1 Like

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.

1 Like