mirror of https://github.com/CGAL/cgal
Add a compare() for two rationals given as four values
This commit is contained in:
parent
be39ec02fa
commit
06f625a98e
|
|
@ -324,6 +324,36 @@ NT approximate_sqrt(const NT& nt)
|
||||||
return approximate_sqrt(nt, Sqrt());
|
return approximate_sqrt(nt, Sqrt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class NT>
|
||||||
|
Comparison_result
|
||||||
|
compare(const NT& xnum, const NT& xden,
|
||||||
|
const NT& ynum, const NT& yden)
|
||||||
|
{
|
||||||
|
// No assumptions on the sign of den are made
|
||||||
|
|
||||||
|
// code assumes that SMALLER == - 1;
|
||||||
|
CGAL_precondition( SMALLER == static_cast<Comparison_result>(-1) );
|
||||||
|
|
||||||
|
int xsign = sign(xnum) * sign(xden) ;
|
||||||
|
int ysign = sign(ynum) * sign(yden) ;
|
||||||
|
if (xsign == 0) return static_cast<Comparison_result>(-ysign);
|
||||||
|
if (ysign == 0) return static_cast<Comparison_result>(xsign);
|
||||||
|
// now (x != 0) && (y != 0)
|
||||||
|
int diff = xsign - ysign;
|
||||||
|
if (diff == 0)
|
||||||
|
{
|
||||||
|
int msign = sign(xden) * sign(yden);
|
||||||
|
NT leftop = NT(xnum * yden * msign);
|
||||||
|
NT rightop = NT(ynum * xden * msign);
|
||||||
|
return compare(leftop, rightop);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (xsign < ysign) ? SMALLER : LARGER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CGAL_NTS_END_NAMESPACE
|
CGAL_NTS_END_NAMESPACE
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue