unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* division of integers by floats
@ 2004-05-05 20:21 Richard Stallman
  2004-05-06 21:17 ` Peter Whaite
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Stallman @ 2004-05-05 20:21 UTC (permalink / raw)


It seems like this is the best change to make.  Does it give correct
results?


*** data.c	27 Apr 2004 04:36:00 -0400	1.235
--- data.c	05 May 2004 14:09:22 -0400	
***************
*** 2520,2525 ****
--- 2520,2533 ----
      default:
        break;
      }
+ 
+   /* For division, if any arg is a float, do the computation
+      in floating point.  */
+   if (code == Adiv)
+     for (argnum = 0; argnum < nargs; argnum++)
+       if (FLOATP (args[argnum]))
+ 	return float_arith_driver ((double) accum, 0, code,
+ 				   nargs, args);
  
    for (argnum = 0; argnum < nargs; argnum++)
      {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: division of integers by floats
  2004-05-05 20:21 division of integers by floats Richard Stallman
@ 2004-05-06 21:17 ` Peter Whaite
  2004-05-08  1:21   ` Richard Stallman
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Whaite @ 2004-05-06 21:17 UTC (permalink / raw)
  Cc: rms

Richard Stallman <rms@gnu.org> wrote:
> It seems like this is the best change to make.  Does it give correct
> results?

It does with limited testing, but having it in the arith_driver like
that means the argument list gets unnecessarily scanned for floats when
there are 2 arguments.

Here's a patch to put the change in the DEFUN.  Note that there is no
effective change for the two arg form, so its still efficient and there
wont be any "surprises" for the dominant usage.

--- data.c      6 May 2004 00:10:15 -0000       1.237
+++ data.c      6 May 2004 20:24:25 -0000
@@ -2698,7 +2698,13 @@
      int nargs;
      Lisp_Object *args;
 {
-  return arith_driver (Adiv, nargs, args);
+  int argnum;
+  if (nargs == 2)
+    return arith_driver (Adiv, nargs, args);
+  for (argnum = 0; argnum < nargs; argnum++)
+    if (FLOATP (args[argnum]))
+      return float_arith_driver (0, 0, Adiv, nargs, args);
+  return arith_driver (Adiv, nargs, args);
 }
 
 DEFUN ("%", Frem, Srem, 2, 2, 0,


-- 
Peter Whaite (http://whaite.ca)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: division of integers by floats
  2004-05-06 21:17 ` Peter Whaite
@ 2004-05-08  1:21   ` Richard Stallman
  2004-05-08 10:28     ` Piet van Oostrum
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Stallman @ 2004-05-08  1:21 UTC (permalink / raw)
  Cc: emacs-devel

    Here's a patch to put the change in the DEFUN.  Note that there is no
    effective change for the two arg form, so its still efficient and there
    wont be any "surprises" for the dominant usage.

Your change is ok too.
(Could someone install it, as a "tiny change"?)

--- data.c      6 May 2004 00:10:15 -0000       1.237
+++ data.c      6 May 2004 20:24:25 -0000
@@ -2698,7 +2698,13 @@
      int nargs;
      Lisp_Object *args;
 {
-  return arith_driver (Adiv, nargs, args);
+  int argnum;
+  if (nargs == 2)
+    return arith_driver (Adiv, nargs, args);
+  for (argnum = 0; argnum < nargs; argnum++)
+    if (FLOATP (args[argnum]))
+      return float_arith_driver (0, 0, Adiv, nargs, args);
+  return arith_driver (Adiv, nargs, args);
 }
 
 DEFUN ("%", Frem, Srem, 2, 2, 0,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: division of integers by floats
  2004-05-08  1:21   ` Richard Stallman
@ 2004-05-08 10:28     ` Piet van Oostrum
  2004-05-09  0:49       ` Juanma Barranquero
  2004-05-12 15:00       ` Peter Whaite
  0 siblings, 2 replies; 6+ messages in thread
From: Piet van Oostrum @ 2004-05-08 10:28 UTC (permalink / raw)


>>>>> Richard Stallman <rms@gnu.org> (RS) wrote:

RS>     Here's a patch to put the change in the DEFUN.  Note that there is no
RS>     effective change for the two arg form, so its still efficient and there
RS>     wont be any "surprises" for the dominant usage.

RS> Your change is ok too.
RS> (Could someone install it, as a "tiny change"?)

RS> --- data.c      6 May 2004 00:10:15 -0000       1.237
RS> +++ data.c      6 May 2004 20:24:25 -0000
RS> @@ -2698,7 +2698,13 @@
RS>       int nargs;
RS>       Lisp_Object *args;
RS>  {
RS> -  return arith_driver (Adiv, nargs, args);
RS> +  int argnum;
RS> +  if (nargs == 2)
RS> +    return arith_driver (Adiv, nargs, args);
RS> +  for (argnum = 0; argnum < nargs; argnum++)
RS> +    if (FLOATP (args[argnum]))
RS> +      return float_arith_driver (0, 0, Adiv, nargs, args);
RS> +  return arith_driver (Adiv, nargs, args);
RS>  }

This can even be combined as:

+  int argnum;
+  for (argnum = 2; argnum < nargs; argnum++)
+    if (FLOATP (args[argnum]))
+      return float_arith_driver (0, 0, Adiv, nargs, args);
+  return arith_driver (Adiv, nargs, args);

-- 
Piet van Oostrum <piet@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum@hccnet.nl

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: division of integers by floats
  2004-05-08 10:28     ` Piet van Oostrum
@ 2004-05-09  0:49       ` Juanma Barranquero
  2004-05-12 15:00       ` Peter Whaite
  1 sibling, 0 replies; 6+ messages in thread
From: Juanma Barranquero @ 2004-05-09  0:49 UTC (permalink / raw)


On 08 May 2004 12:28:12 +0200, Piet van Oostrum <piet@cs.uu.nl> wrote:

> +  int argnum;
> +  for (argnum = 2; argnum < nargs; argnum++)
> +    if (FLOATP (args[argnum]))
> +      return float_arith_driver (0, 0, Adiv, nargs, args);
> +  return arith_driver (Adiv, nargs, args);

Installed.

                                                           /L/e/k/t/u

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: division of integers by floats
  2004-05-08 10:28     ` Piet van Oostrum
  2004-05-09  0:49       ` Juanma Barranquero
@ 2004-05-12 15:00       ` Peter Whaite
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Whaite @ 2004-05-12 15:00 UTC (permalink / raw)
  Cc: emacs-devel

Piet van Oostrum <piet@cs.uu.nl> wrote:
> This can even be combined as:
> 
> +  int argnum;
> +  for (argnum = 2; argnum < nargs; argnum++)
> +    if (FLOATP (args[argnum]))
> +      return float_arith_driver (0, 0, Adiv, nargs, args);
> +  return arith_driver (Adiv, nargs, args);

Thats a nice optimization.

-- 
Peter Whaite (http://whaite.ca)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-05-12 15:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-05 20:21 division of integers by floats Richard Stallman
2004-05-06 21:17 ` Peter Whaite
2004-05-08  1:21   ` Richard Stallman
2004-05-08 10:28     ` Piet van Oostrum
2004-05-09  0:49       ` Juanma Barranquero
2004-05-12 15:00       ` Peter Whaite

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).