From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Fast R6RS div/mod; improved extensibility of numerics Date: Mon, 31 Jan 2011 12:14:53 -0500 Message-ID: <871v3tyoz6.fsf@yeeloong.netris.org> References: <87lj221hn7.fsf@yeeloong.netris.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1296494132 17792 80.91.229.12 (31 Jan 2011 17:15:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 31 Jan 2011 17:15:32 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 31 18:15:27 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PjxLW-0004TI-DW for guile-devel@m.gmane.org; Mon, 31 Jan 2011 18:15:24 +0100 Original-Received: from localhost ([127.0.0.1]:35748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PjxLV-0000TR-0h for guile-devel@m.gmane.org; Mon, 31 Jan 2011 12:15:21 -0500 Original-Received: from [140.186.70.92] (port=42534 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PjxLF-0000Pl-U6 for guile-devel@gnu.org; Mon, 31 Jan 2011 12:15:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PjxLC-0007kq-Vr for guile-devel@gnu.org; Mon, 31 Jan 2011 12:15:05 -0500 Original-Received: from world.peace.net ([216.204.32.208]:35852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PjxLC-0007kY-J8 for guile-devel@gnu.org; Mon, 31 Jan 2011 12:15:02 -0500 Original-Received: from ip68-9-118-38.ri.ri.cox.net ([68.9.118.38] helo=freedomincluded) by world.peace.net with esmtpa (Exim 4.69) (envelope-from ) id 1PjxL5-0001eg-3V; Mon, 31 Jan 2011 12:14:55 -0500 Original-Received: from mhw by freedomincluded with local (Exim 4.69) (envelope-from ) id 1PjxL3-0001jS-DD; Mon, 31 Jan 2011 12:14:53 -0500 In-Reply-To: (Andy Wingo's message of "Sun, 30 Jan 2011 23:24:29 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 216.204.32.208 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11445 Archived-At: --=-=-= Andy Wingo 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Rename-euclidean-centered-_quo_rem-to-euclidean-ce.patch Content-Description: Rename {euclidean,centered}_quo_rem to {euclidean,centered}_divide >From b5441b4fc27ee4c9686c69307369d24f7cacd660 Mon Sep 17 00:00:00 2001 From: Mark H Weaver 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 --=-=-=--