changeset 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 4d3fd773cd30
children 0f05936702f1
files lispref/numbers.texi
diffstat 1 files changed, 50 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lispref/numbers.texi	Sun Aug 12 21:15:14 2001 +0000
+++ b/lispref/numbers.texi	Sun Aug 12 21:16:24 2001 +0000
@@ -360,21 +360,56 @@
 @defun truncate number
 This returns @var{number}, converted to an integer by rounding towards
 zero.
+
+@example
+(truncate 1.2)
+     @result{} 1
+(truncate 1.7)
+     @result{} 1
+(truncate -1.2)
+     @result{} -1
+(truncate -1.7)
+     @result{} -1
+@end example
 @end defun
 
 @defun floor number &optional divisor
 This returns @var{number}, converted to an integer by rounding downward
 (towards negative infinity).
 
-If @var{divisor} is specified, @var{number} is divided by @var{divisor}
-before the floor is taken; this uses the kind of division operation that
-corresponds to @code{mod}, rounding downward.  An @code{arith-error}
-results if @var{divisor} is 0.
+If @var{divisor} is specified, @code{floor} divides @var{number} by
+@var{divisor} and then converts to an integer; this uses the kind of
+division operation that corresponds to @code{mod}, rounding downward.
+An @code{arith-error} results if @var{divisor} is 0.
+
+@example
+(floor 1.2)
+     @result{} 1
+(floor 1.7)
+     @result{} 1
+(floor -1.2)
+     @result{} -2
+(floor -1.7)
+     @result{} -2
+(floor 5.99 3)
+     @result{} 1
+@end example
 @end defun
 
 @defun ceiling number
 This returns @var{number}, converted to an integer by rounding upward
 (towards positive infinity).
+
+@example
+(ceiling 1.2)
+     @result{} 2
+(ceiling 1.7)
+     @result{} 2
+(ceiling -1.2)
+     @result{} -1
+(ceiling -1.7)
+     @result{} -1
+@end example
 @end defun
 
 @defun round number
@@ -382,6 +417,17 @@
 nearest integer.  Rounding a value equidistant between two integers
 may choose the integer closer to zero, or it may prefer an even integer,
 depending on your machine.
+
+@example
+(round 1.2)
+     @result{} 1
+(round 1.7)
+     @result{} 2
+(round -1.2)
+     @result{} -1
+(round -1.7)
+     @result{} -2
+@end example
 @end defun
 
 @node Arithmetic Operations