approx_lt() by <, etc.
+Wed Feb 18 22:21:35 2004 Ben Pfaff <blp@gnu.org>
+
+ Got rid of approx.h. In general, replaced all references to
+ approx_eq() by ==, approx_lt() by <, etc. Other types of changes
+ noted below.
+
+ * Makefile.am: (pspp_SOURCES) Removed approx.h.
+
+ * data-out.c: (try_F) Replaced test for approx_eq(number, 0.0) by
+ test for mag < EPSILON.
+
+ * misc.h: Add definition of EPSILON.
+
Wed Feb 18 21:32:44 2004 Ben Pfaff <blp@gnu.org>
* vfm.c: (procedure) Add check to prevent recursive call.
pspp_SOURCES = $(q_sources_c) \
aggregate.c algorithm.c algorithm.h alloc.c alloc.h \
-apply-dict.c approx.h ascii.c autorecode.c bitvector.h \
+apply-dict.c ascii.c autorecode.c bitvector.h \
cmdline.c cmdline.h command.c command.def command.h compute.c \
count.c data-in.c data-in.h data-list.c \
data-out.c debug-print.h devind.c devind.h dfm.c dfm.h \
+++ /dev/null
-/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
- Written by Ben Pfaff <blp@gnu.org>.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
-
-#if !approx_h
-#define approx_h 1
-
-#include <float.h>
-#include <math.h>
-
-/* Minimum difference to consider values to be distinct. */
-#define EPSILON (DBL_EPSILON*10)
-
-/* The boundary at EPSILON is considered to be equal. */
-/* Possible modification: insert frexp() into all these expressions. */
-
-#define approx_eq(A, B) \
- (fabs((A)-(B))<=EPSILON)
-
-#define approx_ne(A, B) \
- (fabs((A)-(B))>EPSILON)
-
-#define approx_ge(A, B) \
- ((A) >= (B)-EPSILON)
-
-#define approx_gt(A, B) \
- ((A) > (B)+EPSILON)
-
-#define approx_le(A, B) \
- ((A) <= (B)+EPSILON)
-
-#define approx_lt(A, B) \
- ((A) < (B)-EPSILON)
-
-#define approx_floor(x) \
- (floor((x)+EPSILON))
-
-#define approx_in_range(V, L, H) \
- (((V) >= (L)-EPSILON) && ((V) <= (H)+EPSILON))
-
-#define approx_compare(A, B) \
- (approx_gt(A,B) ? 1 : (approx_lt(A,B) ? -1 : 0))
-
-#endif /* !approx_h */
#include <assert.h>
#include <stdlib.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "error.h"
#include "expr.h"
#include "lexer.h"
+#include "misc.h"
#include "str.h"
#include "var.h"
#include <assert.h>
#include <stdlib.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "error.h"
#include "lexer.h"
assert (0);
break;
case CNT_SINGLE:
- if (approx_ne (cmp, num->a))
+ if (cmp != num->a)
break;
counter++;
goto done;
case CNT_HIGH:
- if (approx_lt (cmp, num->a))
+ if (cmp < num->a)
break;
counter++;
goto done;
case CNT_LOW:
- if (approx_gt (cmp, num->a))
+ if (cmp > num->a)
break;
counter++;
goto done;
case CNT_RANGE:
- if (approx_lt (cmp, num->a) || approx_gt (cmp, num->b))
+ if (cmp < num->a || cmp > num->b)
break;
counter++;
goto done;
#include <float.h>
#include <stdlib.h>
#include <time.h>
-#include "approx.h"
#include "error.h"
#include "format.h"
#include "julcal/julcal.h"
n_int = 0;
/* Avoid printing `-.000'. 7/6/96. */
- if (approx_eq (number, 0.0))
+ if (mag < EPSILON)
number = 0.0;
}
else
digits in floor(number), including any sign. */
for (;;)
{
- if (mag >= power10[n_int]) /* Should this be approx_ge()? */
+ if (mag >= power10[n_int])
{
assert (delta[j]);
n_int += delta[j++];
#include "command.h"
#include "lexer.h"
#include "error.h"
-#include "approx.h"
#include "magic.h"
#include "stats.h"
#include "som.h"
}
t->z[count].mean = v->p.dsc.stats[dsc_mean];
t->z[count].std_dev = v->p.dsc.stats[dsc_stddev];
- if (t->z[count].std_dev == SYSMIS
- || approx_eq (t->z[count].std_dev, 0.0))
+ if (t->z[count].std_dev == SYSMIS || t->z[count].std_dev == 0.0)
t->z[count].mean = SYSMIS;
count++;
}
#include <math.h>
#include <errno.h>
#include <stdio.h>
-#include "approx.h"
#include "data-in.h"
#include "error.h"
#include "julcal/julcal.h"
#include "magic.h"
+#include "misc.h"
#include "pool.h"
#include "random.h"
#include "stats.h"
sp--;
if (sp[0].f == SYSMIS)
{
- if (approx_eq (sp[1].f, 0.0))
+ if (sp[1].f == 0.0)
sp->f = 1.0;
}
else if (sp[1].f == SYSMIS)
else
sp->f = SYSMIS;
}
- else if (approx_eq (sp[0].f, 0.0) && approx_eq (sp[1].f, 0.0))
+ else if (sp[0].f == 0.0 && sp[1].f == 0.0)
sp->f = SYSMIS;
else
sp->f = pow (sp[0].f, sp[1].f);
break;
case OP_AND:
- /* Note that the equality operator (==) may be used here
- (instead of approx_eq) because booleans are always
- *exactly* 0, 1, or SYSMIS.
+ /* Note that booleans are always one of 0, 1, or SYSMIS.
Truth table (in order of detection):
if (sp[1].f == SYSMIS)
sp->f = SYSMIS;
else
- sp->f = approx_eq (sp[0].f, sp[1].f);
+ sp->f = sp[0].f == sp[1].f;
}
break;
case OP_GE:
if (sp[1].f == SYSMIS)
sp->f = SYSMIS;
else
- sp->f = approx_ge (sp[0].f, sp[1].f);
+ sp->f = sp[0].f >= sp[1].f;
}
break;
case OP_GT:
if (sp[1].f == SYSMIS)
sp->f = SYSMIS;
else
- sp->f = approx_gt (sp[0].f, sp[1].f);
+ sp->f = sp[0].f > sp[1].f;
}
break;
case OP_LE:
if (sp[1].f == SYSMIS)
sp->f = SYSMIS;
else
- sp->f = approx_le (sp[0].f, sp[1].f);
+ sp->f = sp[0].f <= sp[1].f;
}
break;
case OP_LT:
if (sp[1].f == SYSMIS)
sp->f = SYSMIS;
else
- sp->f = approx_lt (sp[0].f, sp[1].f);
+ sp->f = sp[0].f < sp[1].f;
}
break;
case OP_NE:
if (sp[1].f == SYSMIS)
sp->f = SYSMIS;
else
- sp->f = approx_ne (sp[0].f, sp[1].f);
+ sp->f = sp[0].f != sp[1].f;
}
break;
if (sp->f == SYSMIS)
break;
for (i = 1; i <= n_args; i++)
- if (approx_eq (sp[0].f, sp[i].f))
+ if (sp[0].f == sp[i].f)
{
sp->f = 1.0;
goto main_loop;
for (i = 1; i <= n_args; i += 2)
if (sp[i].f == SYSMIS || sp[i + 1].f == SYSMIS)
continue;
- else if (approx_ge (sp[0].f, sp[i].f)
- && approx_le (sp[0].f, sp[i + 1].f))
+ else if (sp[0].f >= sp[i].f && sp[0].f <= sp[i + 1].f)
{
sp->f = 1.0;
goto main_loop;
sp->f *= sp->f;
break;
case OP_NUM_TO_BOOL:
- if (approx_eq (sp->f, 0.0))
+ if (sp->f == 0.0)
sp->f = 0.0;
- else if (approx_eq (sp->f, 1.0))
+ else if (sp->f == 1.0)
sp->f = 1.0;
else if (sp->f != SYSMIS)
{
{
if (sp[1].f == SYSMIS)
{
- if (approx_ne (sp[0].f, 0.0))
+ if (sp[0].f != 0.0)
sp->f = SYSMIS;
}
else
#include <errno.h>
#include <stdlib.h>
#include "alloc.h"
-#include "approx.h"
#include "data-in.h"
#include "error.h"
#include "julcal/julcal.h"
/* 0*SYSMIS=0, 0/SYSMIS=0; otherwise, SYSMIS and infinities
produce SYSMIS. */
- if (approx_eq (cval, 0.0) && n->type == OP_MUL)
+ if (cval == 0.0 && n->type == OP_MUL)
nvar = 0;
else if (sysmis || !finite (cval))
{
{
/* Otherwise consolidate all the nonconstant terms. */
m = xmalloc (sizeof (struct nonterm_node)
- + ((nvar + approx_ne (cval, def) - 1)
+ + ((nvar + (cval != def) - 1)
* sizeof (union any_node *)));
for (i = c = 0; i < n->n; i++)
if (n->arg[i]->type != OP_NUM_CON)
else
free_node (n->arg[i]);
- if (approx_ne (cval, def))
+ if (cval != def)
{
m->arg[c] = xmalloc (sizeof (struct num_con_node));
m->arg[c]->num_con.type = OP_NUM_CON;
{
if (n->arg[1]->type == OP_NUM_CON)
{
- if (approx_eq (n1, 1.0))
+ if (n1 == 1.0)
{
struct nonterm_node *m = (struct nonterm_node *) n->arg[0];
free (n);
return m;
}
- else if (approx_eq (n1, 2.0))
+ else if (n1 == 2.0)
{
n = xrealloc (n, sizeof (struct nonterm_node));
n->type = OP_SQUARE;
return optimize_tree (n);
case OP_POW:
- if (approx_eq (n0, 0.0) && approx_eq (n1, 0.0))
+ if (n0 == 0.0 && n1 == 0.0)
frnc (SYSMIS);
else if (n0 == SYSMIS && n1 == 0.0)
frnc (1.0);
break;
case OP_EQ:
- rnc (approx_eq (n0, n1));
+ rnc (n0 == n1);
break;
case OP_GE:
- rnc (approx_ge (n0, n1));
+ rnc (n0 >= n1);
break;
case OP_GT:
- rnc (approx_gt (n0, n1));
+ rnc (n0 > n1);
break;
case OP_LE:
- rnc (approx_le (n0, n1));
+ rnc (n0 <= n1);
break;
case OP_LT:
- rnc (approx_lt (n0, n1));
+ rnc (n0 < n1);
break;
case OP_NE:
- rnc (approx_ne (n0, n1));
+ rnc (n0 != n1);
break;
/* String operators. */
for (i = 1; i < n->n; i++)
{
ni = n->arg[i]->num_con.value;
- if (approx_eq (n0, ni))
+ if (n0 == ni)
{
frnc (1.0);
goto any_done;
if (min == SYSMIS || max == SYSMIS)
continue;
sysmis = 0;
- if (approx_ge (n0, min) && approx_le (n0, max))
+ if (n0 >= min && n0 <= max)
{
frnc (1.0);
goto range_done;
rnc (1.0 / n0);
break;
case OP_MOD:
- if (approx_eq (n0, 0.0) && n1 == SYSMIS)
+ if (n0 == 0.0 && n1 == SYSMIS)
frnc (0.0);
else
rnc (fmod (n0, n1));
break;
case OP_NUM_TO_BOOL:
- if (approx_eq (n0, 0.0))
+ if (n0 == 0.0)
n0 = 0.0;
- else if (approx_eq (n0, 1.0))
+ else if (n0 == 1.0)
n0 = 1.0;
else if (n0 != SYSMIS)
{
#include <assert.h>
#include <stdlib.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "data-in.h"
#include "dfm.h"
if (iter->flags & RCT_OTHER)
goto found;
for (i = 0; i < iter->nv; i++)
- if (approx_eq (iter->v[i].f, v.f))
+ if (iter->v[i].f == v.f)
goto found;
}
if (fty.wild)
#include <config.h>
#include <assert.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "do-ifP.h"
#include "error.h"
#include "expr.h"
#include "lexer.h"
+#include "misc.h"
#include "settings.h"
#include "str.h"
#include "var.h"
c->data[two->index->fv].f = t1.f;
/* Throw out various pathological cases. */
- if (!finite (t1.f) || !finite (t2.f) || !finite (t3.f)
- || approx_eq (t2.f, 0.0))
+ if (!finite (t1.f) || !finite (t2.f) || !finite (t3.f) || t2.f == 0.0)
return two->loop_term;
debug_printf (("LOOP %s=%g TO %g BY %g.\n", two->index->name,
t1.f, t3.f, t2.f));
two->flags &= ~LPC_RINDEX;
/* incr>0 but init>term */
- if (approx_gt (t1.f, t3.f))
+ if (t1.f > t3.f)
return two->loop_term;
}
else
two->flags |= LPC_RINDEX;
/* incr<0 but init<term */
- if (approx_lt (t1.f, t3.f))
+ if (t1.f < t3.f)
return two->loop_term;
}
if (two->flags & LPC_RINDEX)
{
/* Test if we're at the end of the looping. */
- if (approx_lt (two->curr, two->term))
+ if (two->curr < two->term)
return two->loop_term;
/* Set the current value into the case. */
else if (two->flags & LPC_INDEX)
{
/* Test if we're at the end of the looping. */
- if (approx_gt (two->curr, two->term))
+ if (two->curr > two->term)
return two->loop_term;
/* Set the current value into the case. */
#if !math_misc_h
#define math_misc_h 1
+#include <float.h>
#include <math.h>
+#define EPSILON (10 * DBL_EPSILON)
+
/* HUGE_VAL is traditionally defined as positive infinity, or
alternatively, DBL_MAX. */
#if !HAVE_ISINF
#include <errno.h>
#include <ctype.h>
#include "alloc.h"
-#include "approx.h"
#include "devind.h"
#include "error.h"
#include "filename.h"
if (c <= 0.0 || ptail == s)
goto lossage;
s = ptail;
- if (approx_eq (c, 0.0))
+ if (c == 0.0)
goto lossage;
if (value > 0)
value += b / c;
double b;
s = &ptail[1];
b = strtod (s, &ptail);
- if (approx_le (b, 0.0) || ptail == s)
+ if (b <= 0.0 || ptail == s)
goto lossage;
s = ptail;
value /= b;
ptail += 2;
value *= factor;
}
- if (approx_lt (value, 0.0))
+ if (value <= 0.0)
goto lossage;
if (tail)
*tail = ptail;
#include <config.h>
#include <assert.h>
#include <ctype.h>
+#include <math.h>
#include <stdlib.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "error.h"
#include "lexer.h"
return cp;
break;
case RCD_SINGLE:
- if (approx_eq (cmp, cp->f1.f))
+ if (cmp == cp->f1.f)
return cp;
break;
case RCD_HIGH:
- if (approx_ge (cmp, cp->f1.f))
+ if (cmp >= cp->f1.f)
return cp;
break;
case RCD_LOW:
- if (approx_le (cmp, cp->f1.f))
+ if (cmp <= cp->f1.f)
return cp;
break;
case RCD_RANGE:
- if (approx_in_range (cmp, cp->f1.f, cp->f2.f))
+ if (cmp >= cp->f1.f && cmp <= cp->f2.f)
return cp;
break;
case RCD_ELSE:
#include <unistd.h> /* Required by SunOS4. */
#endif
#include "alloc.h"
-#include "approx.h"
#include "error.h"
#include "file-handle.h"
#include "getline.h"
*ext->x++ = 255;
continue;
}
- else
+ else if (*elem > INT_MIN && *elem < INT_MAX)
{
- int value = *elem < 0 ? *elem - EPSILON : *elem + EPSILON;
+ int value = *elem;
if (value >= 1 - COMPRESSION_BIAS
&& value <= 251 - COMPRESSION_BIAS
- && approx_eq (value, *elem))
+ && value == *elem)
{
*ext->x++ = value + COMPRESSION_BIAS;
continue;
#include <stdlib.h>
#include <errno.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "error.h"
#include "expr.h"
if (v->type == NUMERIC)
{
- if (approx_ne (a[v->fv].f, b[v->fv].f))
+ if (a[v->fv].f != b[v->fv].f)
{
result = (a[v->fv].f > b[v->fv].f) ? 1 : -1;
break;
#if !val_h
#define val_h 1
+#include <float.h>
/* Values. */
#include <assert.h>
#include <stdlib.h>
#include "alloc.h"
-#include "approx.h"
#include "command.h"
#include "do-ifP.h"
#include "expr.h"
case MISSING_NONE:
return 0;
case MISSING_1:
- return approx_eq (x, v->missing[0].f);
+ return x == v->missing[0].f;
case MISSING_2:
- return (approx_eq (x, v->missing[0].f)
- || approx_eq (x, v->missing[1].f));
+ return x == v->missing[0].f || x == v->missing[1].f;
case MISSING_3:
- return (approx_eq (x, v->missing[0].f)
- || approx_eq (x, v->missing[1].f)
- || approx_eq (x, v->missing[2].f));
+ return (x == v->missing[0].f || x == v->missing[1].f
+ || x == v->missing[2].f);
case MISSING_RANGE:
- return (approx_ge (x, v->missing[0].f)
- && approx_le (x, v->missing[1].f));
+ return x >= v->missing[0].f && x <= v->missing[1].f;
case MISSING_LOW:
- return approx_le (x, v->missing[0].f);
+ return x <= v->missing[0].f;
case MISSING_HIGH:
- return approx_ge (x, v->missing[0].f);
+ return x >= v->missing[0].f;
case MISSING_RANGE_1:
- return ((approx_ge (x, v->missing[0].f)
- && approx_le (x, v->missing[1].f))
- || approx_eq (x, v->missing[2].f));
+ return ((x >= v->missing[0].f && x <= v->missing[1].f)
+ || x == v->missing[2].f);
case MISSING_LOW_1:
- return (approx_le (x, v->missing[0].f)
- || approx_eq (x, v->missing[1].f));
+ return x <= v->missing[0].f || x == v->missing[1].f;
case MISSING_HIGH_1:
- return (approx_ge (x, v->missing[0].f)
- || approx_eq (x, v->missing[1].f));
+ return x >= v->missing[0].f || x == v->missing[1].f;
default:
assert (0);
}
#include <unistd.h> /* Required by SunOS4. */
#endif
#include "alloc.h"
-#include "approx.h"
#include "do-ifP.h"
#include "error.h"
#include "expr.h"
switch (v->type)
{
case NUMERIC:
- if (approx_ne (c->data[v->fv].f, prev_case->data[v->fv].f))
+ if (c->data[v->fv].f != prev_case->data[v->fv].f)
goto not_equal;
break;
case ALPHA: