-
Notifications
You must be signed in to change notification settings - Fork 78
Description
The package IntervalArithmetic intentionally raises error for comparisons between an interval enclosing multiple floating-point values and an interval with a single value, so-called thin interval, when the two sets overlap. Base.iszero(x) dispatchs to x == 0 so this is a comparison with a thin interval and will throw if x is an interval covering a zero.
> using IntervalArithmetic
> a = interval(-1, 1) ## spans across zero
> iszero(a)
ERROR: ArgumentError: `==` is purposely not supported for
overlapping non-thin intervals. See instead `isequal_interval`On the other hand, IntervalArithmetic has a new function that serves the purpose, isthinzero, which allows this comparison to move on and only emit true if x does not enclose any other value.
> isthinzero(interval(-0,0)) ## true
> isthinzero(interval(-0.0,0.0)) ## true
> isthinzero(interval(prevfloat(-0.0),0.0)) ## false
> isthinzero(interval(0.0,nextfloat(0.0))) ## falseThis is likely the behavior Polynomials authors want. Please consider adding this support to this package, otherwise end users like me are going to patch it with type piracy and mess up with other dependent packages.
Quoting a maintainer at IntervalArithmetic, a "safe iszero" (inside Polynomials module) approach is suggested.
The recommended approach (followed, e.g., by
SparseArrays) is to define your own method defaulting toiszerounless the input is an interval. This allows you to not breakIntervalArithmetic(which would occur by directly overloadingBase.iszero), preserving reliability, and you get a finer control on the behaviour. E.g.,
module MyModule
# ... some code...
_safe_iszero(x) = iszero(x)
_safe_iszero(x::Interval) = isthinzero(x)
end