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

Missing implementations on references #81

Closed
lemmih opened this issue May 21, 2021 · 2 comments · Fixed by #82
Closed

Missing implementations on references #81

lemmih opened this issue May 21, 2021 · 2 comments · Fixed by #82

Comments

@lemmih
Copy link
Contributor

lemmih commented May 21, 2021

All the implementations for &NotNan are missing. Without an implementation for, say, &NotNan<T> - &NotNan<T>, these types cannot be used as drop-in replacements for f64 and f32. Ideally NotNan and OrderedFloat would implement exactly the same traits as f64 and f32.

mbrubeck added a commit that referenced this issue May 21, 2021
mbrubeck added a commit that referenced this issue May 21, 2021
@mbrubeck mbrubeck changed the title Missing implementations. Missing implementations on references May 21, 2021
@mbrubeck
Copy link
Collaborator

mbrubeck commented May 21, 2021

#82 implements the std::ops traits on reference types. Example:

fn not_nan<T: Float>(x: T) -> NotNan<T> { NotNan::new(x).unwrap() }

assert_eq!(not_nan(0.0) + not_nan(0.0), 0.0);
assert_eq!(not_nan(0.0) + &not_nan(0.0), 0.0);
assert_eq!(&not_nan(0.0) + not_nan(0.0), 0.0);
assert_eq!(&not_nan(0.0) + &not_nan(0.0), 0.0);

assert_eq!(not_nan(0.0) + 0.0, 0.0);
assert_eq!(not_nan(0.0) + &0.0, 0.0);
assert_eq!(&not_nan(0.0) + 0.0, 0.0);
assert_eq!(&not_nan(0.0) + &0.0, 0.0);

assert_eq!(OrderedFloat(0.0) + OrderedFloat(0.0), 0.0);
assert_eq!(OrderedFloat(0.0) + &OrderedFloat(0.0), 0.0);
assert_eq!(&OrderedFloat(0.0) + OrderedFloat(0.0), 0.0);
assert_eq!(&OrderedFloat(0.0) + &OrderedFloat(0.0), 0.0);

assert_eq!(OrderedFloat(0.0) + 0.0, 0.0);
assert_eq!(OrderedFloat(0.0) + &0.0, 0.0);
assert_eq!(&OrderedFloat(0.0) + 0.0, 0.0);
assert_eq!(&OrderedFloat(0.0) + &0.0, 0.0);

Let me know if I missed anything!

mbrubeck added a commit that referenced this issue May 21, 2021
@lemmih
Copy link
Contributor Author

lemmih commented May 23, 2021

Thanks!

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