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

Checked Math for Composite Types #557

Open
nixpulvis opened this issue Aug 29, 2024 · 1 comment
Open

Checked Math for Composite Types #557

nixpulvis opened this issue Aug 29, 2024 · 1 comment

Comments

@nixpulvis
Copy link

I'd love to be able to do this, for example:

IVec3::ZERO.checked_div(10).ok_or(0)

Thanks.

@bitshifter
Copy link
Owner

I assume the return type of

IVec3::ZERO.checked_div(10).ok_or(0)

should be an IVec3, so it might look more like

IVec3::ZERO.checked_div(10).ok_or(IVec3::ZERO)

but that's dividing a vector by a scalar so most likely I'd also need

IVec3::ZERO.checked_div(IVec3::splat(10)).ok_or(IVec3::ZERO)

It would be a lot of new methods

A try_map<F>(f: F) -> Option<Self> might work for your example here, but while that might work for dividing by a scalar but it wouldn't work for dividing by a vector.

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