|
From: | Paul Eggert |
Subject: | Re: [Emacs-diffs] master 37940b3: min and max now return one of their arguments |
Date: | Tue, 7 Mar 2017 22:08:39 -0800 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
Stefan Monnier wrote:
I'm wondering what is the motivation for this change.
It avoids nonsensical behavior where 'min' and 'max' were inconsistent with '<' and '>'. Before the patch, (max A B) could return A even when (< A B) returned t. For example:
(let* ((a 1e16) (b (1+ (floor a)))) (list a b (max a b) (< a b) (if (< a b) b a)))returned (1e+16 10000000000000001 1e+16 t 10000000000000001) on a 64-bit GNU/Linux host just before the patch was applied. In this example, '<' is behaving correctly since A is less than B, and 'max' is behaving incorrectly since it is returning the lesser of A and B. (Come to think of it, this example is clearer than what's in etc/NEWS, so I'll update etc/NEWS.)
In the old days Emacs could assume that every Emacs integer had an exact floating-point representation, so it was OK for functions like '<' and 'max' to convert integer arguments to floating-point before doing their comparisons since these conversions could not lose information. This is no longer true, and the low-level code now needs to be more careful when comparing fixnums to floats.
[Prev in Thread] | Current Thread | [Next in Thread] |