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

Implement more num-traits (e.g. checked arithmetic) #86

Closed
Patiga opened this issue Nov 18, 2022 · 5 comments
Closed

Implement more num-traits (e.g. checked arithmetic) #86

Patiga opened this issue Nov 18, 2022 · 5 comments

Comments

@Patiga
Copy link
Contributor

Patiga commented Nov 18, 2022

num-traits has many traits not yet implemented by the Vec types.
I personally want the checked math traits, such as CheckedAdd. Without those traits, it's a much bigger hassle to write overflow-avoiding code.
For the sake of completeness, other traits, such as the wrapping ones (e.g. WrappingAdd) could also be implemented.

I'd be willing to implementing this myself.

@yoanlcq
Copy link
Owner

yoanlcq commented Nov 23, 2022

Hi, sorry for the delay.

I see... It looks to me like many such traits in num_traits are implemented on primitive types directly, instead of "any T where T has some trait", but that makes sense implementation-wise...

I think it would be best to go all-out and implement as many of those traits as possible, to make sure there is no need to come back to that later.

I'll try to do that today and get back to you.

Thanks

@Patiga
Copy link
Contributor Author

Patiga commented Nov 23, 2022

Thanks for the reply!
I'm really glad I found this crate. I was about to start my own point-crate, because all the other choices were problematic in some way for me. This one is pretty much exactly what I was aiming at. Love it :)

@yoanlcq
Copy link
Owner

yoanlcq commented Nov 23, 2022

Glad to hear that! :)
Out of curiosity, how did you end up finding it? I'm wondering because I didn't promote it, and to my knowledge there is no hugely popular project using it... It might just be that crates.io's search engine did a good job.

Just to let you know, I'm still working on your request, this is progressing slowly because I have very little time at the moment, but I'm not forgetting, and should push a commit soon (in 1 or 2 days I would guess).

@Patiga
Copy link
Contributor Author

Patiga commented Nov 24, 2022

Yeah, I didn't find vek as early as I would've liked.
First I used cgmath simply because it was the first thing that did what I wanted. Then my requirements grew, and I wrote my own point type. Since that single type would've grown quite big, I wanted to put it into its own crate, at which point I realized I should go looking for an already existing crate again. All the more popular crates I found didn't quite fit. I found vek when I randomly went through the tags that cgmath uses. vek is the third most downloaded crate under the tag quaternion right now.

Thanks for working on it, no need for rush :)
In case it consumes too much time, I can also try to figure it out myself

@yoanlcq
Copy link
Owner

yoanlcq commented Nov 27, 2022

It's now available in 0.15.9;

(could have been published earlier, but I initially thought there would be a need for a macro similar to vec_impl_binop!, but it turned out there wasn't).

That should do it, I'll close this issue but feel free to re-open if there is some stuff missing or such.

I think there are quite a few more traits that could be implemented, but at least those from num_traits::ops are done!

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