emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fix for inconsistent (/ DIVIDEND DIVISOR &rest DIVISORS)


From: Peter Whaite
Subject: Fix for inconsistent (/ DIVIDEND DIVISOR &rest DIVISORS)
Date: Tue, 04 May 2004 18:27:11 -0400

Some time ago there was a thread on division being inconsistent when
floats were involved.  I dont know what the outcome of that discussion
was, but it did occur to me that the simplest fix would be to multiply
the divisors before doing the division.  Here is code for that
(src/data.c)...

DEFUN ("/", Fquo, Squo, 2, MANY, 0,
       doc: /* Return first argument divided by all the remaining arguments.
The arguments must be numbers or markers.
usage: (/ DIVIDEND DIVISOR &rest DIVISORS)  */)
     (nargs, args)
     int nargs;
     Lisp_Object *args;
{
  if (nargs == 2) {
    return arith_driver (Adiv, nargs, args);
  }
  else {
    Lisp_Object divArgs[2];
    divArgs[0] = args[0];
    divArgs[1] = arith_driver (Amult, nargs-1, args+1);
    return arith_driver (Adiv, 2, divArgs);
  }
}

I've left nargs==2 as a special case for efficiency, because it wont
change the existing behavior for 2 arguments, and because 2 arguments is
by far the most common, and perhaps only, usage I see in the cvs *.el
files.

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]