IntervalArithmetic.jl icon indicating copy to clipboard operation
IntervalArithmetic.jl copied to clipboard

Incorrect construction of Interval{Float64} from Rational{Int}

Open saschatimme opened this issue 3 years ago • 4 comments

The rational number 1//10 does not have an exact floating point representation. However currently

julia> x = Interval{Float64}(1//10)
[0.1, 0.100001]

julia> x.lo == x.hi
true

So the interval [x.lo,x.hi] can definitely not contain 1//10.

The relevant codepath is https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/d3a318c6356515ee2d2a0c47ab7af419dea106ea/src/intervals/intervals.jl#L65

saschatimme avatar Aug 10 '20 09:08 saschatimme

Rounding is handled by the @interval macro, which generates correctly-rounded intervals.

julia> x = @interval(1//10)
Interval(0.09999999999999999, 0.1)

julia> x.lo == x.hi
false

krish8484 avatar Aug 10 '20 22:08 krish8484

Many thanks for clarifying this.

saschatimme avatar Aug 11 '20 05:08 saschatimme

I think that the original point is valid though - the result should be an Interval contiaing 1//10.

dpsanders avatar Aug 11 '20 05:08 dpsanders

As it is for pi, for example.

dpsanders avatar Aug 11 '20 05:08 dpsanders

This is resolved on master.

OlivierHnt avatar Sep 05 '23 12:09 OlivierHnt