Int and float functions

Just a question: Why is the Int function capitalized and the float function lower-case?

julia> 0x0001 |> Int

julia> 0x0001 |> float

julia> 0x0001 |> Float
ERROR: UndefVarError: `Float` not defined
 [1] top-level scope
   @ REPL[120]:1

julia> 0x0001 |> int
ERROR: UndefVarError: `int` not defined
 [1] top-level scope
   @ REPL[121]:1

thanks !

julia> 0x0001 |> Float64
1 Like

Thanks for the answer, but it doesn’t really answer the question, which is more of a typographical nature.

Int and float both make the assumption of stockage on 64 bytes.

julia> typeof(0x0001 |> Int)

julia> typeof(0x0001 |> Int64)

julia> typeof(0x0001 |> float)

julia> typeof(0x0001 |> Float64)

Neither is correct. Int is an alias for a type, Int32 on 32-bit systems, Int64 on 64-bit systems. The method of float you invoke forwards to AbstractFloat, whose methods are mostly implemented to forward to Float64, but that’s not a guarantee for all possible methods e.g. AbstractFloat(big(1)). Moreover, the float function has other methods that don’t return an AbstractFloat type, e.g. float(1:5). It’s not a type constructor.


Int is a type name, and the name of the constructor of that type, not just a regular function, and all types are CapitalCase, by convention.

float, on the other hand, is not a type name, and not a constructor.


Int is an alias for the system native integer type. That is usually Int64 these days. For 32-bit systems, it will be Int32.

Importantly since this refers to a specific type, Int(x) will always return Int.

float is not a direct alias for a specific floating point type such as Float64. It can and does return distinct types depending on the input.

julia> Int(0x8) |> typeof

julia> float(8.f5) |> typeof

julia> float(8.5) |> typeof

julia> float(5 + 7im) |> typeof
ComplexF64 (alias for Complex{Float64})

Int and float are thus not analogous functions. Often if you wanted to convert a non-integer type to an integer you would need to do something such as round(Int, x).

1 Like

I am more curious to know why there is no int while there is a float.

1 Like

int-ifying runs into rounding or magnitude issues far more easily, and there’s no convenient default way to handle those, so might as well manually do it with a bunch of other functions and arguments.