emacs-devel
[Top][All Lists]
Advanced

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

Re: Strange division using mixed integers and floats


From: Lars Brinkhoff
Subject: Re: Strange division using mixed integers and floats
Date: 28 Apr 2004 15:20:56 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

David Kastrup <address@hidden> writes:
> Richard Stallman <address@hidden> writes:
> >     But this behaviour is *highly* confusing:
> >     (/ 5 4 2.3) => 0.4347826086956522
> >     Cf. (/ 5 4.0 2.3) => 0.5434782608695653
> > 
> > We could change the functions to convert the arguments to floating
> > point at the start if any is floating point.  Is there any reason
> > not to do that?
> 
> Efficiency?  Lisp is not a statically typed language.  We don't know
> the type of the arguments until after they have been evaluated.  We
> would have to store all intermediate results away before being
> allowed to do the first operation.

Seems like it's only a matter of changing arith_driver to do

      if (FLOATP (val))
        {
          if (code == Adiv)
            return float_arith_driver (0.0, 0, code, nargs, args);
          else
            return float_arith_driver ((double) accum, argnum, code,
                                       nargs, args);
        }

or similar.  Loss of efficiency should be small.

> Also (/ 5 4 2.3) would no longer be equivalent to (/ (/ 5 4) 2.3).

That's more significant, as it's a user-visible change.

-- 
Lars Brinkhoff,         Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting    http://www.brinkhoff.se/





reply via email to

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