diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-03-08 13:43:16 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-03-08 13:44:47 -0800 |
commit | 84d415e94c202c921f8a0e725f4ed7ece7cab04a (patch) | |
tree | 2da27aa55d4dab0337ac6187d5de5d9db7d4e450 /src/data.c | |
parent | de610c4b678e4634e20baa2afee7d8c921e1e3fc (diff) | |
download | emacs-84d415e94c202c921f8a0e725f4ed7ece7cab04a.tar.gz |
* src/data.c (arithcompare): Add comments.
Diffstat (limited to 'src/data.c')
-rw-r--r-- | src/data.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/data.c b/src/data.c index 997a41b6d05..fb7bf51c68e 100644 --- a/src/data.c +++ b/src/data.c @@ -2404,9 +2404,11 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2); /* If either arg is floating point, set F1 and F2 to the 'double' - approximations of the two arguments. Regardless, set I1 and I2 - to integers that break ties if the floating point comparison is - either not done or reports equality. */ + approximations of the two arguments, and set FNEQ if floating-point + comparison reports that F1 is not equal to F2, possibly because F1 + or F2 is a NaN. Regardless, set I1 and I2 to integers that break + ties if the floating-point comparison is either not done or reports + equality. */ if (FLOATP (num1)) { @@ -2417,7 +2419,17 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, f2 = XFLOAT_DATA (num2); } else - i1 = f2 = i2 = XINT (num2); + { + /* Compare a float NUM1 to an integer NUM2 by converting the + integer I2 (i.e., NUM2) to the double F2 (a conversion that + can round on some platforms, if I2 is large enough), and then + converting F2 back to the integer I1 (a conversion that is + always exact), so that I1 exactly equals ((double) NUM2). If + floating-point comparison reports a tie, NUM1 = F1 = F2 = I1 + (exactly) so I1 - I2 = NUM1 - NUM2 (exactly), so comparing I1 + to I2 will break the tie correctly. */ + i1 = f2 = i2 = XINT (num2); + } fneq = f1 != f2; } else @@ -2425,6 +2437,8 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, i1 = XINT (num1); if (FLOATP (num2)) { + /* Compare an integer NUM1 to a float NUM2. This is the + converse of comparing float to integer (see above). */ i2 = f1 = i1; f2 = XFLOAT_DATA (num2); fneq = f1 != f2; |