Skip to content

Base.iszero not fully compatible using IntervalArithmetic values #667

Closed as duplicate

Description

@hsuknowledge

In their 1.0 update, the design of IntervalArithmetic changed so that Base.iszero will throw this error when value is an interval overlapping zero:

> iszero(interval(-1, 1))
ERROR: ArgumentError: `==` is purposely not supported for
overlapping non-thin intervals. See instead `isequal_interval`

A solution using isthinzero is thus suggested, which outputs false only if the compared value is a thin zero (no other floating-point values in the interval).

> 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))) ## false

Please consider updating compatibility with IntervalArithmetic again, thank you.

Note, that an Interval is a Real type, so it matches the second of the following rules (::Number) in your internal _iszero method:

@inline _iszero(x) = iszero(x) === true
@inline _iszero(x::Number) = iszero(x)
@inline _iszero(x::AbstractArray) = iszero(x)

Activity

  1. hsuknowledge commented on Jan 7, 2026

    @hsuknowledge
    Author

    This was in fact properly dealt with in their package in their /ext files. Closing this as non-issue and maybe marked as duplicate of the original issue/PR.

    Example:

    > mat; ## a SparseMatrixCSC of Float64
    > x = interval.(mat.nzval); x[1] = interval(-1, 1)
    > mat = (mat.m, mat.n, mat.colptr, mat.rowval, x);
    > dropzeros!(mat) ## does not throw error because `_iszero` is handled
    ## by dispatching to `IntervalArithmetic.isthinzero` in their compatibility code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions