Skip to content

Usage of _iszero, _isnotzero #609

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

Closed
OlivierHnt opened this issue Mar 16, 2025 · 5 comments · Fixed by #610
Closed

Usage of _iszero, _isnotzero #609

OlivierHnt opened this issue Mar 16, 2025 · 5 comments · Fixed by #610

Comments

@OlivierHnt
Copy link
Contributor

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?

@ViralBShah
Copy link
Member

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

@SobhanMP
Copy link
Member

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

@OlivierHnt
Copy link
Contributor Author

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

LilithHafner pushed a commit that referenced this issue Mar 26, 2025
The purpose of this PR is to not call `==` directly, and use `_iszero`
instead. This is to help integration with
[IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl)
since `==` for our `Interval` type does not always return a Boolean.

Closes #609.

I did not change two checks using `===` since this would break the
behaviour for `-0.0`.
@LilithHafner
Copy link
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.

@OlivierHnt
Copy link
Contributor Author

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.

dkarrasch pushed a commit that referenced this issue May 11, 2025
The purpose of this PR is to not call `==` directly, and use `_iszero`
instead. This is to help integration with
[IntervalArithmetic.jl](https://github.com/JuliaIntervals/IntervalArithmetic.jl)
since `==` for our `Interval` type does not always return a Boolean.

Closes #609.

I did not change two checks using `===` since this would break the
behaviour for `-0.0`.
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