mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
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:
3
CHANGES
3
CHANGES
@@ -86,6 +86,9 @@ The following are the changes from calc version 2.14.3.5 to date:
|
|||||||
The len element in a ZVALUE is of type LEN. LEN type is SB32 when
|
The len element in a ZVALUE is of type LEN. LEN type is SB32 when
|
||||||
MAJOR_VER < 3, or a uintptr_t otherwise.
|
MAJOR_VER < 3, or a uintptr_t otherwise.
|
||||||
|
|
||||||
|
Setting an invalid epsilon via the epsilon(value) or confiv("epsilon",
|
||||||
|
value) triggers an error. The epsilon value must be: 0 < epsilon < 1.
|
||||||
|
|
||||||
|
|
||||||
The following are the changes from calc version 2.14.3.4 to 2.14.3.5:
|
The following are the changes from calc version 2.14.3.4 to 2.14.3.5:
|
||||||
|
|
||||||
|
28
qfunc.c
28
qfunc.c
@@ -43,6 +43,29 @@ STATIC long E_num;
|
|||||||
|
|
||||||
#define QALLOCNUM 64
|
#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.
|
* Set the default epsilon for approximate calculations.
|
||||||
* This must be greater than zero.
|
* This must be greater than zero.
|
||||||
@@ -55,10 +78,7 @@ setepsilon(NUMBER *q)
|
|||||||
{
|
{
|
||||||
NUMBER *old;
|
NUMBER *old;
|
||||||
|
|
||||||
if (qisneg(q) || qiszero(q)) {
|
verify_epsilon(q);
|
||||||
math_error("Epsilon value must be greater than zero");
|
|
||||||
not_reached();
|
|
||||||
}
|
|
||||||
old = conf->epsilon;
|
old = conf->epsilon;
|
||||||
conf->epsilonprec = qprecision(q);
|
conf->epsilonprec = qprecision(q);
|
||||||
conf->epsilon = qlink(q);
|
conf->epsilon = qlink(q);
|
||||||
|
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 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);
|
||||||
E_FUNC NUMBER *qtenpow(long i);
|
E_FUNC NUMBER *qtenpow(long i);
|
||||||
|
Reference in New Issue
Block a user