]> git.ipfire.org Git - thirdparty/gcc.git/commit
[frange] Implement set_nonzero and nonzero_p. master trunk
authorAldy Hernandez <aldy@quesejoda.com>
Tue, 14 Jul 2026 17:27:25 +0000 (17:27 +0000)
committerAldy Hernandez <aldy@quesejoda.com>
Mon, 3 Aug 2026 13:08:19 +0000 (15:08 +0200)
commit3db020600d47180dc097f405d1dd7cfcafe24d43
treeba586ab98e249a4938c58964d355b249bed03d49
parent7decbb57670c3c0f6136be00456fe9c8a41f7aed
[frange] Implement set_nonzero and nonzero_p.

Excluding an interval is now expressible, and excluding zero is just
the [-0.0, +0.0] case of it, so say so.

For some stupid historical reason which I can't remember, the irange
and prange nonzero_p() predicates returns true only for ~[0,0], so
even [5,5] returns false.  When we want to test whether a range
contains a zero, we usually use the contains_p() idiom.  I think this
is idotic, but perhaps there is a reason for it.

I've implemented the frange version the same way, with the wrinkle
that the constructor for ~[-0.0, +0.0] includes the possibility of
+-NAN, which means that nonzero_p() must ignore the NAN bits,
otherwise anything but a strict ~[-0.0, +0.0] +-NAN would return
false.  For example, this:

x = frange(0.0, VR_ANTI_RANGE);
x.clear_nan();
x.nonzero_p(); <-- would return false

Tested on ppc64le Linux: regstrap and LAPACK.  Surprisingly there are
no changes to generated output in my Fortran files, presumably because
intersect/union are enough to fold inequalities away, and also because
there are no callers to nonzero_p() for frange.  Every nonzero_p()
call is guarded by prange or irange checks, but it's nice to
implement these since they are pure virtuals from the base vrange
class.

gcc/ChangeLog:

* value-range.cc (frange::set_nonzero): Implement.
(frange::nonzero_p): Implement.
(range_tests_excluding): Test set_nonzero and nonzero_p.
gcc/value-range.cc