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

Behavior of NAN as min/max for clamp_min/max #134

Closed
jturner314 opened this issue Sep 21, 2019 · 1 comment · Fixed by #135
Closed

Behavior of NAN as min/max for clamp_min/max #134

jturner314 opened this issue Sep 21, 2019 · 1 comment · Fixed by #135

Comments

@jturner314
Copy link
Contributor

#122 added clamp_min and clamp_max functions which preserve NANs in the input. I didn't see any discussion about what the best behavior is when the min/max argument is NAN, and I think it's worth considering before clamp_min/clamp_max are included in an official release. I think four different possible behaviors are reasonable when min/max is NAN:

  1. Panic in debug mode
  2. Panic in both debug and release mode
  3. Return input
  4. Return NAN

Option 1 matches num_traits::clamp. Option 2 matches (currently unstable) f32::clamp/f64::clamp. Option 3 is what the implementation currently does.

I lean towards option 1 for consistency with num_traits::clamp and because it avoids the question of whether option 3 or option 4 makes more sense.

Thoughts?

cc @termoshtt @cuviper

@cuviper
Copy link
Member

cuviper commented Sep 23, 2019

This is important to consider -- thanks for bringing it up! I think consistency with num_traits::clamp would be best -- panic in debug mode, and return input in release mode. Maybe in a future release (semver bumped) we could consider making them all always panic like the std clamp methods.

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

Successfully merging a pull request may close this issue.

2 participants