aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2001-08-12 21:16:24 +0000
committerRichard M. Stallman2001-08-12 21:16:24 +0000
commitb7a2fc9b5bcaf4d52a8ee7f9f657796430faec6e (patch)
tree3757a548161a61c41e212168f6c31aed28e5cacc
parenta9749dabdf94b72b99a3adf3f1bbe88c12fffc31 (diff)
downloademacs-b7a2fc9b5bcaf4d52a8ee7f9f657796430faec6e.tar.gz
emacs-b7a2fc9b5bcaf4d52a8ee7f9f657796430faec6e.zip
Add examples for floor, ceiling, truncate, round.
-rw-r--r--lispref/numbers.texi54
1 files changed, 50 insertions, 4 deletions
diff --git a/lispref/numbers.texi b/lispref/numbers.texi
index eaa2250a3fd..b9ab94cfc81 100644
--- a/lispref/numbers.texi
+++ b/lispref/numbers.texi
@@ -360,21 +360,56 @@ also, and return such arguments unchanged.
360@defun truncate number 360@defun truncate number
361This returns @var{number}, converted to an integer by rounding towards 361This returns @var{number}, converted to an integer by rounding towards
362zero. 362zero.
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
366This returns @var{number}, converted to an integer by rounding downward 377This returns @var{number}, converted to an integer by rounding downward
367(towards negative infinity). 378(towards negative infinity).
368 379
369If @var{divisor} is specified, @var{number} is divided by @var{divisor} 380If @var{divisor} is specified, @code{floor} divides @var{number} by
370before 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
371corresponds to @code{mod}, rounding downward. An @code{arith-error} 382division operation that corresponds to @code{mod}, rounding downward.
372results if @var{divisor} is 0. 383An @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
376This returns @var{number}, converted to an integer by rounding upward 400This 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
@@ -382,6 +417,17 @@ This returns @var{number}, converted to an integer by rounding towards the
382nearest integer. Rounding a value equidistant between two integers 417nearest integer. Rounding a value equidistant between two integers
383may choose the integer closer to zero, or it may prefer an even integer, 418may choose the integer closer to zero, or it may prefer an even integer,
384depending on your machine. 419depending 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