>From 68b1acaefc448add19e2ea90f2acf2b165539c64 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Wed, 26 Jan 2011 04:42:04 -0500 Subject: [PATCH] `inf?' and `nan?' throw exceptions when applied to non-numbers * libguile/numbers.c (scm_inf_p, scm_nan_p): Throw an exception if applied to a non-number object. Previously returned #f. (Note that NaNs _are_ considered numbers by scheme, despite their name). --- NEWS | 6 ++++++ libguile/numbers.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index d5fdb08..80a8c32 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,12 @@ integer-expt. This is more correct, and conforming to R6RS, but seems to be incompatible with R5RS, which would return 0 for all non-zero values of N. +*** `inf?' and `nan?' now throw exceptions for non-numbers + +scm_inf_p `inf?' and scm_nan_p `nan?' now throw exceptions if passed +non-number objects. Previously they returned #f. (Note that NaNs +_are_ considered numbers by scheme, despite their name). + *** New procedure: `finite?' Add scm_finite_p `finite?' from R6RS to guile core, which returns #t diff --git a/libguile/numbers.c b/libguile/numbers.c index dc10a03..48de05a 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -628,8 +628,10 @@ SCM_DEFINE (scm_inf_p, "inf?", 1, 0, 0, else if (SCM_COMPLEXP (x)) return scm_from_bool (isinf (SCM_COMPLEX_REAL (x)) || isinf (SCM_COMPLEX_IMAG (x))); - else + else if (SCM_NUMBERP (x)) return SCM_BOOL_F; + else + SCM_WRONG_TYPE_ARG (1, x); } #undef FUNC_NAME @@ -644,8 +646,10 @@ SCM_DEFINE (scm_nan_p, "nan?", 1, 0, 0, else if (SCM_COMPLEXP (n)) return scm_from_bool (isnan (SCM_COMPLEX_REAL (n)) || isnan (SCM_COMPLEX_IMAG (n))); - else + else if (SCM_NUMBERP (n)) return SCM_BOOL_F; + else + SCM_WRONG_TYPE_ARG (1, n); } #undef FUNC_NAME -- 1.5.6.5