mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
expt / integer-expt fixes
* libguile/numbers.c (scm_integer_expt): Validate the first arg as a number. (scm_expt): Delegate to scm_integer_expt iff x is exact. Fixes fractions.test, which I broke recently * test-suite/tests/numbers.test ("integer-expt"): Add test for (integer-expt #t 0).
This commit is contained in:
parent
02fcbf78b2
commit
5a8fc758b0
2 changed files with 5 additions and 1 deletions
|
@ -1802,6 +1802,8 @@ SCM_DEFINE (scm_integer_expt, "integer-expt", 2, 0, 0,
|
|||
int i2_is_big = 0;
|
||||
SCM acc = SCM_I_MAKINUM (1L);
|
||||
|
||||
SCM_VALIDATE_NUMBER (SCM_ARG1, n);
|
||||
|
||||
/* 0^0 == 1 according to R5RS */
|
||||
if (scm_is_eq (n, SCM_INUM0) || scm_is_eq (n, acc))
|
||||
return scm_is_false (scm_zero_p(k)) ? n : acc;
|
||||
|
@ -5466,7 +5468,7 @@ SCM_DEFINE (scm_expt, "expt", 2, 0, 0,
|
|||
"Return @var{x} raised to the power of @var{y}.")
|
||||
#define FUNC_NAME s_scm_expt
|
||||
{
|
||||
if ((SCM_I_INUMP (x) || SCM_BIGP (x)) && scm_is_integer (y))
|
||||
if (scm_is_true (scm_exact_p (x)) && scm_is_integer (y))
|
||||
return scm_integer_expt (x, y);
|
||||
else if (scm_is_real (x) && scm_is_real (y) && scm_to_double (x) >= 0.0)
|
||||
{
|
||||
|
|
|
@ -2995,6 +2995,8 @@
|
|||
|
||||
(with-test-prefix "integer-expt"
|
||||
|
||||
(pass-if-exception "non-numeric base" exception:wrong-type-arg
|
||||
(integer-expt #t 0))
|
||||
(pass-if-exception "2^+inf" exception:wrong-type-arg
|
||||
(integer-expt 2 +inf.0))
|
||||
(pass-if-exception "2^-inf" exception:wrong-type-arg
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue