More NaN fixes for the non-SSE path.

This commit is contained in:
Marc Glisse 2019-10-30 17:27:00 +01:00
parent 81c7f53d20
commit 72548ecb2d
2 changed files with 24 additions and 2 deletions

View File

@ -639,6 +639,7 @@ private:
return IA (IA_opacify128(r));
# endif
#else
// TODO: try to move some NaN tests out of the hot path (test a.inf()>0 instead of >=0?).
if (a.inf() >= 0.0) // a>=0
{
// b>=0 [a.inf()*b.inf(); a.sup()*b.sup()]
@ -652,7 +653,8 @@ private:
if (b.sup() < 0.0)
bb = a.inf();
}
return IA(-CGAL_IA_MUL(aa, -b.inf()), CGAL_IA_MUL(bb, b.sup()));
double r = (b.sup() == 0) ? 0. : CGAL_IA_MUL(bb, b.sup()); // In case bb is infinite, avoid NaN.
return IA(-CGAL_IA_MUL(aa, -b.inf()), r);
}
else if (a.sup()<=0.0) // a<=0
{
@ -663,9 +665,10 @@ private:
if (b.inf() < 0.0)
{
aa=bb;
if (b.sup() < 0.0)
if (b.sup() <= 0.0)
bb=a.sup();
}
else if (b.sup() <= 0) return 0.; // In case a has an infinite bound, avoid NaN.
return IA(-CGAL_IA_MUL(-bb, b.sup()), CGAL_IA_MUL(-aa, -b.inf()));
}
else // 0 \in a

View File

@ -170,12 +170,31 @@ int main() {
Interval d(0,inf);
// For CGAL's purposes, [0,0]*anything is 0, but we tolerate larger intervals if they can be produced faster.
for (Interval I : { all*zero, zero*all, all*0., 0.*all, b*zero, zero*b, -b*zero, zero*-b, c*zero, zero*c, -c*zero, zero*-c })
{
//std::cout << I << '\n';
assert(I.inf()<=0 && I.sup()>=0);
}
// This should be [0,inf], but again we tolerate more.
for (Interval I : { a*b, b*a, -a*-b, -b*-a, d*d, -d*-d })
{
//std::cout << I << '\n';
assert(I.inf()<=0 && I.sup()==inf);
}
for (Interval I : { -a*b, -b*a, a*-b, b*-a, -d*d, d*-d })
{
//std::cout << I << '\n';
assert(I.inf()==-inf && I.sup()>=0);
}
for (Interval I : { all*a, a*all, all*-a, -a*all })
{
//std::cout << I << '\n';
assert(I.inf()==-inf && I.sup()==inf);
}
for (Interval I : { all*d, d*all, all*-d, -d*all })
{
//std::cout << I << '\n';
assert(I.inf()==-inf && I.sup()==inf);
}
}
{// external functions on Intervals
// functions (abs, square, sqrt, pow)