Skip to content

Usage of _iszero, _isnotzero #609

Closed

Description

@OlivierHnt

We are currently working on releasing the 1.0 version of IntervalArithmetic.jl (see JuliaIntervals/IntervalArithmetic.jl#698). One important decision we made is to be very strict with the usage of boolean comparison functions from Base. For instance, iszero(x::Interval) throws if x contains zero but is not thin, like $[-1, 1]$.

I noticed that you have two internal functions _iszero and _isnotzero which seems to be used only in the context "is the number exactly zero".

I found (on 1.11, but maybe also true on 1.10) that this is not used everywhere, e.g.

https://github.com/JuliaSparse/SparseArrays.jl/blob/242035184c0d539bdb5e64bf26eb7726b123db14/src/sparsevector.jl#L2384C8-L2384C21

Is it possible to replace all instances of x == zero(x) (and similar) with _iszero (or _isnotzero) ? If so, could this be backported to 1.10 and 1.11 as well?

Activity

  1. ViralBShah commented on Mar 16, 2025

    @ViralBShah
    Member

    Should be ok in principle. Are you able to put a PR?

  2. SobhanMP commented on Mar 17, 2025

    @SobhanMP
    Member

    I think it's probably worth reading the comments in #296, in short beware that -0 is a bit weird.

  3. OlivierHnt commented on Mar 17, 2025

    @OlivierHnt
    ContributorAuthor

    Thx for the heads up 🙂. I'll make a PR, we can discuss the backporting procedure then.

  4. LilithHafner commented on Mar 26, 2025

    @LilithHafner
    Member

    I expect that you'll need to return missing or IntervalArithmatic.Unknown() or some such or declare a weak dependency on SpareArrays because iszero(x) === true still throws if iszero(x) throws.

  5. OlivierHnt commented on Mar 26, 2025

    @OlivierHnt
    ContributorAuthor

    Thanks for having a look at this issue. We do have SparseArrays as a weak dependency for the tentative 1.0 (JuliaIntervals/IntervalArithmetic.jl#698) which uses the _iszero and _isnotzero hooks.

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