JuliaIntervals / IntervalArithmetic.jl

Library for validated numerics using interval arithmetic
https://juliaintervals.github.io/IntervalArithmetic.jl/
Other
290 stars 70 forks source link

Compatibility with NaNMath.jl? #626

Open kapple19 opened 5 months ago

kapple19 commented 5 months ago

Having written some of my functions with NaNMath.jl versions of mathematical functions, feeding them Intervals results in a StackOverflowError.

E.g.

julia> ntv = interval(0, 1)
[0.0, 1.0]_com

julia> NaNMath.sin(ntv)
ERROR: StackOverflowError:
Stacktrace:
  [1] bareinterval(x::Interval{Float64})
    @ IntervalArithmetic C:\Users\Aaron\.julia\packages\IntervalArithmetic\7FL3g\src\intervals\construction.jl:298
  [2] float
    @ C:\Users\Aaron\.julia\packages\IntervalArithmetic\7FL3g\src\intervals\real_interface.jl:27 [inlined]   
  [3] sin(x::Interval{Float64}) (repeats 43500 times)
    @ NaNMath C:\Users\Aaron\.julia\packages\NaNMath\ceWIc\src\NaNMath.jl:11
  [4] eval
    @ .\boot.jl:385 [inlined]
  [5] eval
    @ .\Base.jl:88 [inlined]
  [6] repleval(m::Module, code::Expr, ::String)
    @ VSCodeServer c:\Users\Aaron\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:229
  [7] (::VSCodeServer.var"#110#112"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer c:\Users\Aaron\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:192
  [8] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging .\logging.jl:515
  [9] with_logger
    @ .\logging.jl:627 [inlined]
 [10] (::VSCodeServer.var"#109#111"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer c:\Users\Aaron\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\repl.jl:193
 [11] #invokelatest#2
    @ Base .\essentials.jl:887 [inlined]
 [12] invokelatest(::Any)
    @ Base .\essentials.jl:884
 [13] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer c:\Users\Aaron\.vscode\extensions\julialang.language-julia-1.66.2\scripts\packages\VSCodeServer\src\eval.jl:34

Any possibility of future compatibility?

Not sure if this is an issue to raise in NaNMath.jl or here.

My first guess would be to overload NaNMath functions with Interval arguments as a package extension? Maybe such an overload would call the regular Julia functions back.

Kolaru commented 5 months ago

There are two things here