Mercurial > emacs
comparison lispref/numbers.texi @ 38787:4d77816c7cad
Add examples for floor, ceiling, truncate, round.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 12 Aug 2001 21:16:24 +0000 |
parents | 89afca54a135 |
children | 634358ff84a4 |
comparison
equal
deleted
inserted
replaced
38786:4d3fd773cd30 | 38787:4d77816c7cad |
---|---|
358 also, and return such arguments unchanged. | 358 also, and return such arguments unchanged. |
359 | 359 |
360 @defun truncate number | 360 @defun truncate number |
361 This returns @var{number}, converted to an integer by rounding towards | 361 This returns @var{number}, converted to an integer by rounding towards |
362 zero. | 362 zero. |
363 | |
364 @example | |
365 (truncate 1.2) | |
366 @result{} 1 | |
367 (truncate 1.7) | |
368 @result{} 1 | |
369 (truncate -1.2) | |
370 @result{} -1 | |
371 (truncate -1.7) | |
372 @result{} -1 | |
373 @end example | |
363 @end defun | 374 @end defun |
364 | 375 |
365 @defun floor number &optional divisor | 376 @defun floor number &optional divisor |
366 This returns @var{number}, converted to an integer by rounding downward | 377 This returns @var{number}, converted to an integer by rounding downward |
367 (towards negative infinity). | 378 (towards negative infinity). |
368 | 379 |
369 If @var{divisor} is specified, @var{number} is divided by @var{divisor} | 380 If @var{divisor} is specified, @code{floor} divides @var{number} by |
370 before the floor is taken; this uses the kind of division operation that | 381 @var{divisor} and then converts to an integer; this uses the kind of |
371 corresponds to @code{mod}, rounding downward. An @code{arith-error} | 382 division operation that corresponds to @code{mod}, rounding downward. |
372 results if @var{divisor} is 0. | 383 An @code{arith-error} results if @var{divisor} is 0. |
384 | |
385 @example | |
386 (floor 1.2) | |
387 @result{} 1 | |
388 (floor 1.7) | |
389 @result{} 1 | |
390 (floor -1.2) | |
391 @result{} -2 | |
392 (floor -1.7) | |
393 @result{} -2 | |
394 (floor 5.99 3) | |
395 @result{} 1 | |
396 @end example | |
373 @end defun | 397 @end defun |
374 | 398 |
375 @defun ceiling number | 399 @defun ceiling number |
376 This returns @var{number}, converted to an integer by rounding upward | 400 This returns @var{number}, converted to an integer by rounding upward |
377 (towards positive infinity). | 401 (towards positive infinity). |
402 | |
403 @example | |
404 (ceiling 1.2) | |
405 @result{} 2 | |
406 (ceiling 1.7) | |
407 @result{} 2 | |
408 (ceiling -1.2) | |
409 @result{} -1 | |
410 (ceiling -1.7) | |
411 @result{} -1 | |
412 @end example | |
378 @end defun | 413 @end defun |
379 | 414 |
380 @defun round number | 415 @defun round number |
381 This returns @var{number}, converted to an integer by rounding towards the | 416 This returns @var{number}, converted to an integer by rounding towards the |
382 nearest integer. Rounding a value equidistant between two integers | 417 nearest integer. Rounding a value equidistant between two integers |
383 may choose the integer closer to zero, or it may prefer an even integer, | 418 may choose the integer closer to zero, or it may prefer an even integer, |
384 depending on your machine. | 419 depending on your machine. |
420 | |
421 @example | |
422 (round 1.2) | |
423 @result{} 1 | |
424 (round 1.7) | |
425 @result{} 2 | |
426 (round -1.2) | |
427 @result{} -1 | |
428 (round -1.7) | |
429 @result{} -2 | |
430 @end example | |
385 @end defun | 431 @end defun |
386 | 432 |
387 @node Arithmetic Operations | 433 @node Arithmetic Operations |
388 @section Arithmetic Operations | 434 @section Arithmetic Operations |
389 | 435 |