File: floor.htm

package info (click to toggle)
nyquist 3.05-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 31,172 kB
  • ctags: 22,924
  • sloc: ansic: 149,216; sh: 21,301; lisp: 17,746; cpp: 12,778; java: 8,006; makefile: 4,574; python: 39
file content (150 lines) | stat: -rw-r--r-- 4,862 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html><head>

<title>cl:floor</title>

<style type="text/css">
.example {
  color: #000000;
  background-color: #F5F5F5;
  padding: 8px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
  width:auto;
}
.button {
  color: #000000;
  background-color: #F5F5F5;
  padding-top: 1px;
  padding-bottom: 1px;
  padding-left: 4px;
  padding-right: 8px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
  white-space: pre;
}
.box {
  color: #000000;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 16px;
  padding-right: 16px;
  border: #808080;
  border-style: solid;
  border-width: 1px;
}
</style>

</head>

<body>

<a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../../manual/contents.htm">Contents</a> |
<a href="../../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples.htm">Examples</a> |
<a href="../../reference/reference-index.htm">Reference</a>

<hr>

<h1>cl:floor</h1>

<hr>

<p>The <nobr>cl:<b>floor</b></nobr> function
<a href="../../reference/truncate.htm">truncate</a>s an integer or
<nobr>floating-point</nobr> number toward negative infinity:</p>

<p><div class="box">

<dl>
<dt>(cl:<b>floor</b> <i>number </i> [<i>divisor</i>])</dt>
<dd><i>number</i> - an integer or <nobr>floating-point</nobr> number<br>
<i>divisor</i> - an integer or <nobr>floating-point</nobr> number, except zero<br>
<table cellpadding="0" cellspacing="0"><tbody>
<tr>
  <td valign="top"><nobr>returns</nobr></td>
  <td valign="top"><nobr>&nbsp;-&nbsp;</nobr></td>
  <td width="100%">the result of truncating the result of <i>number</i> divided by <i>divisor</i></td>
</tr>
<tr>
  <td></td>
  <td valign="top"><nobr>&nbsp;-&nbsp;</nobr></td>
  <td width="100%">the remainder of the truncate operation</td>
</tr>
</tbody></table></dd>
</dl>

</div></p>

<pre class="example">
(defun <font color="#0000CC">cl:floor</font> (number &amp;optional (divisor
                                  (if (integerp number) 1 1.0)
                                  divisor-p))
  (let ((quotient
          (cond ((and (not divisor-p) (integerp number)) number)
                ((= number divisor) 1)
                (t (let ((i-quotient (/ (truncate number) (truncate divisor)))
                         (f-quotient (/ (float number) divisor)))
                     (if (or (= i-quotient f-quotient)  <font color="#008844">; integer result</font>
                             (not (minusp f-quotient)))
                          (truncate f-quotient)
                          (1- (truncate f-quotient))))))))
    (setq <font color="#AA5500">*rslt*</font> (list quotient (- number (* quotient divisor)))
          <font color="#AA5500">cl:*multiple-values*</font> t)
    quotient))
</pre>

<p>The <nobr>cl:<b>floor</b></nobr> function computes a quotient that has
been truncated toward negative infinity. <nobr>That is</nobr>, the quotient
represents the largest mathematical integer that is not larger than the
mathematical quotient.</p>

<p>The quotient is directly returned by the function, while a list:</p>

<pre class="example">
(quotient remainder)
</pre>

<p>is stored in the Nyquist/XLISP
<a href="../../reference/global-rslt.htm">*rslt*</a> variable and the
<a href="global-multiple-values.htm">cl:*multiple-values*</a> is set to
<a href="../../reference/t.htm">&nbsp;T&nbsp;</a> to signal that
<a href="multiple-values.htm">Multiple Values</a> are returned.</p> 

<nobr>See
<a href="rounding-and-truncation.htm">Rounding and Truncation</a></nobr>
for more details.</p>

<p>Examples:</p>

<pre class="example">
(cl:floor  3.5)  =&gt;  3  <font color="#008844">; *rslt* =&gt; ( 3 0.5)</font>
(cl:floor -3.5)  =&gt; -4  <font color="#008844">; *rslt* =&gt; (-4 0.5)</font>
</pre>

<p>See also:</p>

<ul>
<li><nobr><a href="../../reference/rem.htm">rem</a> - remainder of an integer division</nobr></li>
<li><nobr><a href="../../reference/round.htm">round</a> - round arbitrary numbers to integers</nobr></li>
<li><nobr><a href="../../reference/truncate.htm">truncate</a> - truncate arbitrary numbers toward zero</nobr></li>
<li><nobr><a href="mod.htm">cl:mod</a></nobr></li>
<li><nobr><a href="rem.htm">cl:rem</a></nobr></li>
<li><nobr><a href="round.htm">cl:round</a></nobr></li>
<li><nobr><a href="truncate.htm">cl:truncate</a></nobr></li>
<li><nobr><a href="ceiling.htm">cl:ceiling</a></nobr></li>
</ul>

<p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>

<hr>

<a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
<a href="../../manual/contents.htm">Contents</a> |
<a href="../../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples.htm">Examples</a> |
<a href="../../reference/reference-index.htm">Reference</a>

</body></html>