I have this type and scaffolding:
import Base: convert, promote_rule, show, (*)
immutable FP64 <: AbstractFloat
fp::Float64
end
show(io::IO, a::FP64) = show(io, a.fp)
promote_rule{T<:AbstractFloat}(::Type{FP64}, ::Type{T}) = FP64
When I specify *
this way, it works.
(*)(x::FP64, y::FP64) = (FP64)(x.fp * y.fp)
(*){T<:AbstractFloat}(x::FP64, y::T) = (*)(promote(x, y)...)
(*){T<:AbstractFloat}(x::T, y::FP64) = (*)(promote(x, y)...)
FP64(5.0) * FP64(5.0)
25.0f0
When I specify *
this way , it does not work.
(*){T<:FP64}(x::T, y::T) = (T)(*)(x.fp, y.fp)
(*){T<:FP64}(x::T, y::T) = (T)(*)(x.fp, y.fp)
(*){T<:AbstractFloat}(x::FP64, y::T) = (*)(promote(x, y)...)
(*){T<:AbstractFloat}(x::T, y::FP64) = (*)(promote(x, y)...)
FP64(5.0) * FP64(5.0)
ERROR: MethodError: *(::FP64, ::FP64) is ambiguous. Candidates:
*{T<:FP64}(x::T, y::T) in Main
*{T<:AbstractFloat}(x::FP64, y::T) in Main
*{T<:AbstractFloat}(x::T, y::FP64) in Main
What is happening here (v"0.6-dev.2059")?