January 2020
Intermediate to advanced
532 pages
13h 31m
English
Julia does not automatically perform conversion on data types for safety reasons. Every conversion must be explicitly defined by the programmer.
To make it easier for everyone, Julia already contains conversion functions for numeric types by default. For instance, you can find this interesting piece of code from the Base package:
convert(::Type{T}, x::T) where {T<:Number} = xconvert(::Type{T}, x::Number) where {T<:Number} = T(x)
Both functions take the first argument of the Type{T} type, where T is a subtype of Number. Valid values include all standard numeric types, such as Int64, Int32, Float64, Float32, and so on.
Let's try to understand these two functions further:
Read now
Unlock full access