`promote_type(::Fixed, ::Rational)` should return `Fixed`
ParadaCarleton opened this issue · 3 comments
Julia suggests using Rational
numbers rather than floating-point literals, as floats are more disruptive. While good advice in general, this means code following the style guide will tend to disrupt fixed point numbers, since promote_type(::Fixed, ::Rational)
currently returns Rational
. I think we should flip this convention, to have fixed point numbers behave like floats in this regard.
You can convert
nearly every Fixed
number into a Rational
, but not vice-versa. If we made this change, we might get errors that currently aren't a problem. Are you arguing that's worth it?
You can
convert
nearly everyFixed
number into aRational
, but not vice-versa. If we made this change, we might get errors that currently aren't a problem. Are you arguing that's worth it?
I think it is, for consistency with Float
. I assume you're referring to cases where the Rational
is too big to be represented by a Fixed
number?
Yes.
I think it is, for consistency with Float.
Can you clarify how you reason about the consistency? Is it that "Rational
always loses"? (why?) Is it that FixedPoint
numbers print as float
?
To me, fixed-point numbers seem closer to Integer
or Rational
than AbstractFloat
:
julia> x = N0f8(0.8)
0.8N0f8
julia> x + x
0.596N0f8
That's not behavior you expect to see from a floating-point number. In what way do you think that float
is a better model?