mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
domain of inf?, finite?, nan? is the real numbers
* libguile/numbers.c (scm_inf_p, scm_finite_p, scm_nan_p): The domain of these functions is the real numbers. Error on other input. * doc/ref/api-data.texi (Reals and Rationals): Update the documentation accordingly. * test-suite/tests/numbers.test ("finite?", "inf?"): Update tests.
This commit is contained in:
parent
a4955a0412
commit
10391e06e0
3 changed files with 40 additions and 33 deletions
|
@ -589,19 +589,20 @@ to use @code{inexact->exact} on the arguments.
|
|||
|
||||
@deffn {Scheme Procedure} inf? x
|
||||
@deffnx {C Function} scm_inf_p (x)
|
||||
Return @code{#t} if @var{x} is either @samp{+inf.0} or @samp{-inf.0},
|
||||
@code{#f} otherwise.
|
||||
Return @code{#t} if the real number @var{x} is @samp{+inf.0} or
|
||||
@samp{-inf.0}. Otherwise return @code{#f}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} nan? x
|
||||
@deffnx {C Function} scm_nan_p (x)
|
||||
Return @code{#t} if @var{x} is @samp{+nan.0}, @code{#f} otherwise.
|
||||
Return @code{#t} if the real number @var{x} is @samp{+nan.0}, or
|
||||
@code{#f} otherwise.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} finite? x
|
||||
@deffnx {C Function} scm_finite_p (x)
|
||||
Return @code{#t} if @var{x} is neither infinite nor a NaN,
|
||||
@code{#f} otherwise.
|
||||
Return @code{#t} if the real number @var{x} is neither infinite nor a
|
||||
NaN, @code{#f} otherwise.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} nan
|
||||
|
|
|
@ -600,16 +600,13 @@ SCM_DEFINE (scm_even_p, "even?", 1, 0, 0,
|
|||
|
||||
SCM_DEFINE (scm_finite_p, "finite?", 1, 0, 0,
|
||||
(SCM x),
|
||||
"Return @code{#t} if @var{x} is neither infinite\n"
|
||||
"nor a NaN, @code{#f} otherwise.")
|
||||
"Return @code{#t} if the real number @var{x} is neither\n"
|
||||
"infinite nor a NaN, @code{#f} otherwise.")
|
||||
#define FUNC_NAME s_scm_finite_p
|
||||
{
|
||||
if (SCM_REALP (x))
|
||||
return scm_from_bool (DOUBLE_IS_FINITE (SCM_REAL_VALUE (x)));
|
||||
else if (SCM_COMPLEXP (x))
|
||||
return scm_from_bool (DOUBLE_IS_FINITE (SCM_COMPLEX_REAL (x))
|
||||
&& DOUBLE_IS_FINITE (SCM_COMPLEX_IMAG (x)));
|
||||
else if (SCM_NUMBERP (x))
|
||||
else if (scm_is_real (x))
|
||||
return SCM_BOOL_T;
|
||||
else
|
||||
SCM_WRONG_TYPE_ARG (1, x);
|
||||
|
@ -618,33 +615,31 @@ SCM_DEFINE (scm_finite_p, "finite?", 1, 0, 0,
|
|||
|
||||
SCM_DEFINE (scm_inf_p, "inf?", 1, 0, 0,
|
||||
(SCM x),
|
||||
"Return @code{#t} if @var{x} is either @samp{+inf.0}\n"
|
||||
"or @samp{-inf.0}, @code{#f} otherwise.")
|
||||
"Return @code{#t} if the real number @var{x} is @samp{+inf.0} or\n"
|
||||
"@samp{-inf.0}. Otherwise return @code{#f}.")
|
||||
#define FUNC_NAME s_scm_inf_p
|
||||
{
|
||||
if (SCM_REALP (x))
|
||||
return scm_from_bool (isinf (SCM_REAL_VALUE (x)));
|
||||
else if (SCM_COMPLEXP (x))
|
||||
return scm_from_bool (isinf (SCM_COMPLEX_REAL (x))
|
||||
|| isinf (SCM_COMPLEX_IMAG (x)));
|
||||
else
|
||||
else if (scm_is_real (x))
|
||||
return SCM_BOOL_F;
|
||||
else
|
||||
SCM_WRONG_TYPE_ARG (1, x);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_nan_p, "nan?", 1, 0, 0,
|
||||
(SCM n),
|
||||
"Return @code{#t} if @var{n} is a NaN, @code{#f}\n"
|
||||
"otherwise.")
|
||||
(SCM x),
|
||||
"Return @code{#t} if the real number @var{x} is a NaN,\n"
|
||||
"or @code{#f} otherwise.")
|
||||
#define FUNC_NAME s_scm_nan_p
|
||||
{
|
||||
if (SCM_REALP (n))
|
||||
return scm_from_bool (isnan (SCM_REAL_VALUE (n)));
|
||||
else if (SCM_COMPLEXP (n))
|
||||
return scm_from_bool (isnan (SCM_COMPLEX_REAL (n))
|
||||
|| isnan (SCM_COMPLEX_IMAG (n)));
|
||||
else
|
||||
if (SCM_REALP (x))
|
||||
return scm_from_bool (isnan (SCM_REAL_VALUE (x)));
|
||||
else if (scm_is_real (x))
|
||||
return SCM_BOOL_F;
|
||||
else
|
||||
SCM_WRONG_TYPE_ARG (1, x);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
|
|
@ -317,20 +317,26 @@
|
|||
(pass-if (not (finite? (inf))))
|
||||
(pass-if (not (finite? +inf.0)))
|
||||
(pass-if (not (finite? -inf.0)))
|
||||
(pass-if (not (finite? +inf.0+1i)))
|
||||
(pass-if (not (finite? -inf.0+1i)))
|
||||
(pass-if (not (finite? +1+inf.0i)))
|
||||
(pass-if (not (finite? +1-inf.0i)))
|
||||
(pass-if-exception
|
||||
"complex numbers not in doman of finite?"
|
||||
exception:wrong-type-arg
|
||||
(finite? +inf.0+1i))
|
||||
(pass-if-exception
|
||||
"complex numbers not in doman of finite? (2)"
|
||||
exception:wrong-type-arg
|
||||
(finite? +1+inf.0i))
|
||||
(pass-if-exception
|
||||
"complex numbers not in doman of finite? (3)"
|
||||
exception:wrong-type-arg
|
||||
(finite? +1+1i))
|
||||
(pass-if (finite? 3+0i))
|
||||
(pass-if (not (finite? (nan))))
|
||||
(pass-if (not (finite? +nan.0)))
|
||||
(pass-if (not (finite? 1+nan.0i)))
|
||||
(pass-if (not (finite? +nan.0+nan.0i)))
|
||||
(pass-if (finite? 0))
|
||||
(pass-if (finite? 0.0))
|
||||
(pass-if (finite? -0.0))
|
||||
(pass-if (finite? 42.0))
|
||||
(pass-if (finite? 1/2))
|
||||
(pass-if (finite? 42.0+700i))
|
||||
(pass-if (finite? (+ fixnum-max 1)))
|
||||
(pass-if (finite? (- fixnum-min 1))))
|
||||
|
||||
|
@ -344,6 +350,11 @@
|
|||
;; FIXME: what are the expected behaviors?
|
||||
;; (pass-if (inf? (/ 1.0 0.0))
|
||||
;; (pass-if (inf? (/ 1 0.0))
|
||||
(pass-if-exception
|
||||
"complex numbers not in doman of inf?"
|
||||
exception:wrong-type-arg
|
||||
(inf? +1+inf.0i))
|
||||
(pass-if (inf? +inf.0+0i))
|
||||
(pass-if (not (inf? 0)))
|
||||
(pass-if (not (inf? 42.0)))
|
||||
(pass-if (not (inf? (+ fixnum-max 1))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue