From: Mark H Weaver <mhw@netris.org>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Fast R6RS div/mod; improved extensibility of numerics
Date: Mon, 31 Jan 2011 12:14:53 -0500 [thread overview]
Message-ID: <871v3tyoz6.fsf@yeeloong.netris.org> (raw)
In-Reply-To: <m38vy2yqqq.fsf@unquote.localdomain> (Andy Wingo's message of "Sun, 30 Jan 2011 23:24:29 +0100")
[-- Attachment #1: Type: text/plain, Size: 252 bytes --]
Andy Wingo <wingo@pobox.com> writes:
> If you have time though, I wonder would scm_centered_divide be a better
> name than scm_centered_quo_and_rem? "Divide" is the pronunciation of
> the "/" procedure, I think.
Agreed, here's a patch.
Mark
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Rename {euclidean,centered}_quo_rem to {euclidean,centered}_divide --]
[-- Type: text/x-diff, Size: 15157 bytes --]
From b5441b4fc27ee4c9686c69307369d24f7cacd660 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Mon, 31 Jan 2011 12:03:02 -0500
Subject: [PATCH] Rename {euclidean,centered}_quo_rem to {euclidean,centered}_divide
* libguile/numbers.c (euclidean_quo_rem): Rename to euclidean_divide.
(centered_quo_rem): Rename to {euclidean,centered}_divide.
* libguile/numbers.h: Rename euclidean_quo_rem to euclidean_divide and
centered_quo_rem to centered_divide.
* doc/ref/api-data.texi: Rename euclidean_quo_rem to euclidean_divide and
centered_quo_rem to centered_divide.
---
doc/ref/api-data.texi | 4 +-
libguile/numbers.c | 126 ++++++++++++++++++++++++------------------------
libguile/numbers.h | 4 +-
3 files changed, 67 insertions(+), 67 deletions(-)
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index b090782..b819fcb 100755
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -1244,7 +1244,7 @@ values.
@deffn {Scheme Procedure} euclidean/ x y
@deffnx {Scheme Procedure} euclidean-quotient x y
@deffnx {Scheme Procedure} euclidean-remainder x y
-@deffnx {C Function} scm_euclidean_quo_and_rem (x y)
+@deffnx {C Function} scm_euclidean_divide (x y)
@deffnx {C Function} scm_euclidean_quotient (x y)
@deffnx {C Function} scm_euclidean_remainder (x y)
These procedures accept two real numbers @var{x} and @var{y}, where the
@@ -1275,7 +1275,7 @@ Note that these operators are equivalent to the R6RS operators
@deffn {Scheme Procedure} centered/ x y
@deffnx {Scheme Procedure} centered-quotient x y
@deffnx {Scheme Procedure} centered-remainder x y
-@deffnx {C Function} scm_centered_quo_and_rem (x y)
+@deffnx {C Function} scm_centered_divide (x y)
@deffnx {C Function} scm_centered_quotient (x y)
@deffnx {C Function} scm_centered_remainder (x y)
These procedures accept two real numbers @var{x} and @var{y}, where the
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 3a2244f..41d178b 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -1384,10 +1384,10 @@ scm_i_slow_exact_euclidean_remainder (SCM x, SCM y)
}
-static SCM scm_i_inexact_euclidean_quo_and_rem (double x, double y);
-static SCM scm_i_slow_exact_euclidean_quo_and_rem (SCM x, SCM y);
+static SCM scm_i_inexact_euclidean_divide (double x, double y);
+static SCM scm_i_slow_exact_euclidean_divide (SCM x, SCM y);
-SCM_PRIMITIVE_GENERIC (scm_euclidean_quo_and_rem, "euclidean/", 2, 0, 0,
+SCM_PRIMITIVE_GENERIC (scm_euclidean_divide, "euclidean/", 2, 0, 0,
(SCM x, SCM y),
"Return the integer @var{q} and the real number @var{r}\n"
"such that @math{@var{x} = @var{q}*@var{y} + @var{r}}\n"
@@ -1400,7 +1400,7 @@ SCM_PRIMITIVE_GENERIC (scm_euclidean_quo_and_rem, "euclidean/", 2, 0, 0,
"(euclidean/ -123.2 -63.5) @result{} 2.0 and 3.8\n"
"(euclidean/ 16/3 -10/7) @result{} -3 and 22/21\n"
"@end lisp")
-#define FUNC_NAME s_scm_euclidean_quo_and_rem
+#define FUNC_NAME s_scm_euclidean_divide
{
if (SCM_LIKELY (SCM_I_INUMP (x)))
{
@@ -1408,7 +1408,7 @@ SCM_PRIMITIVE_GENERIC (scm_euclidean_quo_and_rem, "euclidean/", 2, 0, 0,
{
scm_t_inum yy = SCM_I_INUM (y);
if (SCM_UNLIKELY (yy == 0))
- scm_num_overflow (s_scm_euclidean_quo_and_rem);
+ scm_num_overflow (s_scm_euclidean_divide);
else
{
scm_t_inum xx = SCM_I_INUM (x);
@@ -1448,13 +1448,13 @@ SCM_PRIMITIVE_GENERIC (scm_euclidean_quo_and_rem, "euclidean/", 2, 0, 0,
}
}
else if (SCM_REALP (y))
- return scm_i_inexact_euclidean_quo_and_rem
+ return scm_i_inexact_euclidean_divide
(SCM_I_INUM (x), SCM_REAL_VALUE (y));
else if (SCM_FRACTIONP (y))
- return scm_i_slow_exact_euclidean_quo_and_rem (x, y);
+ return scm_i_slow_exact_euclidean_divide (x, y);
else
- SCM_WTA_DISPATCH_2 (g_scm_euclidean_quo_and_rem, x, y, SCM_ARG2,
- s_scm_euclidean_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_euclidean_divide, x, y, SCM_ARG2,
+ s_scm_euclidean_divide);
}
else if (SCM_BIGP (x))
{
@@ -1462,7 +1462,7 @@ SCM_PRIMITIVE_GENERIC (scm_euclidean_quo_and_rem, "euclidean/", 2, 0, 0,
{
scm_t_inum yy = SCM_I_INUM (y);
if (SCM_UNLIKELY (yy == 0))
- scm_num_overflow (s_scm_euclidean_quo_and_rem);
+ scm_num_overflow (s_scm_euclidean_divide);
else
{
SCM q = scm_i_mkbig ();
@@ -1496,40 +1496,40 @@ SCM_PRIMITIVE_GENERIC (scm_euclidean_quo_and_rem, "euclidean/", 2, 0, 0,
scm_i_normbig (r)));
}
else if (SCM_REALP (y))
- return scm_i_inexact_euclidean_quo_and_rem
+ return scm_i_inexact_euclidean_divide
(scm_i_big2dbl (x), SCM_REAL_VALUE (y));
else if (SCM_FRACTIONP (y))
- return scm_i_slow_exact_euclidean_quo_and_rem (x, y);
+ return scm_i_slow_exact_euclidean_divide (x, y);
else
- SCM_WTA_DISPATCH_2 (g_scm_euclidean_quo_and_rem, x, y, SCM_ARG2,
- s_scm_euclidean_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_euclidean_divide, x, y, SCM_ARG2,
+ s_scm_euclidean_divide);
}
else if (SCM_REALP (x))
{
if (SCM_REALP (y) || SCM_I_INUMP (y) ||
SCM_BIGP (y) || SCM_FRACTIONP (y))
- return scm_i_inexact_euclidean_quo_and_rem
+ return scm_i_inexact_euclidean_divide
(SCM_REAL_VALUE (x), scm_to_double (y));
else
- SCM_WTA_DISPATCH_2 (g_scm_euclidean_quo_and_rem, x, y, SCM_ARG2,
- s_scm_euclidean_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_euclidean_divide, x, y, SCM_ARG2,
+ s_scm_euclidean_divide);
}
else if (SCM_FRACTIONP (x))
{
if (SCM_REALP (y))
- return scm_i_inexact_euclidean_quo_and_rem
+ return scm_i_inexact_euclidean_divide
(scm_i_fraction2double (x), SCM_REAL_VALUE (y));
else
- return scm_i_slow_exact_euclidean_quo_and_rem (x, y);
+ return scm_i_slow_exact_euclidean_divide (x, y);
}
else
- SCM_WTA_DISPATCH_2 (g_scm_euclidean_quo_and_rem, x, y, SCM_ARG1,
- s_scm_euclidean_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_euclidean_divide, x, y, SCM_ARG1,
+ s_scm_euclidean_divide);
}
#undef FUNC_NAME
static SCM
-scm_i_inexact_euclidean_quo_and_rem (double x, double y)
+scm_i_inexact_euclidean_divide (double x, double y)
{
double q, r;
@@ -1538,7 +1538,7 @@ scm_i_inexact_euclidean_quo_and_rem (double x, double y)
else if (SCM_LIKELY (y < 0))
q = ceil (x / y);
else if (y == 0)
- scm_num_overflow (s_scm_euclidean_quo_and_rem); /* or return a NaN? */
+ scm_num_overflow (s_scm_euclidean_divide); /* or return a NaN? */
else
q = guile_NaN;
r = x - q * y;
@@ -1550,22 +1550,22 @@ scm_i_inexact_euclidean_quo_and_rem (double x, double y)
We use this only if both arguments are exact,
and at least one of them is a fraction */
static SCM
-scm_i_slow_exact_euclidean_quo_and_rem (SCM x, SCM y)
+scm_i_slow_exact_euclidean_divide (SCM x, SCM y)
{
SCM q, r;
if (!(SCM_I_INUMP (x) || SCM_BIGP (x) || SCM_FRACTIONP (x)))
- SCM_WTA_DISPATCH_2 (g_scm_euclidean_quo_and_rem, x, y, SCM_ARG1,
- s_scm_euclidean_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_euclidean_divide, x, y, SCM_ARG1,
+ s_scm_euclidean_divide);
else if (!(SCM_I_INUMP (y) || SCM_BIGP (y) || SCM_FRACTIONP (y)))
- SCM_WTA_DISPATCH_2 (g_scm_euclidean_quo_and_rem, x, y, SCM_ARG2,
- s_scm_euclidean_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_euclidean_divide, x, y, SCM_ARG2,
+ s_scm_euclidean_divide);
else if (scm_is_true (scm_positive_p (y)))
q = scm_floor (scm_divide (x, y));
else if (scm_is_true (scm_negative_p (y)))
q = scm_ceiling (scm_divide (x, y));
else
- scm_num_overflow (s_scm_euclidean_quo_and_rem);
+ scm_num_overflow (s_scm_euclidean_divide);
r = scm_difference (x, scm_product (q, y));
return scm_values (scm_list_2 (q, r));
}
@@ -2025,11 +2025,11 @@ scm_i_slow_exact_centered_remainder (SCM x, SCM y)
}
-static SCM scm_i_inexact_centered_quo_and_rem (double x, double y);
-static SCM scm_i_bigint_centered_quo_and_rem (SCM x, SCM y);
-static SCM scm_i_slow_exact_centered_quo_and_rem (SCM x, SCM y);
+static SCM scm_i_inexact_centered_divide (double x, double y);
+static SCM scm_i_bigint_centered_divide (SCM x, SCM y);
+static SCM scm_i_slow_exact_centered_divide (SCM x, SCM y);
-SCM_PRIMITIVE_GENERIC (scm_centered_quo_and_rem, "centered/", 2, 0, 0,
+SCM_PRIMITIVE_GENERIC (scm_centered_divide, "centered/", 2, 0, 0,
(SCM x, SCM y),
"Return the integer @var{q} and the real number @var{r}\n"
"such that @math{@var{x} = @var{q}*@var{y} + @var{r}}\n"
@@ -2042,7 +2042,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quo_and_rem, "centered/", 2, 0, 0,
"(centered/ -123.2 -63.5) @result{} 2.0 and 3.8\n"
"(centered/ 16/3 -10/7) @result{} -4 and -8/21\n"
"@end lisp")
-#define FUNC_NAME s_scm_centered_quo_and_rem
+#define FUNC_NAME s_scm_centered_divide
{
if (SCM_LIKELY (SCM_I_INUMP (x)))
{
@@ -2050,7 +2050,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quo_and_rem, "centered/", 2, 0, 0,
{
scm_t_inum yy = SCM_I_INUM (y);
if (SCM_UNLIKELY (yy == 0))
- scm_num_overflow (s_scm_centered_quo_and_rem);
+ scm_num_overflow (s_scm_centered_divide);
else
{
scm_t_inum xx = SCM_I_INUM (x);
@@ -2089,18 +2089,18 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quo_and_rem, "centered/", 2, 0, 0,
else if (SCM_BIGP (y))
{
/* Pass a denormalized bignum version of x (even though it
- can fit in a fixnum) to scm_i_bigint_centered_quo_and_rem */
- return scm_i_bigint_centered_quo_and_rem
+ can fit in a fixnum) to scm_i_bigint_centered_divide */
+ return scm_i_bigint_centered_divide
(scm_i_long2big (SCM_I_INUM (x)), y);
}
else if (SCM_REALP (y))
- return scm_i_inexact_centered_quo_and_rem
+ return scm_i_inexact_centered_divide
(SCM_I_INUM (x), SCM_REAL_VALUE (y));
else if (SCM_FRACTIONP (y))
- return scm_i_slow_exact_centered_quo_and_rem (x, y);
+ return scm_i_slow_exact_centered_divide (x, y);
else
- SCM_WTA_DISPATCH_2 (g_scm_centered_quo_and_rem, x, y, SCM_ARG2,
- s_scm_centered_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_centered_divide, x, y, SCM_ARG2,
+ s_scm_centered_divide);
}
else if (SCM_BIGP (x))
{
@@ -2108,7 +2108,7 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quo_and_rem, "centered/", 2, 0, 0,
{
scm_t_inum yy = SCM_I_INUM (y);
if (SCM_UNLIKELY (yy == 0))
- scm_num_overflow (s_scm_centered_quo_and_rem);
+ scm_num_overflow (s_scm_centered_divide);
else
{
SCM q = scm_i_mkbig ();
@@ -2146,42 +2146,42 @@ SCM_PRIMITIVE_GENERIC (scm_centered_quo_and_rem, "centered/", 2, 0, 0,
}
}
else if (SCM_BIGP (y))
- return scm_i_bigint_centered_quo_and_rem (x, y);
+ return scm_i_bigint_centered_divide (x, y);
else if (SCM_REALP (y))
- return scm_i_inexact_centered_quo_and_rem
+ return scm_i_inexact_centered_divide
(scm_i_big2dbl (x), SCM_REAL_VALUE (y));
else if (SCM_FRACTIONP (y))
- return scm_i_slow_exact_centered_quo_and_rem (x, y);
+ return scm_i_slow_exact_centered_divide (x, y);
else
- SCM_WTA_DISPATCH_2 (g_scm_centered_quo_and_rem, x, y, SCM_ARG2,
- s_scm_centered_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_centered_divide, x, y, SCM_ARG2,
+ s_scm_centered_divide);
}
else if (SCM_REALP (x))
{
if (SCM_REALP (y) || SCM_I_INUMP (y) ||
SCM_BIGP (y) || SCM_FRACTIONP (y))
- return scm_i_inexact_centered_quo_and_rem
+ return scm_i_inexact_centered_divide
(SCM_REAL_VALUE (x), scm_to_double (y));
else
- SCM_WTA_DISPATCH_2 (g_scm_centered_quo_and_rem, x, y, SCM_ARG2,
- s_scm_centered_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_centered_divide, x, y, SCM_ARG2,
+ s_scm_centered_divide);
}
else if (SCM_FRACTIONP (x))
{
if (SCM_REALP (y))
- return scm_i_inexact_centered_quo_and_rem
+ return scm_i_inexact_centered_divide
(scm_i_fraction2double (x), SCM_REAL_VALUE (y));
else
- return scm_i_slow_exact_centered_quo_and_rem (x, y);
+ return scm_i_slow_exact_centered_divide (x, y);
}
else
- SCM_WTA_DISPATCH_2 (g_scm_centered_quo_and_rem, x, y, SCM_ARG1,
- s_scm_centered_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_centered_divide, x, y, SCM_ARG1,
+ s_scm_centered_divide);
}
#undef FUNC_NAME
static SCM
-scm_i_inexact_centered_quo_and_rem (double x, double y)
+scm_i_inexact_centered_divide (double x, double y)
{
double q, r;
@@ -2190,7 +2190,7 @@ scm_i_inexact_centered_quo_and_rem (double x, double y)
else if (SCM_LIKELY (y < 0))
q = ceil (x/y - 0.5);
else if (y == 0)
- scm_num_overflow (s_scm_centered_quo_and_rem); /* or return a NaN? */
+ scm_num_overflow (s_scm_centered_divide); /* or return a NaN? */
else
q = guile_NaN;
r = x - q * y;
@@ -2201,7 +2201,7 @@ scm_i_inexact_centered_quo_and_rem (double x, double y)
/* Assumes that both x and y are bigints, though
x might be able to fit into a fixnum. */
static SCM
-scm_i_bigint_centered_quo_and_rem (SCM x, SCM y)
+scm_i_bigint_centered_divide (SCM x, SCM y)
{
SCM q, r, min_r;
@@ -2254,16 +2254,16 @@ scm_i_bigint_centered_quo_and_rem (SCM x, SCM y)
We use this only if both arguments are exact,
and at least one of them is a fraction */
static SCM
-scm_i_slow_exact_centered_quo_and_rem (SCM x, SCM y)
+scm_i_slow_exact_centered_divide (SCM x, SCM y)
{
SCM q, r;
if (!(SCM_I_INUMP (x) || SCM_BIGP (x) || SCM_FRACTIONP (x)))
- SCM_WTA_DISPATCH_2 (g_scm_centered_quo_and_rem, x, y, SCM_ARG1,
- s_scm_centered_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_centered_divide, x, y, SCM_ARG1,
+ s_scm_centered_divide);
else if (!(SCM_I_INUMP (y) || SCM_BIGP (y) || SCM_FRACTIONP (y)))
- SCM_WTA_DISPATCH_2 (g_scm_centered_quo_and_rem, x, y, SCM_ARG2,
- s_scm_centered_quo_and_rem);
+ SCM_WTA_DISPATCH_2 (g_scm_centered_divide, x, y, SCM_ARG2,
+ s_scm_centered_divide);
else if (scm_is_true (scm_positive_p (y)))
q = scm_floor (scm_sum (scm_divide (x, y),
exactly_one_half));
@@ -2271,7 +2271,7 @@ scm_i_slow_exact_centered_quo_and_rem (SCM x, SCM y)
q = scm_ceiling (scm_difference (scm_divide (x, y),
exactly_one_half));
else
- scm_num_overflow (s_scm_centered_quo_and_rem);
+ scm_num_overflow (s_scm_centered_divide);
r = scm_difference (x, scm_product (q, y));
return scm_values (scm_list_2 (q, r));
}
diff --git a/libguile/numbers.h b/libguile/numbers.h
index 2cf3fd7..10a4f17 100644
--- a/libguile/numbers.h
+++ b/libguile/numbers.h
@@ -178,10 +178,10 @@ SCM_API SCM scm_abs (SCM x);
SCM_API SCM scm_quotient (SCM x, SCM y);
SCM_API SCM scm_remainder (SCM x, SCM y);
SCM_API SCM scm_modulo (SCM x, SCM y);
-SCM_API SCM scm_euclidean_quo_and_rem (SCM x, SCM y);
+SCM_API SCM scm_euclidean_divide (SCM x, SCM y);
SCM_API SCM scm_euclidean_quotient (SCM x, SCM y);
SCM_API SCM scm_euclidean_remainder (SCM x, SCM y);
-SCM_API SCM scm_centered_quo_and_rem (SCM x, SCM y);
+SCM_API SCM scm_centered_divide (SCM x, SCM y);
SCM_API SCM scm_centered_quotient (SCM x, SCM y);
SCM_API SCM scm_centered_remainder (SCM x, SCM y);
SCM_API SCM scm_gcd (SCM x, SCM y);
--
1.5.6.5
next prev parent reply other threads:[~2011-01-31 17:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-30 16:27 [PATCH] Fast R6RS div/mod; improved extensibility of numerics Mark H Weaver
2011-01-30 22:24 ` Andy Wingo
2011-01-30 22:55 ` Ludovic Courtès
2011-01-31 6:19 ` [PATCH] Rework the testing framework for number-theoretic division operators Mark H Weaver
2011-01-31 8:52 ` Andy Wingo
2011-01-31 17:14 ` Mark H Weaver [this message]
2011-01-31 17:35 ` [PATCH] Fast R6RS div/mod; improved extensibility of numerics Mark H Weaver
2011-01-31 19:26 ` Andy Wingo
2011-01-31 20:16 ` Andy Wingo
2011-01-31 20:30 ` Mark H Weaver
2011-01-31 20:46 ` Andy Wingo
2011-01-31 20:46 ` Mark H Weaver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871v3tyoz6.fsf@yeeloong.netris.org \
--to=mhw@netris.org \
--cc=guile-devel@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).