Commit 046c6b9f authored by Marius Gerbershagen's avatar Marius Gerbershagen
Browse files

number_compare.d: fix number comparison for NaN

All comparisons with NaN should return NIL for consistency with the
IEEE standard.
parent d9a105da
......@@ -159,9 +159,18 @@ monotonic(int s, int t, int narg, ecl_va_list nums)
FEwrong_type_nth_arg(@[<], 1, c, @[real]);
}
/* INV: type check occurs in ecl_number_compare() */
for (c = ecl_va_arg(nums); --narg; c = d) {
c = ecl_va_arg(nums);
#ifdef ECL_IEEE_FP
if (ecl_float_nan_p(c))
return1(ECL_NIL);
#endif
for (; --narg; c = d) {
d = ecl_va_arg(nums);
if (s*ecl_number_compare(d, c) < t)
if (
#ifdef ECL_IEEE_FP
ecl_float_nan_p(d) ||
#endif
s*ecl_number_compare(d, c) < t)
return1(ECL_NIL);
}
return1(ECL_T);
......@@ -173,7 +182,7 @@ monotonic(int s, int t, int narg, ecl_va_list nums)
ecl_va_end(nums); \
return result; }
cl_object @<= MONOTONIC( 1, 0);
cl_object @>= MONOTONIC(-1, 0);
cl_object @< MONOTONIC( 1, 1);
cl_object @> MONOTONIC(-1, 1);
cl_object @<= MONOTONIC( 1, 0)
cl_object @>= MONOTONIC(-1, 0)
cl_object @< MONOTONIC( 1, 1)
cl_object @> MONOTONIC(-1, 1)
......@@ -385,22 +385,22 @@
(def-inline /= :always (t t) :bool "!ecl_number_equalp(#0,#1)")
(def-inline /= :always (fixnum-float fixnum-float) :bool "(#0)!=(#1)")
(def-inline < :always (t t) :bool "ecl_number_compare(#0,#1)<0")
(def-inline < :always (t t) :bool "ecl_lower(#0,#1)")
(def-inline < :always (fixnum-float fixnum-float) :bool "(#0)<(#1)")
(def-inline < :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)<(#1) && (#1)<(#2))")
(def-inline > :always (t t) :bool "ecl_number_compare(#0,#1)>0")
(def-inline > :always (t t) :bool "ecl_greater(#0,#1)")
(def-inline > :always (fixnum-float fixnum-float) :bool "(#0)>(#1)")
(def-inline > :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)>(#1) && (#1)>(#2))")
(def-inline <= :always (t t) :bool "ecl_number_compare(#0,#1)<=0")
(def-inline <= :always (t t) :bool "ecl_lowereq(#0,#1)")
(def-inline <= :always (fixnum-float fixnum-float) :bool "(#0)<=(#1)")
(def-inline <= :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)<=(#1) && (#1)<=(#2))")
(def-inline >= :always (t t) :bool "ecl_number_compare(#0,#1)>=0")
(def-inline >= :always (t t) :bool "ecl_greatereq(#0,#1)")
(def-inline >= :always (fixnum-float fixnum-float) :bool "(#0)>=(#1)")
(def-inline >= :always (fixnum-float fixnum-float fixnum-float) :bool
"@012;((#0)>=(#1) && (#1)>=(#2))")
......
......@@ -1191,10 +1191,17 @@ extern ECL_API cl_object cl_min _ECL_ARGS((cl_narg narg, cl_object min, ...));
extern ECL_API int ecl_number_equalp(cl_object x, cl_object y);
extern ECL_API int ecl_number_compare(cl_object x, cl_object y);
#ifdef ECL_IEEE_FP
#define ecl_lowereq(x,y) (!ecl_float_nan_p(x) && !ecl_float_nan_p(y) && ecl_number_compare((x),(y)) <= 0)
#define ecl_greatereq(x,y) (!ecl_float_nan_p(x) && !ecl_float_nan_p(y) && ecl_number_compare((x),(y)) >= 0)
#define ecl_lower(x,y) (!ecl_float_nan_p(x) && !ecl_float_nan_p(y) && ecl_number_compare((x),(y)) < 0)
#define ecl_greater(x,y) (!ecl_float_nan_p(x) && !ecl_float_nan_p(y) && ecl_number_compare((x),(y)) > 0)
#else
#define ecl_lowereq(x,y) (ecl_number_compare((x),(y)) <= 0)
#define ecl_greatereq(x,y) (ecl_number_compare((x),(y)) >= 0)
#define ecl_lower(x,y) (ecl_number_compare((x),(y)) < 0)
#define ecl_greater(x,y) (ecl_number_compare((x),(y)) > 0)
#endif
/* num_log.c */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment