Mercurial > emacs
comparison lispref/numbers.texi @ 21007:66d807bdc5b4
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 28 Feb 1998 01:53:53 +0000 |
parents | 981e116b4ac6 |
children | 90da2489c498 |
comparison
equal
deleted
inserted
replaced
21006:00022857f529 | 21007:66d807bdc5b4 |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | 2 @c This is part of the GNU Emacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. |
4 @c See the file elisp.texi for copying conditions. | 4 @c See the file elisp.texi for copying conditions. |
5 @setfilename ../info/numbers | 5 @setfilename ../info/numbers |
6 @node Numbers, Strings and Characters, Lisp Data Types, Top | 6 @node Numbers, Strings and Characters, Lisp Data Types, Top |
7 @chapter Numbers | 7 @chapter Numbers |
8 @cindex integers | 8 @cindex integers |
14 numbers are numbers with fractional parts, such as @minus{}4.5, 0.0, or | 14 numbers are numbers with fractional parts, such as @minus{}4.5, 0.0, or |
15 2.71828. They can also be expressed in exponential notation: | 15 2.71828. They can also be expressed in exponential notation: |
16 1.5e2 equals 150; in this example, @samp{e2} stands for ten to the | 16 1.5e2 equals 150; in this example, @samp{e2} stands for ten to the |
17 second power, and is multiplied by 1.5. Floating point values are not | 17 second power, and is multiplied by 1.5. Floating point values are not |
18 exact; they have a fixed, limited amount of precision. | 18 exact; they have a fixed, limited amount of precision. |
19 | |
20 Support for floating point numbers is a new feature in Emacs 19, and it | |
21 is controlled by a separate compilation option, so you may encounter a site | |
22 where Emacs does not support them. | |
23 | 19 |
24 @menu | 20 @menu |
25 * Integer Basics:: Representation and range of integers. | 21 * Integer Basics:: Representation and range of integers. |
26 * Float Basics:: Representation and range of floating point. | 22 * Float Basics:: Representation and range of floating point. |
27 * Predicates on Numbers:: Testing for numbers. | 23 * Predicates on Numbers:: Testing for numbers. |
118 (+ 1 134217727) | 114 (+ 1 134217727) |
119 @result{} -134217728 | 115 @result{} -134217728 |
120 @result{} 1000 0000 0000 0000 0000 0000 0000 | 116 @result{} 1000 0000 0000 0000 0000 0000 0000 |
121 @end example | 117 @end example |
122 | 118 |
123 Many of the following functions accept markers for arguments as well | 119 Many of the functions described in this chapter accept markers for |
124 as integers. (@xref{Markers}.) More precisely, the actual arguments to | 120 arguments in place of numbers. (@xref{Markers}.) Since the actual |
125 such functions may be either integers or markers, which is why we often | 121 arguments to such functions may be either numbers or markers, we often |
126 give these arguments the name @var{int-or-marker}. When the argument | 122 give these arguments the name @var{number-or-marker}. When the argument |
127 value is a marker, its position value is used and its buffer is ignored. | 123 value is a marker, its position value is used and its buffer is ignored. |
128 | |
129 @ignore | |
130 In version 19, except where @emph{integer} is specified as an | |
131 argument, all of the functions for markers and integers also work for | |
132 floating point numbers. | |
133 @end ignore | |
134 | 124 |
135 @node Float Basics | 125 @node Float Basics |
136 @section Floating Point Basics | 126 @section Floating Point Basics |
137 | 127 |
138 @cindex @code{LISP_FLOAT_TYPE} configuration macro | 128 Floating point numbers are useful for representing numbers that are |
139 Emacs version 19 supports floating point numbers, if compiled with the | 129 not integral. The precise range of floating point numbers is |
140 macro @code{LISP_FLOAT_TYPE} defined. The precise range of floating | 130 machine-specific; it is the same as the range of the C data type |
141 point numbers is machine-specific; it is the same as the range of the C | 131 @code{double} on the machine you are using. |
142 data type @code{double} on the machine in question. | 132 |
143 | 133 The read-syntax for floating point numbers requires either a decimal |
144 The printed representation for floating point numbers requires either | 134 point (with at least one digit following), an exponent, or both. For |
145 a decimal point (with at least one digit following), an exponent, or | 135 example, @samp{1500.0}, @samp{15e2}, @samp{15.0e2}, @samp{1.5e3}, and |
146 both. For example, @samp{1500.0}, @samp{15e2}, @samp{15.0e2}, | 136 @samp{.15e4} are five ways of writing a floating point number whose |
147 @samp{1.5e3}, and @samp{.15e4} are five ways of writing a floating point | 137 value is 1500. They are all equivalent. You can also use a minus sign |
148 number whose value is 1500. They are all equivalent. You can also use | 138 to write negative floating point numbers, as in @samp{-1.0}. |
149 a minus sign to write negative floating point numbers, as in | |
150 @samp{-1.0}. | |
151 | 139 |
152 @cindex IEEE floating point | 140 @cindex IEEE floating point |
153 @cindex positive infinity | 141 @cindex positive infinity |
154 @cindex negative infinity | 142 @cindex negative infinity |
155 @cindex infinity | 143 @cindex infinity |
160 ``not-a-number''; numerical functions return such values in cases where | 148 ``not-a-number''; numerical functions return such values in cases where |
161 there is no correct answer. For example, @code{(sqrt -1.0)} returns a | 149 there is no correct answer. For example, @code{(sqrt -1.0)} returns a |
162 NaN. For practical purposes, there's no significant difference between | 150 NaN. For practical purposes, there's no significant difference between |
163 different NaN values in Emacs Lisp, and there's no rule for precisely | 151 different NaN values in Emacs Lisp, and there's no rule for precisely |
164 which NaN value should be used in a particular case, so this manual | 152 which NaN value should be used in a particular case, so this manual |
165 doesn't try to distinguish them. Emacs Lisp has no read syntax for NaNs | 153 doesn't try to distinguish them. Here are the read syntaxes for |
166 or infinities; perhaps we should create a syntax in the future. | 154 these numbers: |
155 | |
156 @table @asis | |
157 @item positive infinity | |
158 @samp{1.0e+INF} | |
159 @item negative infinity | |
160 @samp{-1.0e+INF} | |
161 @item Not-a-number | |
162 @samp{0.0e+NaN}. | |
163 @end table | |
167 | 164 |
168 You can use @code{logb} to extract the binary exponent of a floating | 165 You can use @code{logb} to extract the binary exponent of a floating |
169 point number (or estimate the logarithm of an integer): | 166 point number (or estimate the logarithm of an integer): |
170 | 167 |
171 @defun logb number | 168 @defun logb number |
172 This function returns the binary exponent of @var{number}. More | 169 This function returns the binary exponent of @var{number}. More |
173 precisely, the value is the logarithm of @var{number} base 2, rounded | 170 precisely, the value is the logarithm of @var{number} base 2, rounded |
174 down to an integer. | 171 down to an integer. |
172 | |
173 @example | |
174 (logb 10) | |
175 @result{} 3 | |
176 (logb 10.0e20) | |
177 @result{} 69 | |
178 @end example | |
175 @end defun | 179 @end defun |
176 | 180 |
177 @node Predicates on Numbers | 181 @node Predicates on Numbers |
178 @section Type Predicates for Numbers | 182 @section Type Predicates for Numbers |
179 | 183 |
230 compare them, then you test whether two values are the same | 234 compare them, then you test whether two values are the same |
231 @emph{object}. By contrast, @code{=} compares only the numeric values | 235 @emph{object}. By contrast, @code{=} compares only the numeric values |
232 of the objects. | 236 of the objects. |
233 | 237 |
234 At present, each integer value has a unique Lisp object in Emacs Lisp. | 238 At present, each integer value has a unique Lisp object in Emacs Lisp. |
235 Therefore, @code{eq} is equivalent @code{=} where integers are | 239 Therefore, @code{eq} is equivalent to @code{=} where integers are |
236 concerned. It is sometimes convenient to use @code{eq} for comparing an | 240 concerned. It is sometimes convenient to use @code{eq} for comparing an |
237 unknown value with an integer, because @code{eq} does not report an | 241 unknown value with an integer, because @code{eq} does not report an |
238 error if the unknown value is not a number---it accepts arguments of any | 242 error if the unknown value is not a number---it accepts arguments of any |
239 type. By contrast, @code{=} signals an error if the arguments are not | 243 type. By contrast, @code{=} signals an error if the arguments are not |
240 numbers or markers. However, it is a good idea to use @code{=} if you | 244 numbers or markers. However, it is a good idea to use @code{=} if you |
426 (+ 1 2 3 4) | 430 (+ 1 2 3 4) |
427 @result{} 10 | 431 @result{} 10 |
428 @end example | 432 @end example |
429 @end defun | 433 @end defun |
430 | 434 |
431 @defun - &optional number-or-marker &rest other-numbers-or-markers | 435 @defun - &optional number-or-marker &rest more-numbers-or-markers |
432 The @code{-} function serves two purposes: negation and subtraction. | 436 The @code{-} function serves two purposes: negation and subtraction. |
433 When @code{-} has a single argument, the value is the negative of the | 437 When @code{-} has a single argument, the value is the negative of the |
434 argument. When there are multiple arguments, @code{-} subtracts each of | 438 argument. When there are multiple arguments, @code{-} subtracts each of |
435 the @var{other-numbers-or-markers} from @var{number-or-marker}, | 439 the @var{more-numbers-or-markers} from @var{number-or-marker}, |
436 cumulatively. If there are no arguments, the result is 0. | 440 cumulatively. If there are no arguments, the result is 0. |
437 | 441 |
438 @example | 442 @example |
439 (- 10 1 2 3 4) | 443 (- 10 1 2 3 4) |
440 @result{} 0 | 444 @result{} 0 |