making = a builtin

fixing = and eqv? to work properly on NaNs
fixing other comparison predicates to be consistent
This commit is contained in:
JeffBezanson
2009-04-15 23:54:43 +00:00
parent 81641a2240
commit 36a209cd5f
12 changed files with 99 additions and 25 deletions
+1
View File
@@ -116,6 +116,7 @@ typedef u_ptrint_t uptrint_t;
#define LABS(n) (((n)^((n)>>(NBITS-1))) - ((n)>>(NBITS-1)))
#define NBABS(n,nb) (((n)^((n)>>((nb)-1))) - ((n)>>((nb)-1)))
#define DFINITE(d) (((*(int64_t*)&(d))&0x7ff0000000000000LL)!=0x7ff0000000000000LL)
#define DNAN(d) (((*(int64_t*)&(d))&0x7ff8000000000000LL)==0x7ff8000000000000LL)
extern double D_PNAN;
extern double D_NNAN;
+2 -2
View File
@@ -93,11 +93,11 @@ void llt_init()
ios_init_stdstreams();
D_PNAN = strtod("+NaN",NULL);
D_NNAN = strtod("-NaN",NULL);
D_NNAN = -strtod("+NaN",NULL);
D_PINF = strtod("+Inf",NULL);
D_NINF = strtod("-Inf",NULL);
F_PNAN = strtof("+NaN",NULL);
F_NNAN = strtof("-NaN",NULL);
F_NNAN = -strtof("+NaN",NULL);
F_PINF = strtof("+Inf",NULL);
F_NINF = strtof("-Inf",NULL);
}
+10 -5
View File
@@ -235,16 +235,21 @@ int cmp_lt(void *a, numerictype_t atag, void *b, numerictype_t btag)
return 0;
}
int cmp_eq(void *a, numerictype_t atag, void *b, numerictype_t btag)
int cmp_eq(void *a, numerictype_t atag, void *b, numerictype_t btag,
int equalnans)
{
if (atag==btag)
if (atag==btag && !equalnans)
return cmp_same_eq(a, b, atag);
double da = conv_to_double(a, atag);
double db = conv_to_double(b, btag);
if ((int)atag >= T_FLOAT && (int)btag >= T_FLOAT)
if ((int)atag >= T_FLOAT && (int)btag >= T_FLOAT) {
if (equalnans && DNAN(da)) {
return *(uint64_t*)&da == *(uint64_t*)&db;
}
return (da == db);
}
if (da != db)
return 0;
@@ -339,8 +344,8 @@ void test_operators()
assert(cmp_lt(&d, T_DOUBLE, &i64, T_INT64));
assert(!cmp_lt(&i64, T_INT64, &d, T_DOUBLE));
assert(!cmp_eq(&d, T_DOUBLE, &i64, T_INT64));
assert(!cmp_eq(&d, T_DOUBLE, &i64, T_INT64, 0));
i64 = DBL_MAXINT;
assert(cmp_eq(&d, T_DOUBLE, &i64, T_INT64));
assert(cmp_eq(&d, T_DOUBLE, &i64, T_INT64, 0));
}
#endif
+2 -1
View File
@@ -75,7 +75,8 @@ uint32_t conv_to_uint32(void *data, numerictype_t tag);
int cmp_same_lt(void *a, void *b, numerictype_t tag);
int cmp_same_eq(void *a, void *b, numerictype_t tag);
int cmp_lt(void *a, numerictype_t atag, void *b, numerictype_t btag);
int cmp_eq(void *a, numerictype_t atag, void *b, numerictype_t btag);
int cmp_eq(void *a, numerictype_t atag, void *b, numerictype_t btag,
int equalnans);
#ifdef ARCH_X86_64
# define LEGACY_REGS "=Q"