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

Incorrect rounding for extreme irrationals #616

Closed
Joel-Dahne opened this issue Jan 17, 2024 · 1 comment · Fixed by #617
Closed

Incorrect rounding for extreme irrationals #616

Joel-Dahne opened this issue Jan 17, 2024 · 1 comment · Fixed by #617

Comments

@Joel-Dahne
Copy link
Contributor

See 52941 and my comment in #615.

The rounding of irrationals in Base Julia is not fully rigorous and can give incorrect results in extreme cases. This has as a consequence that intervals constructed from irrationals are not guaranteed to enclose them. For example, defining the irrational $1 - \pi^{-300}$ gives us

julia> Base.@irrational almost_one (1 - big(π)^-300)

julia> almost_one
almost_one = 1.0...

julia> Float64(almost_one, RoundDown)
1.0

julia> interval(almost_one)
[1.0, 1.0]_com

where the interval clearly doesn't contain the irrational.

For Base Julia these types of extreme cases are maybe fine to not get fully correct. For interval arithmetic not so much. I would propose to limit the construction of intervals from irrationals to only those irrationals which are implemented in mpfr, which are Irrational{:π}, Irrational{:γ} and Irrational{:catalan}. One could also support Irrational{:ℯ}, but one has to call mpfr directly since the regular constructor doesn't expose the rounding parameter.

Note that the constructors in src/constructors.jl under the comment

# by-pass the absence of `BigFloat(..., ROUNDING_MODE)` (cf. base/irrationals.jl)
# for some irrationals defined in MathConstants (cf. base/mathconstants.jl)

are not safe, as by the above the rounding to Float64 is not safe.

@OlivierHnt
Copy link
Member

Indeed.. Hopefully PR #617 addresses this issue correctly.

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

Successfully merging a pull request may close this issue.

2 participants