Mercurial > hg > xemacs-beta
comparison man/lispref/numbers.texi @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | 65c19d2020f7 |
children |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
238 exact, it is often a bad idea to check for equality of two floating | 238 exact, it is often a bad idea to check for equality of two floating |
239 point values. Usually it is better to test for approximate equality. | 239 point values. Usually it is better to test for approximate equality. |
240 Here's a function to do this: | 240 Here's a function to do this: |
241 | 241 |
242 @example | 242 @example |
243 (defvar fuzz-factor 1.0e-6) | 243 (defconst fuzz-factor 1.0e-6) |
244 (defun approx-equal (x y) | 244 (defun approx-equal (x y) |
245 (or (and (= x 0) (= y 0)) | 245 (or (and (= x 0) (= y 0)) |
246 (< (/ (abs (- x y)) | 246 (< (/ (abs (- x y)) |
247 (max (abs x) (abs y))) | 247 (max (abs x) (abs y))) |
248 fuzz-factor))) | 248 fuzz-factor))) |
255 distinct integer objects can have the same numeric value. XEmacs Lisp | 255 distinct integer objects can have the same numeric value. XEmacs Lisp |
256 can have just one integer object for any given value because it has a | 256 can have just one integer object for any given value because it has a |
257 limited range of integer values. | 257 limited range of integer values. |
258 @end quotation | 258 @end quotation |
259 | 259 |
260 @defun = number-or-marker1 number-or-marker2 | 260 In addition to numbers, all of the following functions also accept |
261 This function tests whether its arguments are numerically equal, and | 261 characters and markers as arguments, and treat them as their number |
262 returns @code{t} if so, @code{nil} otherwise. | 262 equivalents. |
263 @end defun | 263 |
264 | 264 @defun = number &rest more-numbers |
265 @defun /= number-or-marker1 number-or-marker2 | 265 This function returns @code{t} if all of its arguments are numerically |
266 This function tests whether its arguments are numerically not equal. It | 266 equal, @code{nil} otherwise. |
267 returns @code{t} if so, and @code{nil} otherwise. | 267 |
268 @end defun | 268 @example |
269 | 269 (= 5) |
270 @defun < number-or-marker1 number-or-marker2 | 270 @result{} t |
271 This function tests whether its first argument is strictly less than | 271 (= 5 6) |
272 its second argument. It returns @code{t} if so, @code{nil} otherwise. | 272 @result{} nil |
273 @end defun | 273 (= 5 5.0) |
274 | 274 @result{} t |
275 @defun <= number-or-marker1 number-or-marker2 | 275 (= 5 5 6) |
276 This function tests whether its first argument is less than or equal | 276 @result{} nil |
277 to its second argument. It returns @code{t} if so, @code{nil} | 277 @end example |
278 otherwise. | 278 @end defun |
279 @end defun | 279 |
280 | 280 @defun /= number &rest more-numbers |
281 @defun > number-or-marker1 number-or-marker2 | 281 This function returns @code{t} if no two arguments are numerically |
282 This function tests whether its first argument is strictly greater | 282 equal, @code{nil} otherwise. |
283 than its second argument. It returns @code{t} if so, @code{nil} | 283 |
284 otherwise. | 284 @example |
285 @end defun | 285 (/= 5 6) |
286 | 286 @result{} t |
287 @defun >= number-or-marker1 number-or-marker2 | 287 (/= 5 5 6) |
288 This function tests whether its first argument is greater than or | 288 @result{} nil |
289 equal to its second argument. It returns @code{t} if so, @code{nil} | 289 (/= 5 6 1) |
290 otherwise. | 290 @result{} t |
291 @end defun | 291 @end example |
292 | 292 @end defun |
293 @defun max number-or-marker &rest numbers-or-markers | 293 |
294 @defun < number &rest more-numbers | |
295 This function returns @code{t} if the sequence of its arguments is | |
296 monotonically increasing, @code{nil} otherwise. | |
297 | |
298 @example | |
299 (< 5 6) | |
300 @result{} t | |
301 (< 5 6 6) | |
302 @result{} nil | |
303 (< 5 6 7) | |
304 @result{} t | |
305 @end example | |
306 @end defun | |
307 | |
308 @defun <= number &rest more-numbers | |
309 This function returns @code{t} if the sequence of its arguments is | |
310 monotonically nondecreasing, @code{nil} otherwise. | |
311 | |
312 @example | |
313 (<= 5 6) | |
314 @result{} t | |
315 (<= 5 6 6) | |
316 @result{} t | |
317 (<= 5 6 5) | |
318 @result{} nil | |
319 @end example | |
320 @end defun | |
321 | |
322 @defun > number &rest more-numbers | |
323 This function returns @code{t} if the sequence of its arguments is | |
324 monotonically decreasing, @code{nil} otherwise. | |
325 @end defun | |
326 | |
327 @defun >= number &rest more-numbers | |
328 This function returns @code{t} if the sequence of its arguments is | |
329 monotonically nonincreasing, @code{nil} otherwise. | |
330 @end defun | |
331 | |
332 @defun max number &rest more-numbers | |
294 This function returns the largest of its arguments. | 333 This function returns the largest of its arguments. |
295 | 334 |
296 @example | 335 @example |
297 (max 20) | 336 (max 20) |
298 @result{} 20 | 337 @result{} 20 |
301 (max 1 3 2.5) | 340 (max 1 3 2.5) |
302 @result{} 3 | 341 @result{} 3 |
303 @end example | 342 @end example |
304 @end defun | 343 @end defun |
305 | 344 |
306 @defun min number-or-marker &rest numbers-or-markers | 345 @defun min number &rest more-numbers |
307 This function returns the smallest of its arguments. | 346 This function returns the smallest of its arguments. |
308 | 347 |
309 @example | 348 @example |
310 (min -4 1) | 349 (min -4 1) |
311 @result{} -4 | 350 @result{} -4 |