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

Intervalize contents of Aff #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Intervalize contents of Aff #19

wants to merge 1 commit into from

Conversation

dpsanders
Copy link
Member

@dpsanders dpsanders commented Mar 10, 2020

This attempts to fix #14 in the most naive way: make everything stored inside the Aff type (the internal component that does the affine calculation) into an interval when the Aff object is first created.

The result of the example in #14 is as follows after this PR:

julia> Affine(-1..1) + Affine(1e23) + Affine(2020.0) - Affine(1e23)
affine=⟨[0, 1.67773e+07]; Interval{Float64}[[1, 1]]; [0, 0]⟩; range=[-1, 1.67773e+07]

Due to the precision of Float64 I don't think we can expect a better answer than this.
However, with BigFloat we get

julia> Affine(big(-1..1)) + Affine(big(1e23)) + Affine(big(2020.0)) - Affine(big(1e23))
affine=⟨[2020, 2020]₂₅₆; Interval{BigFloat}[[1, 1]₂₅₆]; [-0, 0]₂₅₆⟩; range=[2019, 2021]₂₅₆

which is correct!

(Note that there are some missing promotions to do Affine(-1..1) + Affine(big(1)).)

This PR surely does not give the fastest code, but at least it seems to be correct...

cc @mforets @RockerM4NHUN

@dpsanders
Copy link
Member Author

Tests need updating.

@dpsanders
Copy link
Member Author

The strange number in the above calculation is coming from

julia> nextfloat(1e23) - 1e23
1.6777216e7

julia> x = interval(1e23) + interval(2020)
Interval(1.0e23, 1.0000000000000001e23)

julia> x.hi == nextfloat(x.lo)
true

@dpsanders
Copy link
Member Author

In other words,

julia> eps(1e23)
1.6777216e7

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 this pull request may close these issues.

Incorrect result for addition with widely-varying floating point numbers
1 participant