Use the CGAL assertions/warnings/errors in Core

This commit is contained in:
Andreas Fabri 2023-03-09 13:12:32 +00:00
parent ca477995c9
commit 44d289396c
11 changed files with 40 additions and 71 deletions

View File

@ -194,8 +194,7 @@ void BigFloatRep :: truncM(const BigFloatRep& B, const extLong& r, const extLong
err = 2; err = 2;
exp = B.exp + t; exp = B.exp + t;
} else // t < chunkCeil(clLg(B.err)) } else // t < chunkCeil(clLg(B.err))
core_error(std::string("BigFloat error: truncM called with stricter") CGAL_error_msg("BigFloat error: truncM called with stricter precision than current error.");
+ "precision than current error.", __FILE__, __LINE__, true);
} else {// B.m == 0 } else {// B.m == 0
long t = chunkFloor(- a.asLong()) - B.exp; long t = chunkFloor(- a.asLong()) - B.exp;
@ -204,8 +203,7 @@ void BigFloatRep :: truncM(const BigFloatRep& B, const extLong& r, const extLong
err = 1; err = 1;
exp = B.exp + t; exp = B.exp + t;
} else // t < chunkCeil(clLg(B.err)) } else // t < chunkCeil(clLg(B.err))
core_error(std::string("BigFloat error: truncM called with stricter") CGAL_error_msg("BigFloat error: truncM called with stricter precision than current error.");
+ "precision than current error.", __FILE__, __LINE__, true);
} }
} }
@ -258,7 +256,7 @@ void BigFloatRep::div(const BigInt& N, const BigInt& D,
exp = 0; exp = 0;
} }
} else // D == 0 } else // D == 0
core_error( "BigFloat error: zero divisor.", __FILE__, __LINE__, true); CGAL_error_msg( "BigFloat error: zero divisor.");
// Call normalization globally -- IP 10/9/98 // Call normalization globally -- IP 10/9/98
normal(); normal();
@ -539,8 +537,7 @@ void BigFloatRep :: div(const BigFloatRep& x, const BigFloatRep& y,
bigNormal(bigErr); bigNormal(bigErr);
} }
} else {// y.m <= y.err } else {// y.m <= y.err
core_error("BigFloat error: possible zero divisor.", CGAL_error_msg("BigFloat error: possible zero divisor.");
__FILE__, __LINE__, true);
} }
// Call normalization globally -- IP 10/9/98 // Call normalization globally -- IP 10/9/98
@ -735,8 +732,7 @@ void BigFloatRep::sqrt(const BigFloatRep& x, const extLong& a, const BigFloat& A
} // end of case with error in mantissa } // end of case with error in mantissa
}//else }//else
} else } else
core_error("BigFloat error: squareroot called with negative operand.", CGAL_error_msg("BigFloat error: squareroot called with negative operand.");
__FILE__, __LINE__, true);
} //sqrt with initial approximation } //sqrt with initial approximation
// compareMExp(x) // compareMExp(x)
@ -823,8 +819,7 @@ BigFloatRep::toDecimal(unsigned int width, bool Scientific) const {
if (err > 0 && err >= abs(m)) { if (err > 0 && err >= abs(m)) {
// if err is larger than mantissa, sign and significant values // if err is larger than mantissa, sign and significant values
// can not be determined. // can not be determined.
core_error("BigFloat error: Error is too big!", CGAL_warning_msg(true, "BigFloat error: Error is too big!");
__FILE__, __LINE__, false);
decOut.rep = "0.0e0"; // error is too big decOut.rep = "0.0e0"; // error is too big
decOut.isScientific = false; decOut.isScientific = false;
decOut.noSignificant = 0; decOut.noSignificant = 0;
@ -1004,8 +999,7 @@ void BigFloatRep :: fromString(const char *str, extLong prec ) {
// NOTE: prec defaults to get_static_defBigFloatInputDigits() (see BigFloat.h) // NOTE: prec defaults to get_static_defBigFloatInputDigits() (see BigFloat.h)
// check that prec is not INFTY // check that prec is not INFTY
if (prec.isInfty()) if (prec.isInfty())
core_error("BigFloat error: infinite precision not allowed", CGAL_error_msg("BigFloat error: infinite precision not allowed");
__FILE__, __LINE__, true);
const char *e = strchr(str, 'e'); const char *e = strchr(str, 'e');
int dot = 0; int dot = 0;

View File

@ -176,7 +176,7 @@ void core_error(std::string msg, std::string file, int lineno, bool err) {
<< msg << std::endl; << msg << std::endl;
outFile.close(); outFile.close();
if (err) { if (err) {
std::cerr << (std::string("CORE ERROR") + " (file " + file + ", line " (std::string("CORE ERROR") + " (file " + file + ", line "
+ std::to_string(lineno) +"):" + msg + "\n").c_str(); + std::to_string(lineno) +"):" + msg + "\n").c_str();
std::exit(1); //Note: do not call abort() std::exit(1); //Note: do not call abort()
} }

View File

@ -72,9 +72,7 @@ public:
Expr(float f) : RCExpr(nullptr) { // check for valid numbers Expr(float f) : RCExpr(nullptr) { // check for valid numbers
// (i.e., not infinite and not NaN) // (i.e., not infinite and not NaN)
if (! CGAL_CORE_finite(f)) { if (! CGAL_CORE_finite(f)) {
core_error(" ERROR : constructed an invalid float! ", __FILE__, __LINE__, false); CGAL_error_msg("ERROR : constructed an invalid float! ");
if (get_static_AbortFlag())
abort();
get_static_InvalidFlag() = -1; get_static_InvalidFlag() = -1;
} }
rep = new ConstDoubleRep(f); rep = new ConstDoubleRep(f);
@ -83,9 +81,7 @@ public:
Expr(double d) : RCExpr(nullptr) { // check for valid numbers Expr(double d) : RCExpr(nullptr) { // check for valid numbers
// (i.e., not infinite and not NaN) // (i.e., not infinite and not NaN)
if (! CGAL_CORE_finite(d)) { if (! CGAL_CORE_finite(d)) {
core_error(" ERROR : constructed an invalid double! ", __FILE__, __LINE__, false); CGAL_error_msg("ERROR : constructed an invalid double! ");
if (get_static_AbortFlag())
abort();
get_static_InvalidFlag() = -2; get_static_InvalidFlag() = -2;
} }
rep = new ConstDoubleRep(d); rep = new ConstDoubleRep(d);
@ -173,9 +169,7 @@ public:
/// /= operator /// /= operator
Expr& operator/=(const Expr& e) { Expr& operator/=(const Expr& e) {
if ((e.rep)->getSign() == 0) { if ((e.rep)->getSign() == 0) {
core_error(" ERROR : division by zero ! ",__FILE__, __LINE__, false); CGAL_error_msg("ERROR : division by zero ! ");
if (get_static_AbortFlag())
abort();
get_static_InvalidFlag() = -3; get_static_InvalidFlag() = -3;
} }
*this = new DivRep(rep, e.rep); *this = new DivRep(rep, e.rep);
@ -376,9 +370,7 @@ inline Expr operator*(const Expr& e1, const Expr& e2) {
/// division /// division
inline Expr operator/(const Expr& e1, const Expr& e2) { inline Expr operator/(const Expr& e1, const Expr& e2) {
if (e2.sign() == 0) { if (e2.sign() == 0) {
core_error(" ERROR : division by zero ! ", __FILE__, __LINE__, false); CGAL_error_msg("ERROR : division by zero ! ");
if (get_static_AbortFlag())
abort();
get_static_InvalidFlag() = -4; get_static_InvalidFlag() = -4;
} }
return Expr(new DivRep(e1.Rep(), e2.Rep())); return Expr(new DivRep(e1.Rep(), e2.Rep()));
@ -479,9 +471,7 @@ inline bool isDivisible(const Expr& e1, const Expr& e2) {
/// square root /// square root
inline Expr sqrt(const Expr& e) { inline Expr sqrt(const Expr& e) {
if (e.sign() < 0) { if (e.sign() < 0) {
core_error(" ERROR : sqrt of negative value ! ", __FILE__, __LINE__, false); CGAL_error_msg("ERROR : sqrt of negative value ! ");
if (get_static_AbortFlag())
abort();
get_static_InvalidFlag() = -5; get_static_InvalidFlag() = -5;
} }
return Expr(new SqrtRep(e.Rep())); return Expr(new SqrtRep(e.Rep()));

View File

@ -564,9 +564,7 @@ public:
I = ss.isolateRoot(n); I = ss.isolateRoot(n);
// check whether n-th root exists // check whether n-th root exists
if (I.first == 1 && I.second == 0) { if (I.first == 1 && I.second == 0) {
core_error("CORE ERROR! root index out of bound", CGAL_error_msg("CORE ERROR! root index out of bound");
__FILE__, __LINE__, true);
abort();
} }
// test if the root isolated in I is 0: // test if the root isolated in I is 0:
if ((I.first == 0)&&(I.second == 0)) if ((I.first == 0)&&(I.second == 0))
@ -583,9 +581,7 @@ public:
ss.isolateRoots(I.first, I.second, v); ss.isolateRoots(I.first, I.second, v);
I = v.front(); I = v.front();
if (v.size() != 1) { if (v.size() != 1) {
core_error("CORE ERROR! non-isolating interval", CGAL_error_msg("CORE ERROR! non-isolating interval");
__FILE__, __LINE__, true);
abort();
} }
ffVal = computeFilteredValue(); // Chee: this line seems unnecessary ffVal = computeFilteredValue(); // Chee: this line seems unnecessary
} }
@ -1092,8 +1088,7 @@ void AddSubRep<Operator>::computeExactFlags() {
uMSB() = newValue.uMSB(); // chen: to get tighers value. uMSB() = newValue.uMSB(); // chen: to get tighers value.
sign() = newValue.sign(); sign() = newValue.sign();
} else if (lowBound.isInfty()) {//check if rootbound is too big } else if (lowBound.isInfty()) {//check if rootbound is too big
core_error("AddSubRep:root bound has exceeded the maximum size\n \ CGAL_warning_msg(false, "AddSubRep:root bound has exceeded the maximum size but we still cannot decide zero.");
but we still cannot decide zero.\n", __FILE__, __LINE__, false);
} else { // Op(first, second) == 0 } else { // Op(first, second) == 0
lMSB() = CORE_negInfty; lMSB() = CORE_negInfty;
sign() = 0; sign() = 0;
@ -1186,8 +1181,7 @@ void AddSubRep<Operator>::computeExactFlags() {
//8/9/01, Chee: implement escape precision here: //8/9/01, Chee: implement escape precision here:
if (i> get_static_EscapePrec()) { if (i> get_static_EscapePrec()) {
get_static_EscapePrecFlag() = -i.asLong();//negative means EscapePrec is used get_static_EscapePrecFlag() = -i.asLong();//negative means EscapePrec is used
core_error("Escape precision triggered at", CGAL_warning_msg(false, "Escape precision triggered");
__FILE__, __LINE__, false);
if (get_static_EscapePrecWarning()) if (get_static_EscapePrecWarning())
std::cout<< "Escape Precision triggered at " std::cout<< "Escape Precision triggered at "
<< get_static_EscapePrec() << " bits" << std::endl; << get_static_EscapePrec() << " bits" << std::endl;
@ -1204,8 +1198,7 @@ void AddSubRep<Operator>::computeExactFlags() {
#endif #endif
if (sign() == 0 && ua .isInfty()) { if (sign() == 0 && ua .isInfty()) {
core_error("AddSubRep: root bound has exceeded the maximum size\n \ CGAL_error_msg("AddSubRep: root bound has exceeded the maximum size but we still cannot decide zero.");
but we still cannot decide zero.\n", __FILE__, __LINE__, true);
} // if (sign == 0 && ua .isInfty()) } // if (sign == 0 && ua .isInfty())
}// else do progressive }// else do progressive
} }
@ -1236,8 +1229,7 @@ void AddSubRep<Operator>::computeApproxValue(const extLong& relPrec,
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "CORE WARNING: a huge lMSB in AddSubRep: " << lMSB(); oss << "CORE WARNING: a huge lMSB in AddSubRep: " << lMSB();
core_error(oss.str(), CGAL_warning_msg(false, oss.str().c_str());
__FILE__, __LINE__, false);
} }
extLong rf = first->uMSB()-lMSB()+relPrec+EXTLONG_FOUR; // 2 better extLong rf = first->uMSB()-lMSB()+relPrec+EXTLONG_FOUR; // 2 better

View File

@ -702,7 +702,7 @@ void computeExactFlags_temp(ConstRep* t, const Real &value) {
} else { } else {
t->uMSB() = value.uMSB(); t->uMSB() = value.uMSB();
t->lMSB() = value.lMSB(); t->lMSB() = value.lMSB();
core_error("Leaves in DAG is not exact!", __FILE__, __LINE__, true); CGAL_error_msg("Leafs in DAG is not exact!");
} }
t->sign() = value.sign(); t->sign() = value.sign();
@ -809,8 +809,7 @@ void SqrtRep::computeExactFlags() {
sign() = child->sign(); sign() = child->sign();
if (sign() < 0) if (sign() < 0)
core_error("squareroot is called with negative operand.", CGAL_error_msg("square root is called with negative operand.");
__FILE__, __LINE__, true);
uMSB() = child->uMSB() / EXTLONG_TWO; uMSB() = child->uMSB() / EXTLONG_TWO;
lMSB() = child->lMSB() / EXTLONG_TWO; lMSB() = child->lMSB() / EXTLONG_TWO;
@ -928,7 +927,7 @@ void DivRep::computeExactFlags() {
second->computeExactFlags(); second->computeExactFlags();
if (!second->sign()) if (!second->sign())
core_error("zero divisor.", __FILE__, __LINE__, true); CGAL_error_msg("zero divisor.");
if (!first->sign()) {// value must be exactly zero. if (!first->sign()) {// value must be exactly zero.
reduceToZero(); reduceToZero();
@ -1025,8 +1024,7 @@ void MultRep::computeApproxValue(const extLong& relPrec,
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "CORE WARNING: a huge lMSB in AddSubRep " << lMSB(); oss << "CORE WARNING: a huge lMSB in AddSubRep " << lMSB();
core_error(oss.str(), CGAL_warning_msg(false, oss.str().c_str());
__FILE__, __LINE__, false);
} }
extLong r = relPrec + EXTLONG_FOUR; extLong r = relPrec + EXTLONG_FOUR;
@ -1048,8 +1046,7 @@ void DivRep::computeApproxValue(const extLong& relPrec,
{ {
std::ostringstream oss; std::ostringstream oss;
oss << "CORE WARNING: a huge lMSB in AddSubRep " << lMSB(); oss << "CORE WARNING: a huge lMSB in AddSubRep " << lMSB();
core_error(oss.str(), CGAL_warning_msg(false, oss.str().c_str());
__FILE__, __LINE__, false);
} }
extLong rr = relPrec + EXTLONG_SEVEN; // These rules come from extLong rr = relPrec + EXTLONG_SEVEN; // These rules come from
@ -1082,7 +1079,7 @@ void Expr::debug(int mode, int level, int depthLimit) const {
else if (mode == Expr::TREE_MODE) else if (mode == Expr::TREE_MODE)
rep->debugTree(level, 0, depthLimit); rep->debugTree(level, 0, depthLimit);
else else
core_error("unknown debugging mode", __FILE__, __LINE__, false); CGAL_warning_msg(false, "unknown debugging mode");
std::cout << "---- End Expr debug(): " << std::endl; std::cout << "---- End Expr debug(): " << std::endl;
} }

View File

@ -137,8 +137,8 @@ public:
} }
/// division /// division
filteredFp operator/ (const filteredFp& x) const { filteredFp operator/ (const filteredFp& x) const {
if (x.fpVal == 0.0) CGAL_warning_msg(x.fpVal != 0.0, "possible zero divisor!");
core_error("possible zero divisor!", __FILE__, __LINE__, false);
double xxx = core_abs(x.fpVal) / x.maxAbs - (x.ind+1)*CORE_EPS + DBL_MIN; double xxx = core_abs(x.fpVal) / x.maxAbs - (x.ind+1)*CORE_EPS + DBL_MIN;
if (xxx > 0) { if (xxx > 0) {
double val = fpVal / x.fpVal; double val = fpVal / x.fpVal;
@ -149,8 +149,8 @@ public:
} }
/// square root /// square root
filteredFp sqrt () const { filteredFp sqrt () const {
if (fpVal < 0.0)
core_error("possible negative sqrt!", __FILE__, __LINE__, false); CGAL_warning_msg( !(fpVal < 0.0), "possible negative sqrt!");
if (fpVal > 0.0) { if (fpVal > 0.0) {
double val = std::sqrt(fpVal); double val = std::sqrt(fpVal);
return filteredFp(val, ( maxAbs / fpVal ) * val, 1 + ind); return filteredFp(val, ( maxAbs / fpVal ) * val, 1 + ind);

View File

@ -149,8 +149,7 @@ const extLong EXTLONG_EIGHT(8);
// private comparison function // private comparison function
inline int extLong::cmp(const extLong& x) const { inline int extLong::cmp(const extLong& x) const {
if (isNaN() || x.isNaN()) { if (isNaN() || x.isNaN()) {
core_error("Two extLong NaN's cannot be compared!", CGAL_warning_msg(false, "Two extLong NaN's cannot be compared!");
__FILE__, __LINE__, false);
} }
return (val == x.val) ? 0 : ((val > x.val) ? 1 : -1); return (val == x.val) ? 0 : ((val > x.val) ? 1 : -1);
} }

View File

@ -77,7 +77,7 @@ extLong& extLong::operator+= (const extLong& y) {
if (flag == 2 || y.flag == 2 || (flag * y.flag < 0)) { if (flag == 2 || y.flag == 2 || (flag * y.flag < 0)) {
#ifdef CORE_DEBUG #ifdef CORE_DEBUG
if (flag * y.flag < 0) //want a message at the first creation of NaN if (flag * y.flag < 0) //want a message at the first creation of NaN
core_error("extLong NaN Error in addition.", __FILE__, __LINE__, false); CGAL_warning_msg(false, "extLong NaN Error in addition.");
#endif #endif
*this = CORE_NaNLong; *this = CORE_NaNLong;
@ -96,7 +96,7 @@ extLong& extLong::operator-= (const extLong& y) {
if (flag == 2 || y.flag == 2 || (flag * y.flag > 0)) { if (flag == 2 || y.flag == 2 || (flag * y.flag > 0)) {
#ifdef CORE_DEBUG #ifdef CORE_DEBUG
if (flag * y.flag > 0) //want a message at the first creation of NaN if (flag * y.flag > 0) //want a message at the first creation of NaN
core_error("extLong NaN Error in subtraction.", __FILE__, __LINE__, false); CGAL_warning_msg(false, "extLong NaN Error in subtraction.");
#endif #endif
*this = CORE_NaNLong; *this = CORE_NaNLong;
@ -131,7 +131,7 @@ extLong& extLong::operator*= (const extLong& y) {
*this = CORE_negInfty; *this = CORE_negInfty;
} else { } else {
#ifdef CORE_DEBUG #ifdef CORE_DEBUG
core_error("extLong NaN Error in multiplication.",__FILE__,__LINE__,false); CGAL_warning_msg(false, "extLong NaN Error in multiplication.");
#endif #endif
*this = CORE_NaNLong; *this = CORE_NaNLong;
} }
@ -144,9 +144,9 @@ extLong& extLong::operator/= (const extLong& y) {
if (flag==2 || y.flag==2 || ((flag != 0) && (y.flag != 0)) || (y.val == 0)) { if (flag==2 || y.flag==2 || ((flag != 0) && (y.flag != 0)) || (y.val == 0)) {
#ifdef CORE_DEBUG #ifdef CORE_DEBUG
if (y.val == 0) if (y.val == 0)
core_error("extLong NaN Error, Divide by Zero.", __FILE__, __LINE__, false); CGAL_warning_msg(false, "extLong NaN Error, Divide by Zero.");
else if ((flag !=0) && (y.flag !=0)) else if ((flag !=0) && (y.flag !=0))
core_error("extLong NaN Error, +/-Inf/Inf.", __FILE__, __LINE__, false); CGAL_warning_msg(false, "extLong NaN Error, +/-Inf/Inf.");
#endif #endif
*this = CORE_NaNLong; *this = CORE_NaNLong;
@ -181,7 +181,7 @@ extLong extLong::operator- () const {
CGAL_INLINE_FUNCTION CGAL_INLINE_FUNCTION
int extLong::sign() const { int extLong::sign() const {
if (flag == 2) if (flag == 2)
core_error("NaN Sign can not be determined!", __FILE__, __LINE__, false); CGAL_warning_msg(false, "NaN Sign can not be determined!");
return ((val == 0) ? 0 : ((val > 0) ? 1 : -1)); return ((val == 0) ? 0 : ((val > 0) ? 1 : -1));
} }

View File

@ -1336,7 +1336,7 @@ cout <<"Number of roots at " << xCurr << " are " << numRoots<<endl;
if (!xCurr.isExact()){ if (!xCurr.isExact()){
std::ostringstream oss; std::ostringstream oss;
oss << "xCurr has error! xCurr=" << xCurr; oss << "xCurr has error! xCurr=" << xCurr;
core_error(oss.str(), __FILE__, __LINE__, false); CGAL_warning_msg(false, oss.str());
} }
}//main while loop }//main while loop
@ -1426,4 +1426,3 @@ void showIntervals(char* s, BFVecInterval &vI) {
/*************************************************************************** */ /*************************************************************************** */
// END // END
/*************************************************************************** */ /*************************************************************************** */

View File

@ -673,7 +673,7 @@ Polynomial<NT> Polynomial<NT>::pseudoRemainder (
int bTrueDegree = tmpB.degree; int bTrueDegree = tmpB.degree;
C = NT(1); // Initialized to C=1. C = NT(1); // Initialized to C=1.
if (bTrueDegree == -1) { if (bTrueDegree == -1) {
core_error("ERROR in Polynomial<NT>::pseudoRemainder :\n -- divide by zero polynomial", __FILE__, __LINE__, false); CGAL_warning_msg(false, "ERROR in Polynomial<NT>::pseudoRemainder :\n -- divide by zero polynomial");
return Polynomial(0); // Unit Polynomial (arbitrary!) return Polynomial(0); // Unit Polynomial (arbitrary!)
} }
if (bTrueDegree > degree) { if (bTrueDegree > degree) {

View File

@ -607,8 +607,7 @@ public:
if (ff == 0) { if (ff == 0) {
NEWTON_DIV_BY_ZERO = true; NEWTON_DIV_BY_ZERO = true;
del = 0; del = 0;
core_error("Zero divisor in Newton Iteration", CGAL_warning_msg(false, "Zero divisor in Newton Iteration");
__FILE__, __LINE__, false);
return 0; return 0;
} }
@ -680,8 +679,7 @@ public:
stepsize++; // heuristic stepsize++; // heuristic
} while ((del != 0) && ((del.uMSB() >= -prec) && (count >0))) ; } while ((del != 0) && ((del.uMSB() >= -prec) && (count >0))) ;
if (count == 0) core_error("newtonIterE: reached count=0", CGAL_assertion(count != 0, "newtonIterE: reached count=0");
__FILE__, __LINE__, true);
del = BigFloat(core_abs(del.m()), err, del.exp() ); del = BigFloat(core_abs(del.m()), err, del.exp() );
del.makeCeilExact(); del.makeCeilExact();
return val; return val;