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

easier interop with floats #85

Open
benmkw opened this issue Oct 22, 2020 · 3 comments
Open

easier interop with floats #85

benmkw opened this issue Oct 22, 2020 · 3 comments

Comments

@benmkw
Copy link

benmkw commented Oct 22, 2020

Can TryFrom be implemented as well as FromPrimitive? This would make it easier to make conversions using .try_nto().

I would further propose to allow performing arithmetic between rationals and floats although this would mean that From would make more sense than TryFrom and errors would panic instead of returning an error.

@cuviper
Copy link
Member

cuviper commented Oct 22, 2020

TryFrom seems fine. It will need to be tested for compiler support, but you can see how num-bigint did that.

I think arithmetic between rationals and floats is a lot more problematic, so I'd rather leave that to explicit conversions.

@benmkw
Copy link
Author

benmkw commented Oct 22, 2020

Ok I see seems like I should be able to basically do exactly the same using cfg attributes and just forward to the FromPrimitive methods. The Results Error type would be empty though as they only return an Option.

@benmkw
Copy link
Author

benmkw commented Nov 19, 2020

I added methods for converting from ints as well (some require try_from/ some can be done through from as they should never fail). In some generic code I'm currently using them as they make it a bit less noisy.

Maybe you can take a look and say if this is too much or seems appropriate?

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