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

Interval creation with .. returns inconsistent types #416

Closed
remi-garcia opened this issue Sep 21, 2020 · 8 comments · Fixed by #567
Closed

Interval creation with .. returns inconsistent types #416

remi-garcia opened this issue Sep 21, 2020 · 8 comments · Fixed by #567

Comments

@remi-garcia
Copy link

I find it strange that:

julia> typeof(Float16(0)..Float32(0.5))
Interval{Float32}

julia> typeof(Int(0)..Float32(0.5))
Interval{Float64}

I would think that typeof(Int(0)..Float32(0.5)) == Interval{Float32}

@dpsanders
Copy link
Member

You're right that that seems wrong according to Julia's standard promotion mechanism:

julia> promote(1, 3.5f0)
(1.0f0, 3.5f0)

@dpsanders
Copy link
Member

That is due to using ... If you use interval it behaves as expected:

julia> interval(Int(0), Float32(0.5)) |> typeof
Interval{Float32}

@dpsanders
Copy link
Member

But yes this should be fixed.

@remi-garcia
Copy link
Author

I don't find what should be the differences between Interval(a, b), interval(a, b) and a..b. To solve this issue that information would help me.

@Kolaru
Copy link
Collaborator

Kolaru commented Sep 22, 2020

Interval is the direct construsctor, interval checks the bounds and is slightly safer and slower but otherwise equivalent. .. in the other hand tries to be clever, and thus its behavior is not very well defined, but as mentionned in #396 we should probably not do it and rather rely on macro for the cleverness.

@Kolaru Kolaru changed the title Declaring interval and type promoting Interval creation with .. returns inconsistent types Sep 22, 2020
@lbenet
Copy link
Member

lbenet commented Sep 22, 2020

Just to clarify with an example what @Kolaru wrote above, interval(2, 1) throws an error because the lower bound is larger than the upper one, while Interval(2, 1) does not throw any error.

Regarding .., the next example is a nice illustration:

julia> using IntervalArithmetic

julia> setformat(:full);

julia>  a = Interval(0.1,0.25)
Interval(0.1, 0.25)

julia> b = 0.1 .. 0.25
Interval(0.09999999999999999, 0.25)

julia> 1//10  a
false

julia> 1//10  b
true

So the "cleverness" to which @Kolaru referred is related to "correct" (outer) rounding.

@dpsanders
Copy link
Member

This is explained in the docs: https://juliaintervals.github.io/IntervalArithmetic.jl/stable/construction/

@remi-garcia
Copy link
Author

I'll put a RTFM on the side of my screen. Sorry.

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.

4 participants