diff options
| author | Paul Eggert | 2019-11-10 15:01:06 -0800 |
|---|---|---|
| committer | Paul Eggert | 2019-11-10 15:04:20 -0800 |
| commit | b6942c0c37a504e00c717c8c74bfa9dcd208c931 (patch) | |
| tree | 40565eb305e75021b6d96e90fd678c87a9de10be /doc/misc | |
| parent | 6ad5eb97940b07bf8d28f8517608351b3af1221c (diff) | |
| download | emacs-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.
Diffstat (limited to 'doc/misc')
| -rw-r--r-- | doc/misc/cl.texi | 54 |
1 files changed, 24 insertions, 30 deletions
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 |
| 3114 | This function makes sure that the Common Lisp floating-point parameters | 3114 | This function makes sure that the Common Lisp floating-point parameters |
| 3115 | like @code{cl-most-positive-float} have been initialized. Until it is | 3115 | like @code{cl-most-positive-float} have been initialized. Until it is |
| 3116 | called, these parameters will be @code{nil}. | 3116 | called, these parameters have unspecified values. |
| 3117 | @c If this version of Emacs does not support floats, the parameters will | ||
| 3118 | @c remain @code{nil}. | ||
| 3119 | If the parameters have already been initialized, the function returns | 3117 | If the parameters have already been initialized, the function returns |
| 3120 | immediately. | 3118 | immediately. |
| 3121 | |||
| 3122 | The algorithm makes assumptions that will be valid for almost all | ||
| 3123 | machines, but will fail if the machine's arithmetic is extremely | ||
| 3124 | unusual, e.g., decimal. | ||
| 3125 | @end defun | 3119 | @end defun |
| 3126 | 3120 | ||
| 3127 | Since true Common Lisp supports up to four different kinds of floating-point | 3121 | Since true Common Lisp supports up to four different kinds of floating-point |
| 3128 | numbers, it has families of constants like | 3122 | numbers, 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 |
| 3131 | kind of floating-point number, so this package just uses single constants. | 3125 | one set of constants because Emacs has only one kind of |
| 3126 | floating-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 |
| 3134 | This constant equals the largest value a Lisp float can hold. | 3130 | This constant equals the largest finite value a Lisp float can hold. |
| 3135 | For those systems whose arithmetic supports infinities, this is | 3131 | For IEEE binary64 format, this equals @code{(- (expt 2 1024) (- 2 |
| 3136 | the largest @emph{finite} value. For IEEE machines, the value | 3132 | 971))}, which equals @code{1.7976931348623157e+308}. |
| 3137 | is 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 |
| 3141 | This constant equals the most negative value a Lisp float can hold. | 3136 | This 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)}.) | 3137 | For 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 |
| 3146 | This constant equals the smallest Lisp float value greater than zero. | 3141 | This constant equals the smallest positive Lisp float that is |
| 3147 | For IEEE machines, it is about @code{4.94e-324} if denormals are | 3142 | @dfn{normalized}, i.e., that has full precision. |
| 3148 | supported or @code{2.22e-308} if not. | 3143 | For IEEE binary64 format, this equals @code{(expt 2 -1022)}, |
| 3144 | which 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 |
| 3152 | This constant equals the smallest @emph{normalized} Lisp float greater | 3148 | This constant equals the smallest Lisp float value greater than zero. |
| 3153 | than zero, i.e., the smallest value for which IEEE denormalization | 3149 | For IEEE binary64 format, this equals @code{5e-324} (which equals |
| 3154 | will not result in a loss of precision. For IEEE machines, this | 3150 | @code{(expt 2 -1074)}) if subnormal numbers are supported, and |
| 3155 | value is about @code{2.22e-308}. For machines that do not support | 3151 | @code{cl-least-positive-normalized-float} otherwise. |
| 3156 | the concept of denormalization and gradual underflow, this constant | ||
| 3157 | will 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 |
| 3170 | This constant is the smallest positive Lisp float that can be added | 3164 | This constant is the smallest positive Lisp float that can be added |
| 3171 | to 1.0 to produce a distinct value. Adding a smaller number to 1.0 | 3165 | to 1.0 to produce a distinct value. Adding a smaller number to 1.0 |
| 3172 | will yield 1.0 again due to roundoff. For IEEE machines, epsilon | 3166 | will yield 1.0 again due to roundoff. For IEEE binary64 format, this |
| 3173 | is about @code{2.22e-16}. | 3167 | equals @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 |
| 3177 | This is the smallest positive value that can be subtracted from | 3171 | This is the smallest positive value that can be subtracted from |
| 3178 | 1.0 to produce a distinct value. For IEEE machines, it is about | 3172 | 1.0 to produce a distinct value. For IEEE binary64 format, this |
| 3179 | @code{1.11e-16}. | 3173 | equals @code{(expt 2 -53)}, which equals @code{1.1102230246251565e-16}. |
| 3180 | @end defvar | 3174 | @end defvar |
| 3181 | 3175 | ||
| 3182 | @node Sequences | 3176 | @node Sequences |