-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
surprising NaN in conversion from f64 #112
Comments
Hi @majewsky, thanks for reporting this! |
Hi @majewsky, Longer explanation:
If you use either |
I suspected something like this. Would it then make sense to have this be an |
I agree. We should cater try_from for more reliable conversions.
|
I randomly came across how another similar library solves this problem, and will leave this here as potential inspiration. The bigint/bigfloat implementation in the Go standard library provides a cast from floating-point numbers into I don't know whether it is feasible to actually obtain the required information from the float-to-fraction conversion algorithm that you're using, but from an API design perspective, it would be nice to have, say: impl TryFrom<f64> for GenericFraction<u64> {
type Error = LossOfPrecisionError<GenericFraction<u64>>; // placeholder name
}
struct LossOfPrecisionError<F> {
best_estimate: F,
// ...other fields to describe the loss of precision...
// (e.g. the Go library reports whether the estimate is below or above the true value)
} Library users could then decide to |
Thanks for the feedback. I agree, that's one of the sensible ways to do that. The current from logic was implemented years ago before |
This test fails:
The text was updated successfully, but these errors were encountered: