#define M_PI 3.14159265358979323846264338327
#endif
+#define EPSILON 0.000000001 /**< limit of precision for float equality */
+#define EQ(x,y) (fabs(x-y) < EPSILON) /**< floating point equality macro */
+
static void do_spellnum(char *num, unsigned int len, char **buff,
char ***bp);
static int nval_sort(const void *, const void *);
safe_str(T(e_nums), buff, bp);
return;
}
- safe_boolean(parse_number(args[0]) == parse_number(args[1]), buff, bp);
+ safe_boolean(EQ(parse_number(args[0]), parse_number(args[1])), buff, bp);
}
/* ARGSUSED */
safe_str(T(e_nums), buff, bp);
return;
}
- safe_boolean(parse_number(args[0]) != parse_number(args[1]), buff, bp);
+ safe_boolean(!EQ(parse_number(args[0]), parse_number(args[1])), buff, bp);
}
/* ARGSUSED */
return;
}
x = parse_number(args[0]);
- if (x == 0)
+ if (EQ(x, 0))
safe_chr('0', buff, bp);
else if (x > 0)
safe_chr('1', buff, bp);
}
sum = sqrt(sum);
- if (!sum) {
+ if (EQ(sum, 0)) {
/* zero vector */
p1 = tbuf;
safe_chr('0', buff, bp);
return;
}
y = parse_number(args[1]);
- if (y == 0) {
+ if (EQ(y, 0)) {
safe_str(T("#-1 DIVISION BY ZERO"), buff, bp);
return;
}
}
num = parse_number(args[0]);
m = parse_number(args[1]);
- if (num < 0 && (m != (int) m)) {
+ if (num < 0 && (!EQ(m, (int) m))) {
safe_str(T("#-1 FRACTIONAL POWER OF NEGATIVE"), buff, bp);
return;
}
} else
first = 0;
r = 0.0;
- if (v * (*d) != *n) {
+ if (!EQ(v * (*d), *n)) {
r = (N - v * D) / (v * (*d) - *n);
if (r <= 1.0) {
t = N;
epsilon = 1.0 / m * floor(0.5 + m * epsilon);
if (epsilon <= error)
return epsilon;
- } while (r != 0.0);
+ } while (!EQ(r, 0.0));
return epsilon;
}
if (n < 0) {
n = fabs(n);
sign = 1;
- } else if (n == 0) {
+ } else if (EQ(n, 0)) {
safe_chr('0', buff, bp);
return;
}
}
temp = parse_integer(ptr[n]);
- if (temp == 0) {
+ if (EQ(temp, 0)) {
safe_str(T("#-1 DIVISION BY ZERO"), buff, bp);
return;
}
"%-10s %7d %7d %6d %4d %4d %4d %4d %4d %6.3f %7u", hname,
htab->hashsize, htab->entries, longest, lengths[0], lengths[1],
lengths[2], lengths[3], lengths[4],
- totchains == 0.0 ? 0.0 : chainlens / totchains, bytes);
+ totchains > 0 ? chainlens / totchains : 0.0, bytes);
}