diff --git a/qfunc.c b/qfunc.c index e304b49..d5e43d5 100644 --- a/qfunc.c +++ b/qfunc.c @@ -47,8 +47,28 @@ STATIC long E_num; /* * 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. + * given: + * q epsilon or eps argument + * + * returns: + * false q is NULL or q <= 0 or q >= 1 + * true 0 < q < 1 + */ +bool +check_epsilon(NUMBER *q) +{ + /* verify that 0 < epsilon < 1 */ + if (q == NULL || qisneg(q) || qiszero(q) || qisone(q) || qreli(q, 1) > 0) { + return false; + } + return true; +} + + +/* + * verify_epsilon - verify that 0 < epsilon < 1 + * + * This function is called via the OP_SETEPSILON op code, config("epsilon"). * * 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 @@ -58,7 +78,7 @@ void verify_epsilon(NUMBER *q) { /* verify that 0 < epsilon < 1 */ - if (q == NULL || qisneg(q) || qiszero(q) || qisone(q) || qreli(q, 1) > 0) { + if (check_epsilon(q) == false) { math_error("Invalid value for epsilon: must be: 0 < epsilon < 1"); not_reached(); } diff --git a/qmath.h b/qmath.h index 16cca81..5b95cc2 100644 --- a/qmath.h +++ b/qmath.h @@ -167,6 +167,7 @@ E_FUNC long qprecision(NUMBER *q); E_FUNC long qplaces(NUMBER *q, ZVALUE base); E_FUNC long qdecplaces(NUMBER *q); E_FUNC long qdigits(NUMBER *q, ZVALUE base); +E_FUNC bool check_epsilon(NUMBER *q); E_FUNC void verify_epsilon(NUMBER *q); E_FUNC void setepsilon(NUMBER *q); E_FUNC NUMBER *qbitvalue(long i);