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

Bug in atomic for BigFloat arguments #410

Closed
cnaak opened this issue Sep 4, 2020 · 1 comment · Fixed by #567
Closed

Bug in atomic for BigFloat arguments #410

cnaak opened this issue Sep 4, 2020 · 1 comment · Fixed by #567

Comments

@cnaak
Copy link

cnaak commented Sep 4, 2020

In trying to make an Interval{BigFloat} out of 0.1 ± √eps(0.1), the resulting interval width is actually eps(0.1):

julia> FAV = BigFloat("0.1")
0.1000000000000000000000000000000000000000000000000000000000000000000000000000002

julia> EPS = eps(FAV)
1.039000033391147479886700654141525447676787907933243563752171509196807550877029e-39

julia> FAV ± EPS
0.09999999999999999999999999999999999999999999999999999999999999999999999999999914 ± 1.079521069386805578173293982850049946389500045554535173127962933771073975395304e-78

julia> eps(FAV)
1.079521069386805578173293982850049946389500045554535173127962933771073975395303e-78

The same happens if we change the strategy:

julia> LO = FAV - EPS
0.09999999999999999999999999999999999999896099996660885252011329934585847455232392

julia> HI = FAV + EPS
0.1000000000000000000000000000000000000010390000333911474798867006541415254476765

julia> LO..HI
0.09999999999999999999999999999999999999999999999999999999999999999999999999999914 ± 1.079521069386805578173293982850049946389500045554535173127962933771073975395304e-78

Digging on the code, I've found that .. calls atomic, which calls rationalize, which should have a BigInt first argument for BigFloat numbers:

julia> rationalize(HI)
1//10

julia> rationalize(BigInt, HI)
105871026433921985079814859890155025049//1058710264339219850798148598901550250479

So that the following workaround produces the desired Interval:

julia> atomic = IntervalArithmetic.atomic
atomic (generic function with 13 methods)

julia> interval(atomic(Interval{BigFloat}, rationalize(BigInt, LO)).lo,
                atomic(Interval{BigFloat}, rationalize(BigInt, HI)).hi)
0.1000000000000000000000000000000000000000000000000000000000000000000000000000013 ± 1.039000033391147479886700654141525447677370932472424860032427799066497795404064e-39
@dpsanders
Copy link
Member

I definitely don't think we should always use BigInt.

In any case the whole conversion and atomic stuff really needs to be rewritten.
Currently there seem to be many conversions that are far too slow because they are going through atomic and trying to be too clever.

We should reduce all the cleverness and use it only when using @interval and the string macros.

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.

3 participants