I’m creating a numeric type (fixed point) and ran into the following problem when trying to print:
here’s the definition of the type
type Fixed{m, f} <: Real
x :: Int64
end
c = complex(a,b)
println(c)
ERROR: LoadError: no promotion exists for Fixed{1,15} and Int64
Stacktrace:
[1] promote_type(::Type{Fixed{1,15}}, ::Type{Int64}) at ./promotion.jl:161
[2] promote at ./promotion.jl:175 [inlined]
...
i tried defining a promote_type,
function promote_type(x::Fixed{m,f}, ::Type{Int64}) where {m,f}
x.x
end
and that gives me exactly the same error.
Then I realized, why is it trying to promote the type ?
if i do
println(a)
where a is Fixed{1,15}(0), i get the default representation,
Fixed{1,15}(0)
So it would seem that println(complex(a,b)) should simply use that representation for each of the real and imaginary parts. yes, this means that I haven’t defined a show method.
However defining a show method doesn’t seem to help.
function show(io::IO, x::Fixed{m,f}) where {m,f}
print(io, x.x)
end
ERROR: LoadError: no promotion exists for Fixed{1,15} and Int64
Stacktrace:
[1] promote_type(::Type{Fixed{1,15}}, ::Type{Int64}) at ./promotion.jl:161
I’ve been perusing the documentation and looking through FixedPointNumbers but can’t quite figure out what to try next.
Thanks,