Debian Codegraph @

docsrc/xlisp/xlisp-doc/examples/common-lisp/ceiling.htm

raw
1 <html><head>
2
3 <title>cl:ceiling</title>
4
5 <style type="text/css">
6 .example {
7 color: #000000;
8 background-color: #F5F5F5;
9 padding: 8px;
10 border: #808080;
11 border-style: solid;
12 border-width: 1px;
13 width:auto;
14 }
15 .button {
16 color: #000000;
17 background-color: #F5F5F5;
18 padding-top: 1px;
19 padding-bottom: 1px;
20 padding-left: 4px;
21 padding-right: 8px;
22 border: #808080;
23 border-style: solid;
24 border-width: 1px;
25 white-space: pre;
26 }
27 .box {
28 color: #000000;
29 padding-top: 4px;
30 padding-bottom: 4px;
31 padding-left: 16px;
32 padding-right: 16px;
33 border: #808080;
34 border-style: solid;
35 border-width: 1px;
36 }
37 </style>
38
39 </head>
40
41 <body>
42
43 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
44 <a href="../../manual/contents.htm">Contents</a> |
45 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
46 <a href="../examples.htm">Examples</a> |
47 <a href="../../reference/reference-index.htm">Reference</a>
48
49 <hr>
50
51 <h1>cl:ceiling</h1>
52
53 <hr>
54
55 <p>The <nobr>cl:<b>ceiling</b></nobr> function
56 <a href="../../reference/truncate.htm">truncate</a>s an integer or
57 <nobr>floating-point</nobr> number toward positive infinity:</p>
58
59 <p><div class="box">
60
61 <dl>
62 <dt>(cl:<b>ceiling</b> <i>number </i> [<i>divisor</i>])</dt>
63 <dd><i>number</i> - an integer or <nobr>floating-point</nobr> number<br>
64 <i>divisor</i> - an integer or <nobr>floating-point</nobr> number, except zero<br>
65 <table cellpadding="0" cellspacing="0"><tbody>
66 <tr>
67 <td valign="top"><nobr>returns</nobr></td>
68 <td valign="top"><nobr>&nbsp;-&nbsp;</nobr></td>
69 <td width="100%">the result of truncating the result of <i>number</i> divided by <i>divisor</i></td>
70 </tr>
71 <tr>
72 <td></td>
73 <td valign="top"><nobr>&nbsp;-&nbsp;</nobr></td>
74 <td width="100%">the remainder of the truncate operation</td>
75 </tr>
76 </tbody></table></dd>
77 </dl>
78
79 </div></p>
80
81 <pre class="example">
82 (defun <font color="#0000CC">cl:ceiling</font> (number &amp;optional (divisor
83 (if (integerp number) 1 1.0)
84 divisor-p))
85 (let ((quotient
86 (cond ((and (not divisor-p) (integerp number)) number)
87 ((= number divisor) 1)
88 (t (let ((i-quotient (/ (truncate number) (truncate divisor)))
89 (f-quotient (/ (float number) divisor)))
90 (if (or (= i-quotient f-quotient) <font color="#008844">; integer result</font>
91 (not (plusp f-quotient)))
92 (truncate f-quotient)
93 (1+ (truncate f-quotient))))))))
94 (setq <font color="#AA5500">*rslt*</font> (list quotient (- number (* quotient divisor)))
95 <font color="#AA5500">cl:*multiple-values*</font> t)
96 quotient))
97 </pre>
98
99 <p>The <nobr>cl:<b>ceiling</b></nobr> function computes a quotient that has
100 been truncated toward positive infinity. <nobr>That is</nobr>, the quotient
101 represents the smallest mathematical integer that is not smaller than the
102 mathematical result.</p>
103
104 <p>The quotient is directly returned by the function, while a list:</p>
105
106 <pre class="example">
107 (quotient remainder)
108 </pre>
109
110 <p>is stored in the Nyquist/XLISP
111 <a href="../../reference/global-rslt.htm">*rslt*</a> variable and the
112 <a href="global-multiple-values.htm">cl:*multiple-values*</a> is set to
113 <a href="../../reference/t.htm">&nbsp;T&nbsp;</a> to signal that
114 <a href="multiple-values.htm">Multiple Values</a> are returned.</p>
115
116 <nobr>See
117 <a href="rounding-and-truncation.htm">Rounding and Truncation</a></nobr>
118 for more details.</p>
119
120 <p>Examples:</p>
121
122 <pre class="example">
123 (cl:ceiling 3.5) =&gt; 4 <font color="#008844">; *rslt* =&gt; ( 4 -0.5)</font>
124 (cl:ceiling -3.5) =&gt; -3 <font color="#008844">; *rslt* =&gt; (-3 -0.5)</font>
125 </pre>
126
127 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
128
129 <hr>
130
131 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
132 <a href="../../manual/contents.htm">Contents</a> |
133 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
134 <a href="../examples.htm">Examples</a> |
135 <a href="../../reference/reference-index.htm">Reference</a>
136
137 </body></html>