Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promote_type(::Fixed, ::Rational) should return Fixed #261

Open
ParadaCarleton opened this issue Jan 15, 2023 · 3 comments
Open

promote_type(::Fixed, ::Rational) should return Fixed #261

ParadaCarleton opened this issue Jan 15, 2023 · 3 comments

Comments

@ParadaCarleton
Copy link

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.

@timholy
Copy link
Member

timholy commented Jan 16, 2023

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?

@ParadaCarleton
Copy link
Author

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?

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?

@timholy
Copy link
Member

timholy commented Jan 17, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants