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

Feature request: Limiting precision #99

Open
ijustlovemath opened this issue Aug 12, 2021 · 2 comments
Open

Feature request: Limiting precision #99

ijustlovemath opened this issue Aug 12, 2021 · 2 comments

Comments

@ijustlovemath
Copy link

I'm using this library to losslessly model orbits in an n-body simulator, and I've noticed that after just a few iterations, the length of the data field seems to be growing quite rapidly; quadratically or exponentially is my guess. It would be useful to be able to do something like:

let mut n = Ratio::from_float(1.0).unwrap();
n.max_precision(20); // maximum number of digits in either numerator or denominator is now 20, lossy approximations afterwards

You could implement this using Farey fractions, see here: https://math.stackexchange.com/questions/2438510/can-i-find-the-closest-rational-to-any-given-real-if-i-assume-that-the-denomina

I may also just be unfamiliar with the API and don't see where this option exists

@ijustlovemath
Copy link
Author

One workaround, which may be somewhat wasteful, is the following:

let mut x = Ratio::from_float(1.1).unwrap();
// do something to update x...
x = Ratio::from_float(x.to_f64().unwrap()).unwrap();

@cuviper
Copy link
Member

cuviper commented Aug 23, 2021

I think it would be difficult to carry around a precision and maintain that throughout internal computation -- but it might not be so bad to offer some kind of "approximation" method to do this manually.

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

No branches or pull requests

2 participants