What's the difference between Float64 and Real? And what is the Real type for?

Pardon this naive question but: what exactly is the difference between Float64 and Real? For example, say we have:

a = [1.0, 2.0, 3.0] 
b = Array{Real,1}(a)

When I call typeof() on each, it reports the types as Vector{Float64} and Vector{Real}, respectively. But how are a and b different, and in what ways do they behave differently? It seems to me that applying arithmetic operations to b (e.g. b.^2, b .+ b, etc.) just gives back an object of type Vector{Float64}…So what is the point of Real numbers?

Real is an abstract type, while Float64 is a concrete type.

Int64 <: Real and Float64 <: Real

Abstract types don’t carry any information on memory layout. They are used to organize methods and organize types. See the docs here.

3 Likes
julia> Int64 isa Real
false

I think you meant

julia> Int64 <: Real
true
1 Like

If you want to write a function that accepts Float32 and Float64 and Int64 and Rational etc. But not complex numbers. Then Real is there for you.

And Vector{Real} is a container that accepts all those different number types that are subtypes of Real.

7 Likes