Debian Codegraph @

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

raw
1 <html><head>
2
3 <title>cl:mod</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:mod</h1>
52
53 <hr>
54
55 <p><div class="box">
56
57 <dl>
58 <dt>(cl:<b>mod</b> <i>number divisor</i>)</dt>
59 <dd><i>number</i> - an integer or floating-point number<br>
60 <i>divisor</i> - an integer or floating-point number<br>
61 returns - the remainder of a <a href="#cl-floor">cl:floor</a> operation</dd>
62 </dl>
63
64 </div></p>
65
66 <pre class="example">
67 (defun <font color="#0000CC">cl:mod</font> (number divisor)
68 (if (= (abs number) (abs divisor))
69 (if (and (integerp number) (integerp divisor)) 0 0.0)
70 (let* ((i-quotient (/ (truncate number) (truncate divisor)))
71 (f-quotient (/ (float number) divisor))
72 (quotient (if (or (= i-quotient f-quotient) <font color="#008844">; integer result</font>
73 (not (minusp f-quotient)))
74 (truncate f-quotient)
75 (1- (truncate f-quotient)))))
76 (- number (* quotient divisor)))))
77 </pre>
78
79 <p>The <nobr>cl:<b>mod</b></nobr> function performs the
80 <a href="floor.htm">cl:floor</a> operation on its arguments and returns the
81 remainder of the <a href="floor.htm">cl:floor</a> operation. <nobr>The
82 result</nobr> is either zero or an integer or <nobr>floating-point</nobr>
83 number with the same sign as the 'divisor' argument. <nobr>If both</nobr>
84 arguments are integer numbers, the <nobr>cl:<b>mod</b></nobr> function is
85 equal to the mathematical modulus function.</p>
86
87 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
88
89 <hr>
90
91 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
92 <a href="../../manual/contents.htm">Contents</a> |
93 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
94 <a href="../examples.htm">Examples</a> |
95 <a href="../../reference/reference-index.htm">Reference</a>
96
97 </body></html>