aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-11-10 15:01:06 -0800
committerPaul Eggert2019-11-10 15:04:20 -0800
commitb6942c0c37a504e00c717c8c74bfa9dcd208c931 (patch)
tree40565eb305e75021b6d96e90fd678c87a9de10be
parent6ad5eb97940b07bf8d28f8517608351b3af1221c (diff)
downloademacs-b6942c0c37a504e00c717c8c74bfa9dcd208c931.tar.gz
emacs-b6942c0c37a504e00c717c8c74bfa9dcd208c931.zip
Document Lisp floats a bit better
* doc/lispref/numbers.texi (Float Basics): * doc/misc/cl.texi (Implementation Parameters): * lisp/emacs-lisp/cl-lib.el (cl-most-positive-float) (cl-least-positive-float) (cl-least-positive-normalized-float, cl-float-epsilon) (cl-float-negative-epsilon): Document IEEE floating point better. Don’t suggest that Emacs might use some floating-point format other than IEEE format, as Emacs currently assumes IEEE in several places and there seems little point in removing those assumptions.
-rw-r--r--doc/lispref/numbers.texi8
-rw-r--r--doc/misc/cl.texi54
-rw-r--r--lisp/emacs-lisp/cl-lib.el16
3 files changed, 37 insertions, 41 deletions
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index 0c71387a8a7..939ad5c85a1 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -218,8 +218,12 @@ considered to be valid as a character. @xref{Character Codes}.
218 Floating-point numbers are useful for representing numbers that are 218 Floating-point numbers are useful for representing numbers that are
219not integral. The range of floating-point numbers is 219not integral. The range of floating-point numbers is
220the same as the range of the C data type @code{double} on the machine 220the same as the range of the C data type @code{double} on the machine
221you are using. On all computers currently supported by Emacs, this is 221you are using. On all computers supported by Emacs, this is
222double-precision @acronym{IEEE} floating point. 222@acronym{IEEE} binary64 floating point format, which is standardized by
223@url{https://standards.ieee.org/standard/754-2019.html,,IEEE Std 754-2019}
224and is discussed further in David Goldberg's paper
225``@url{https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html,
226What Every Computer Scientist Should Know About Floating-Point Arithmetic}''.
223 227
224 The read syntax for floating-point numbers requires either a decimal 228 The read syntax for floating-point numbers requires either a decimal
225point, an exponent, or both. Optional signs (@samp{+} or @samp{-}) 229point, an exponent, or both. Optional signs (@samp{+} or @samp{-})
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 246f86bfd1a..cfdbc7c41b2 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -3113,48 +3113,42 @@ function that must be called before the parameters can be used.
3113@defun cl-float-limits 3113@defun cl-float-limits
3114This function makes sure that the Common Lisp floating-point parameters 3114This function makes sure that the Common Lisp floating-point parameters
3115like @code{cl-most-positive-float} have been initialized. Until it is 3115like @code{cl-most-positive-float} have been initialized. Until it is
3116called, these parameters will be @code{nil}. 3116called, these parameters have unspecified values.
3117@c If this version of Emacs does not support floats, the parameters will
3118@c remain @code{nil}.
3119If the parameters have already been initialized, the function returns 3117If the parameters have already been initialized, the function returns
3120immediately. 3118immediately.
3121
3122The algorithm makes assumptions that will be valid for almost all
3123machines, but will fail if the machine's arithmetic is extremely
3124unusual, e.g., decimal.
3125@end defun 3119@end defun
3126 3120
3127Since true Common Lisp supports up to four different kinds of floating-point 3121Since true Common Lisp supports up to four different kinds of floating-point
3128numbers, it has families of constants like 3122numbers, it has families of constants like
3129@code{most-positive-single-float}, @code{most-positive-double-float}, 3123@code{most-positive-single-float}, @code{most-positive-double-float},
3130@code{most-positive-long-float}, and so on. Emacs has only one 3124@code{most-positive-long-float}, and so on. This package uses just
3131kind of floating-point number, so this package just uses single constants. 3125one set of constants because Emacs has only one kind of
3126floating-point number, namely the IEEE binary64 floating-point format.
3127@xref{Float Basics,,,elisp,GNU Emacs Lisp Reference Manual}.
3132 3128
3133@defvar cl-most-positive-float 3129@defvar cl-most-positive-float
3134This constant equals the largest value a Lisp float can hold. 3130This constant equals the largest finite value a Lisp float can hold.
3135For those systems whose arithmetic supports infinities, this is 3131For IEEE binary64 format, this equals @code{(- (expt 2 1024) (- 2
3136the largest @emph{finite} value. For IEEE machines, the value 3132971))}, which equals @code{1.7976931348623157e+308}.
3137is approximately @code{1.79e+308}.
3138@end defvar 3133@end defvar
3139 3134
3140@defvar cl-most-negative-float 3135@defvar cl-most-negative-float
3141This constant equals the most negative value a Lisp float can hold. 3136This constant equals the most negative finite value a Lisp float can hold.
3142(It is assumed to be equal to @code{(- cl-most-positive-float)}.) 3137For IEEE binary64 format, this equals @code{(- cl-most-positive-float)}.
3143@end defvar 3138@end defvar
3144 3139
3145@defvar cl-least-positive-float 3140@defvar cl-least-positive-normalized-float
3146This constant equals the smallest Lisp float value greater than zero. 3141This constant equals the smallest positive Lisp float that is
3147For IEEE machines, it is about @code{4.94e-324} if denormals are 3142@dfn{normalized}, i.e., that has full precision.
3148supported or @code{2.22e-308} if not. 3143For IEEE binary64 format, this equals @code{(expt 2 -1022)},
3144which equals @code{2.2250738585072014e-308}.
3149@end defvar 3145@end defvar
3150 3146
3151@defvar cl-least-positive-normalized-float 3147@defvar cl-least-positive-float
3152This constant equals the smallest @emph{normalized} Lisp float greater 3148This constant equals the smallest Lisp float value greater than zero.
3153than zero, i.e., the smallest value for which IEEE denormalization 3149For IEEE binary64 format, this equals @code{5e-324} (which equals
3154will not result in a loss of precision. For IEEE machines, this 3150@code{(expt 2 -1074)}) if subnormal numbers are supported, and
3155value is about @code{2.22e-308}. For machines that do not support 3151@code{cl-least-positive-normalized-float} otherwise.
3156the concept of denormalization and gradual underflow, this constant
3157will always equal @code{cl-least-positive-float}.
3158@end defvar 3152@end defvar
3159 3153
3160@defvar cl-least-negative-float 3154@defvar cl-least-negative-float
@@ -3169,14 +3163,14 @@ This constant is the negative counterpart of
3169@defvar cl-float-epsilon 3163@defvar cl-float-epsilon
3170This constant is the smallest positive Lisp float that can be added 3164This constant is the smallest positive Lisp float that can be added
3171to 1.0 to produce a distinct value. Adding a smaller number to 1.0 3165to 1.0 to produce a distinct value. Adding a smaller number to 1.0
3172will yield 1.0 again due to roundoff. For IEEE machines, epsilon 3166will yield 1.0 again due to roundoff. For IEEE binary64 format, this
3173is about @code{2.22e-16}. 3167equals @code{(expt 2 -52)}, which equals @code{2.220446049250313e-16}.
3174@end defvar 3168@end defvar
3175 3169
3176@defvar cl-float-negative-epsilon 3170@defvar cl-float-negative-epsilon
3177This is the smallest positive value that can be subtracted from 3171This is the smallest positive value that can be subtracted from
31781.0 to produce a distinct value. For IEEE machines, it is about 31721.0 to produce a distinct value. For IEEE binary64 format, this
3179@code{1.11e-16}. 3173equals @code{(expt 2 -53)}, which equals @code{1.1102230246251565e-16}.
3180@end defvar 3174@end defvar
3181 3175
3182@node Sequences 3176@node Sequences
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index ff096918173..7d0df27e14b 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -299,7 +299,7 @@ If true return the decimal value of digit CHAR in RADIX."
299(defconst cl-most-positive-float nil 299(defconst cl-most-positive-float nil
300 "The largest value that a Lisp float can hold. 300 "The largest value that a Lisp float can hold.
301If your system supports infinities, this is the largest finite value. 301If your system supports infinities, this is the largest finite value.
302For IEEE machines, this is approximately 1.79e+308. 302For Emacs, this equals 1.7976931348623157e+308.
303Call `cl-float-limits' to set this.") 303Call `cl-float-limits' to set this.")
304 304
305(defconst cl-most-negative-float nil 305(defconst cl-most-negative-float nil
@@ -309,8 +309,8 @@ Call `cl-float-limits' to set this.")
309 309
310(defconst cl-least-positive-float nil 310(defconst cl-least-positive-float nil
311 "The smallest value greater than zero that a Lisp float can hold. 311 "The smallest value greater than zero that a Lisp float can hold.
312For IEEE machines, it is about 4.94e-324 if denormals are supported, 312For Emacs, this equals 5e-324 if subnormal numbers are supported,
313or 2.22e-308 if they are not. 313`cl-least-positive-normalized-float' if they are not.
314Call `cl-float-limits' to set this.") 314Call `cl-float-limits' to set this.")
315 315
316(defconst cl-least-negative-float nil 316(defconst cl-least-negative-float nil
@@ -320,10 +320,8 @@ Call `cl-float-limits' to set this.")
320 320
321(defconst cl-least-positive-normalized-float nil 321(defconst cl-least-positive-normalized-float nil
322 "The smallest normalized Lisp float greater than zero. 322 "The smallest normalized Lisp float greater than zero.
323This is the smallest value for which IEEE denormalization does not lose 323This is the smallest value that has full precision.
324precision. For IEEE machines, this value is about 2.22e-308. 324For Emacs, this equals 2.2250738585072014e-308.
325For machines that do not support the concept of denormalization
326and gradual underflow, this constant equals `cl-least-positive-float'.
327Call `cl-float-limits' to set this.") 325Call `cl-float-limits' to set this.")
328 326
329(defconst cl-least-negative-normalized-float nil 327(defconst cl-least-negative-normalized-float nil
@@ -334,12 +332,12 @@ Call `cl-float-limits' to set this.")
334(defconst cl-float-epsilon nil 332(defconst cl-float-epsilon nil
335 "The smallest positive float that adds to 1.0 to give a distinct value. 333 "The smallest positive float that adds to 1.0 to give a distinct value.
336Adding a number less than this to 1.0 returns 1.0 due to roundoff. 334Adding a number less than this to 1.0 returns 1.0 due to roundoff.
337For IEEE machines, epsilon is about 2.22e-16. 335For Emacs, this equals 2.220446049250313e-16.
338Call `cl-float-limits' to set this.") 336Call `cl-float-limits' to set this.")
339 337
340(defconst cl-float-negative-epsilon nil 338(defconst cl-float-negative-epsilon nil
341 "The smallest positive float that subtracts from 1.0 to give a distinct value. 339 "The smallest positive float that subtracts from 1.0 to give a distinct value.
342For IEEE machines, it is about 1.11e-16. 340For Emacs, this equals 1.1102230246251565e-16.
343Call `cl-float-limits' to set this.") 341Call `cl-float-limits' to set this.")
344 342
345 343