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

Calculate number of representable values between two BigFloats #29

Open
exoriente opened this issue Jun 21, 2024 · 3 comments
Open

Calculate number of representable values between two BigFloats #29

exoriente opened this issue Jun 21, 2024 · 3 comments

Comments

@exoriente
Copy link

exoriente commented Jun 21, 2024

Hi @stencillogic,

Is there a way to determine how close two BigFloats are to each other in terms of number of representable values, given a certain precision? I need it for an application in which I want to gradually increase precision and discover automatically whether or not it's time to increase precision as the algorithm zooms in further.

Some background: As a practice project to take some first steps in the Rust language, I'm building a small application that allows you to explore the Mandelbrot fractal. It allows the user to zoom in further and further into an area in the complex plane and I'm enlarging smaller and smaller parts of the fractal to render them on screen. Currently I'm using f64 to represent the complex coordinates, but that allows you to zoom in only so far. I would like to switch to BigFloat and to increase the precision automatically when necessary. I'm looking for a way to judge whether the current precision still suffices.

Is there a way to do something like this: n = representable_values_between(x, y, p) with n being an integer representing the number of floating point values that can be represented at precision p, that are larger or equal than x and smaller than y?

Let me know if the issue is clear. If not, I can explain further.

@stencillogic
Copy link
Owner

Hi,

Thanks for raising the issue. There is no such or in some way similar function in the library. You may want to implement it yourself.

@exoriente
Copy link
Author

Thanks for your quick response. Do you plan on implementing a feature like next_up and next_down for BigFloat? See: https://doc.rust-lang.org/std/primitive.f64.html#method.next_up . That would give some hand holds to do it manually, like here: https://stackoverflow.com/questions/55049251/how-many-values-can-be-represented-in-a-given-range-by-a-float.

@stencillogic
Copy link
Owner

Good idea! Created a new issue for it: #30
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

No branches or pull requests

2 participants