Skip to content

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

2 participants