-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
infinity-related functions shouldn't be generic over Num #4788
Comments
Yeah, I'm concerned about this. Warnings about failure is always worrying - it would be better if this could be enforced via the type system. I've been working hard at a refactor of the numeric modules, but this design issue is making it hard to merge: https://github.com/bjz/rust/tree/incoming/src/libcore/num From my perspective, infinities and NaNs should be defined in a separate Float trait like so:
|
Related: #4789 |
The current implementation:
|
Haskell uses a typeclass RealFloat: http://www.bucephalus.org/text/Haskell98numbers/Haskell98numbers.png |
Thanks for that, that's very useful. |
Just as in #4789, as the writer of these functions I'm aware that they are bad solution, but I needed them for being able to handle both integers and floats correctly in the string conversion functions. The problem is simple: If the inf and NaN functions are only reachable for Floats, then the only two options for a function that works with all numbers but has to special case inf and NaN are:
A possible solution might be a 'SpecialValue' trait where NaN, inf and -inf are an Option, depending on whether the numeric type has them or not, but that again would mean unnecessary impls... Really, maybe I'm being an Idiot here, or not giving it enough time, but I don't see how it's possible with the proposed system to write generic functions that can work with both integers and floats. :( |
See #4819 |
This can be closed now, those functions got removed again. |
Fixed in 3edc7c0 |
num::is_infinity, etc. are generic functions on the Num, One and Zero traits and do divides by zero. This doesn't make sense for integers.
The text was updated successfully, but these errors were encountered: