>From a112e4169b07a9b2aa49e1375ed507004768f6cd 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: Add NEWS entry. --- NEWS | 6 ++++++ libguile/numbers.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 436efe8..8153d0e 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,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 a631ee4..c6a2162 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 @@ -645,8 +647,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