diff options
| author | Paul Eggert | 2017-03-08 13:43:16 -0800 |
|---|---|---|
| committer | Paul Eggert | 2017-03-08 13:44:47 -0800 |
| commit | 84d415e94c202c921f8a0e725f4ed7ece7cab04a (patch) | |
| tree | 2da27aa55d4dab0337ac6187d5de5d9db7d4e450 /src | |
| parent | de610c4b678e4634e20baa2afee7d8c921e1e3fc (diff) | |
| download | emacs-84d415e94c202c921f8a0e725f4ed7ece7cab04a.tar.gz emacs-84d415e94c202c921f8a0e725f4ed7ece7cab04a.zip | |
* src/data.c (arithcompare): Add comments.
Diffstat (limited to 'src')
| -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, | |||
| 2404 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2); | 2404 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2); |
| 2405 | 2405 | ||
| 2406 | /* If either arg is floating point, set F1 and F2 to the 'double' | 2406 | /* If either arg is floating point, set F1 and F2 to the 'double' |
| 2407 | approximations of the two arguments. Regardless, set I1 and I2 | 2407 | approximations of the two arguments, and set FNEQ if floating-point |
| 2408 | to integers that break ties if the floating point comparison is | 2408 | comparison reports that F1 is not equal to F2, possibly because F1 |
| 2409 | either not done or reports equality. */ | 2409 | or F2 is a NaN. Regardless, set I1 and I2 to integers that break |
| 2410 | ties if the floating-point comparison is either not done or reports | ||
| 2411 | equality. */ | ||
| 2410 | 2412 | ||
| 2411 | if (FLOATP (num1)) | 2413 | if (FLOATP (num1)) |
| 2412 | { | 2414 | { |
| @@ -2417,7 +2419,17 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, | |||
| 2417 | f2 = XFLOAT_DATA (num2); | 2419 | f2 = XFLOAT_DATA (num2); |
| 2418 | } | 2420 | } |
| 2419 | else | 2421 | else |
| 2420 | i1 = f2 = i2 = XINT (num2); | 2422 | { |
| 2423 | /* Compare a float NUM1 to an integer NUM2 by converting the | ||
| 2424 | integer I2 (i.e., NUM2) to the double F2 (a conversion that | ||
| 2425 | can round on some platforms, if I2 is large enough), and then | ||
| 2426 | converting F2 back to the integer I1 (a conversion that is | ||
| 2427 | always exact), so that I1 exactly equals ((double) NUM2). If | ||
| 2428 | floating-point comparison reports a tie, NUM1 = F1 = F2 = I1 | ||
| 2429 | (exactly) so I1 - I2 = NUM1 - NUM2 (exactly), so comparing I1 | ||
| 2430 | to I2 will break the tie correctly. */ | ||
| 2431 | i1 = f2 = i2 = XINT (num2); | ||
| 2432 | } | ||
| 2421 | fneq = f1 != f2; | 2433 | fneq = f1 != f2; |
| 2422 | } | 2434 | } |
| 2423 | else | 2435 | else |
| @@ -2425,6 +2437,8 @@ arithcompare (Lisp_Object num1, Lisp_Object num2, | |||
| 2425 | i1 = XINT (num1); | 2437 | i1 = XINT (num1); |
| 2426 | if (FLOATP (num2)) | 2438 | if (FLOATP (num2)) |
| 2427 | { | 2439 | { |
| 2440 | /* Compare an integer NUM1 to a float NUM2. This is the | ||
| 2441 | converse of comparing float to integer (see above). */ | ||
| 2428 | i2 = f1 = i1; | 2442 | i2 = f1 = i1; |
| 2429 | f2 = XFLOAT_DATA (num2); | 2443 | f2 = XFLOAT_DATA (num2); |
| 2430 | fneq = f1 != f2; | 2444 | fneq = f1 != f2; |