diff options
| author | Paul Eggert | 2018-07-18 03:16:54 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-07-18 03:18:53 -0700 |
| commit | c70d22f70b77b053d01c7380122d166ecb728610 (patch) | |
| tree | 1fe0dee176da15fca2907c84abc7ec096b7e4116 /doc | |
| parent | ba6cc1d04cef8e25534a72e90a8f0f8db0026c9f (diff) | |
| download | emacs-c70d22f70b77b053d01c7380122d166ecb728610.tar.gz emacs-c70d22f70b77b053d01c7380122d166ecb728610.zip | |
Fix bug with eql etc. on NaNs
Fix a bug where eql, sxhash-eql, memql, and make-hash-table
were not consistent on NaNs. Likewise for equal,
sxhash-equal, member, and make-hash-table. Some of these
functions ignored NaN significands, whereas others treated
them as significant. It's more logical to treat significands
as significant, and this typically makes eql a bit more
efficient on floats, with just one integer comparison instead
of one to three floating-point comparisons.
* doc/lispref/numbers.texi (Float Basics): Document that
NaNs are never numerically equal, but might be eql.
* src/fns.c (WORDS_PER_DOUBLE): Move to top level of this file.
(union double_and_words): Now named, and at the top level of this file.
(same_float): New function.
(Fmemql, Feql, internal_equal, cmpfn_eql): Use it, so that
the corresponding functions treat NaNs consistently.
(sxhash_float): Simplify based on above-mentioned changes.
* test/src/fns-tests.el (fns-tests-equality-nan): New test.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/numbers.texi | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi index 2fed2b642fd..6c51b849d35 100644 --- a/doc/lispref/numbers.texi +++ b/doc/lispref/numbers.texi | |||
| @@ -232,13 +232,18 @@ distinguish them. | |||
| 232 | @cindex negative infinity | 232 | @cindex negative infinity |
| 233 | @cindex infinity | 233 | @cindex infinity |
| 234 | @cindex NaN | 234 | @cindex NaN |
| 235 | @findex eql | ||
| 236 | @findex sxhash-eql | ||
| 235 | The @acronym{IEEE} floating-point standard supports positive | 237 | The @acronym{IEEE} floating-point standard supports positive |
| 236 | infinity and negative infinity as floating-point values. It also | 238 | infinity and negative infinity as floating-point values. It also |
| 237 | provides for a class of values called NaN, or ``not a number''; | 239 | provides for a class of values called NaN, or ``not a number''; |
| 238 | numerical functions return such values in cases where there is no | 240 | numerical functions return such values in cases where there is no |
| 239 | correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN@. | 241 | correct answer. For example, @code{(/ 0.0 0.0)} returns a NaN@. |
| 240 | Although NaN values carry a sign, for practical purposes there is no other | 242 | A NaN is never numerically equal to any value, not even to itself. |
| 241 | significant difference between different NaN values in Emacs Lisp. | 243 | NaNs carry a sign and a significand, and non-numeric functions like |
| 244 | @code{eql} and @code{sxhash-eql} treat two NaNs as equal when their | ||
| 245 | signs and significands agree. Significands of NaNs are | ||
| 246 | machine-dependent and are not directly visible to Emacs Lisp. | ||
| 242 | 247 | ||
| 243 | Here are read syntaxes for these special floating-point values: | 248 | Here are read syntaxes for these special floating-point values: |
| 244 | 249 | ||