Julia Primitive Types
A primitive type is a type whose values are stored as plain bits with no fields inside. Int32 and Float32 are examples of primitive types.
Common number types are primitive
Int32, Float32, and UInt8 are primitive. Each test is true.
println(isprimitivetype(Int32))
println(isprimitivetype(Float32))
println(isprimitivetype(UInt8))Text is not primitive
String is not primitive. Bool is primitive.
println(isprimitivetype(String))
println(isprimitivetype(Bool))Primitive sizes are small and fixed
Int32 takes 4 bytes. UInt8 takes 1 byte. Float32 takes 4 bytes.
println(sizeof(Int32))
println(sizeof(UInt8))
println(sizeof(Float32))Example
a = Int32(7)
b = Float32(2.5)
println(typeof(a))
println(typeof(b))
println(isprimitivetype(typeof(a)))
println(a + Int32(3))Key points
- Primitive type: a primitive type stores values as plain bits with no fields inside.
- Primitive test: isprimitivetype tells whether a type is primitive.
- Integer size: Int32 uses 4 bytes of storage.
- Small integer: UInt8 uses 1 byte of storage.
- Decimal size: Float32 uses 4 bytes of storage.
In this example, an Int32 value and a Float32 value are made. Their types print as Int32 and Float32, the integer type tests as primitive, and adding 3 to 7 gives 10.
Note
String is not primitive.
Try it Yourself
Edit the code, then press Run.
Running is simulated · JuliaHub
Exercise
Which of these is a primitive type?