mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 20:30:28 +02:00
Quotient, remainder and modulo accept inexact integers
* libguile/numbers.c (scm_quotient, scm_remainder, scm_modulo): Accept inexact integers as well as exact ones, as required by the R5RS. * test-suite/tests/numbers.test (quotient, remainder, modulo): Add tests.
This commit is contained in:
parent
5d344028fb
commit
0748e3f3f0
2 changed files with 24 additions and 6 deletions
|
@ -796,9 +796,9 @@ SCM_PRIMITIVE_GENERIC (scm_quotient, "quotient", 2, 0, 0,
|
||||||
"Return the quotient of the numbers @var{x} and @var{y}.")
|
"Return the quotient of the numbers @var{x} and @var{y}.")
|
||||||
#define FUNC_NAME s_scm_quotient
|
#define FUNC_NAME s_scm_quotient
|
||||||
{
|
{
|
||||||
if (SCM_LIKELY (SCM_I_INUMP (x)) || SCM_LIKELY (SCM_BIGP (x)))
|
if (SCM_LIKELY (scm_is_integer (x)))
|
||||||
{
|
{
|
||||||
if (SCM_LIKELY (SCM_I_INUMP (y)) || SCM_LIKELY (SCM_BIGP (y)))
|
if (SCM_LIKELY (scm_is_integer (y)))
|
||||||
return scm_truncate_quotient (x, y);
|
return scm_truncate_quotient (x, y);
|
||||||
else
|
else
|
||||||
SCM_WTA_DISPATCH_2 (g_scm_quotient, x, y, SCM_ARG2, s_scm_quotient);
|
SCM_WTA_DISPATCH_2 (g_scm_quotient, x, y, SCM_ARG2, s_scm_quotient);
|
||||||
|
@ -817,9 +817,9 @@ SCM_PRIMITIVE_GENERIC (scm_remainder, "remainder", 2, 0, 0,
|
||||||
"@end lisp")
|
"@end lisp")
|
||||||
#define FUNC_NAME s_scm_remainder
|
#define FUNC_NAME s_scm_remainder
|
||||||
{
|
{
|
||||||
if (SCM_LIKELY (SCM_I_INUMP (x)) || SCM_LIKELY (SCM_BIGP (x)))
|
if (SCM_LIKELY (scm_is_integer (x)))
|
||||||
{
|
{
|
||||||
if (SCM_LIKELY (SCM_I_INUMP (y)) || SCM_LIKELY (SCM_BIGP (y)))
|
if (SCM_LIKELY (scm_is_integer (y)))
|
||||||
return scm_truncate_remainder (x, y);
|
return scm_truncate_remainder (x, y);
|
||||||
else
|
else
|
||||||
SCM_WTA_DISPATCH_2 (g_scm_remainder, x, y, SCM_ARG2, s_scm_remainder);
|
SCM_WTA_DISPATCH_2 (g_scm_remainder, x, y, SCM_ARG2, s_scm_remainder);
|
||||||
|
@ -839,9 +839,9 @@ SCM_PRIMITIVE_GENERIC (scm_modulo, "modulo", 2, 0, 0,
|
||||||
"@end lisp")
|
"@end lisp")
|
||||||
#define FUNC_NAME s_scm_modulo
|
#define FUNC_NAME s_scm_modulo
|
||||||
{
|
{
|
||||||
if (SCM_LIKELY (SCM_I_INUMP (x)) || SCM_LIKELY (SCM_BIGP (x)))
|
if (SCM_LIKELY (scm_is_integer (x)))
|
||||||
{
|
{
|
||||||
if (SCM_LIKELY (SCM_I_INUMP (y)) || SCM_LIKELY (SCM_BIGP (y)))
|
if (SCM_LIKELY (scm_is_integer (y)))
|
||||||
return scm_floor_remainder (x, y);
|
return scm_floor_remainder (x, y);
|
||||||
else
|
else
|
||||||
SCM_WTA_DISPATCH_2 (g_scm_modulo, x, y, SCM_ARG2, s_scm_modulo);
|
SCM_WTA_DISPATCH_2 (g_scm_modulo, x, y, SCM_ARG2, s_scm_modulo);
|
||||||
|
|
|
@ -633,6 +633,12 @@
|
||||||
(pass-if "n = fixnum-min - 1"
|
(pass-if "n = fixnum-min - 1"
|
||||||
(eqv? 1 (quotient (- fixnum-min 1) (- fixnum-min 1)))))
|
(eqv? 1 (quotient (- fixnum-min 1) (- fixnum-min 1)))))
|
||||||
|
|
||||||
|
;; Inexact integers
|
||||||
|
|
||||||
|
(pass-if (eqv? 5.0 (quotient 35.0 7.0)))
|
||||||
|
(pass-if (eqv? 5.0 (quotient 35 7.0)))
|
||||||
|
(pass-if (eqv? 5.0 (quotient 35.0 7 )))
|
||||||
|
|
||||||
;; Positive dividend and divisor
|
;; Positive dividend and divisor
|
||||||
|
|
||||||
(pass-if "35 / 7"
|
(pass-if "35 / 7"
|
||||||
|
@ -826,6 +832,12 @@
|
||||||
(pass-if "n = fixnum-min - 1"
|
(pass-if "n = fixnum-min - 1"
|
||||||
(eqv? 0 (remainder (- fixnum-min 1) (- fixnum-min 1)))))
|
(eqv? 0 (remainder (- fixnum-min 1) (- fixnum-min 1)))))
|
||||||
|
|
||||||
|
;; Inexact integers
|
||||||
|
|
||||||
|
(pass-if (eqv? 2.0 (remainder 37.0 7.0)))
|
||||||
|
(pass-if (eqv? 2.0 (remainder 37 7.0)))
|
||||||
|
(pass-if (eqv? 2.0 (remainder 37.0 7 )))
|
||||||
|
|
||||||
;; Positive dividend and divisor
|
;; Positive dividend and divisor
|
||||||
|
|
||||||
(pass-if "35 / 7"
|
(pass-if "35 / 7"
|
||||||
|
@ -1009,6 +1021,12 @@
|
||||||
(pass-if "n = fixnum-min - 1"
|
(pass-if "n = fixnum-min - 1"
|
||||||
(eqv? 0 (modulo (- fixnum-min 1) (- fixnum-min 1)))))
|
(eqv? 0 (modulo (- fixnum-min 1) (- fixnum-min 1)))))
|
||||||
|
|
||||||
|
;; Inexact integers
|
||||||
|
|
||||||
|
(pass-if (eqv? 1.0 (modulo 13.0 4.0)))
|
||||||
|
(pass-if (eqv? 1.0 (modulo 13 4.0)))
|
||||||
|
(pass-if (eqv? 1.0 (modulo 13.0 4 )))
|
||||||
|
|
||||||
;; Positive dividend and divisor
|
;; Positive dividend and divisor
|
||||||
|
|
||||||
(pass-if "13 % 4"
|
(pass-if "13 % 4"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue