-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Guide: Fixing Inverse in Generics section #17224
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
Comments
(BTW, your replacement code can use fn inverse<T: Float>(x: T) -> Result<T, &'static str> {
if x.is_zero() { return Err("x cannot be zero!") }
Ok(std::num::one::<T>() / x)
} Not super important of course.) |
Thanks @huonw 👍 |
Is this still the way to go with the changes to |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Jan 13, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this issue
Jan 15, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the section on Generics, the inverse function is introduced which gives inverse of a
f32
andf64
. The section uses this following code to demonstrate the usage ofTraits
but then doesn't provide an example of how to fix the original problem.As a beginner, I found it a bit hard to make this work as the solution is quite unintuitive for someone new to rust.
It would be great if after the diversion to
Traits
the generics section closes off with a solution to theinverse
problem with a bit of explanation ofstd::num
module.The text was updated successfully, but these errors were encountered: