mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
improve check for invalid epsilon
We added check_epsilon(NUMBER *q) so that later, builtin functions can check the eps value as well.
This commit is contained in:
26
qfunc.c
26
qfunc.c
@@ -47,8 +47,28 @@ STATIC long E_num;
|
|||||||
/*
|
/*
|
||||||
* verify_epsilon - verify that 0 < epsilon < 1
|
* verify_epsilon - verify that 0 < epsilon < 1
|
||||||
*
|
*
|
||||||
* This function is called via the OP_SETEPSILON op code, config("epsilon",
|
* given:
|
||||||
* and from various builtin functions that take an epsilon argument.
|
* 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
|
* 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
|
* out of range, then a math_error() is triggered causing this function
|
||||||
@@ -58,7 +78,7 @@ void
|
|||||||
verify_epsilon(NUMBER *q)
|
verify_epsilon(NUMBER *q)
|
||||||
{
|
{
|
||||||
/* verify that 0 < epsilon < 1 */
|
/* 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");
|
math_error("Invalid value for epsilon: must be: 0 < epsilon < 1");
|
||||||
not_reached();
|
not_reached();
|
||||||
}
|
}
|
||||||
|
1
qmath.h
1
qmath.h
@@ -167,6 +167,7 @@ E_FUNC long qprecision(NUMBER *q);
|
|||||||
E_FUNC long qplaces(NUMBER *q, ZVALUE base);
|
E_FUNC long qplaces(NUMBER *q, ZVALUE base);
|
||||||
E_FUNC long qdecplaces(NUMBER *q);
|
E_FUNC long qdecplaces(NUMBER *q);
|
||||||
E_FUNC long qdigits(NUMBER *q, ZVALUE base);
|
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 verify_epsilon(NUMBER *q);
|
||||||
E_FUNC void setepsilon(NUMBER *q);
|
E_FUNC void setepsilon(NUMBER *q);
|
||||||
E_FUNC NUMBER *qbitvalue(long i);
|
E_FUNC NUMBER *qbitvalue(long i);
|
||||||
|
Reference in New Issue
Block a user