Docstrings

EltypeExtensions._to_precisiontypeMethod
_to_precisiontype(T::Type, S::Type)

Convert type S to have the precisiontype of T. An exception is that if T<:Integer, then Rational will also be unwrapped.

Examples

julia> _to_precisiontype(Float64, Complex{Rational{Int}})
ComplexF64 (alias for Complex{Float64})

julia> _to_precisiontype(BigFloat, Matrix{Complex{Bool}})
Matrix{Complex{BigFloat}} (alias for Array{Complex{BigFloat}, 2})

julia> _to_precisiontype(Int, Complex{Rational{BigInt}})
Complex{Rational{Int64}}
EltypeExtensions.basetypeMethod
basetype(T::Type)

Recursively apply eltype to T until convergence.

Examples

julia> basetype(Matrix{BitArray})
Bool

julia> basetype(Vector{Set{Complex{Float64}}})
ComplexF64 (alias for Complex{Float64})

julia> basetype([1:n for n in 1:10])
Int64
EltypeExtensions.elconvertMethod
elconvert(T, A)

Similar to convert(T, A), but T refers to the eltype.

Examples

julia> elconvert(Float64, 1:10)
1.0:1.0:10.0

julia> typeof(elconvert(Float64, rand(Int, 3, 3)))
Matrix{Float64} (alias for Array{Float64, 2})
EltypeExtensions.precisionconvertMethod
precisionconvert(T::Type, A, prec)

Convert A to have the precisiontype of T. prec is optional.

  • When T has static precision (e.g. Float64), prec has no effect.
  • When T has dynamic precision (e.g. BigFloat), prec specifies the precision of conversion. When prec is not provided, the precision is decided by the external setup from T.
  • When T is an integer, the conversion will dig into Rational as well. In contrast, since Rational as a whole is more "precise" than an integer, precisiontype doesn't unwrap Rational.

Examples

julia> precisionconvert(BigFloat, 1//3+im, 128)
0.3333333333333333333333333333333333333338 + 1.0im

julia> precisionconvert(Float16, [[m/n for n in 1:3] for m in 1:3])
3-element Vector{Vector{Float16}}:
 [1.0, 0.5, 0.3333]
 [2.0, 1.0, 0.6665]
 [3.0, 1.5, 1.0]
EltypeExtensions.precisiontypeMethod
precisiontype(T::Type)

Returns the type that decides the precision of T. The difference from basetype is that precisiontype unwraps composite basetypes such as Complex and that precisiontype is not generalised.

Examples

julia> precisiontype(Complex{Float32})
Float32

julia> precisiontype(Matrix{ComplexF64})
Float64