fix setting an invalid epsilon

Setting an invalid epsilon via the epsilon(value) or confiv("epsilon",
value) triggers an error.  The epsilon value must be: 0 < epsilon < 1.
This commit is contained in:
Landon Curt Noll
2023-08-31 03:20:38 -07:00
parent e021e2130f
commit b95a62c14e
3 changed files with 28 additions and 4 deletions

28
qfunc.c
View File

@@ -43,6 +43,29 @@ STATIC long E_num;
#define QALLOCNUM 64
/*
* verify_epsilon - verify that 0 < epsilon < 1
*
* This function is called via the OP_SETEPSILON op code, config("epsilon",
* and from various builtin functions that take an epsilon argument.
*
* If all is well, this function just returns. If the arg passed is
* out of range, then a math_error() is triggered causing this function
* to not return.
*/
void
verify_epsilon(NUMBER *q)
{
/* verify that 0 < epsilon < 1 */
if (q == NULL || qisneg(q) || qiszero(q) || qisone(q) || qreli(q, 1) > 0) {
math_error("Invalid value for epsilon: must be: 0 < epsilon < 1");
not_reached();
}
return;
}
/*
* Set the default epsilon for approximate calculations.
* This must be greater than zero.
@@ -55,10 +78,7 @@ setepsilon(NUMBER *q)
{
NUMBER *old;
if (qisneg(q) || qiszero(q)) {
math_error("Epsilon value must be greater than zero");
not_reached();
}
verify_epsilon(q);
old = conf->epsilon;
conf->epsilonprec = qprecision(q);
conf->epsilon = qlink(q);