summaryrefslogtreecommitdiff
path: root/docsrc/xlisp/xlisp-doc/examples/common-lisp/truncate.htm
diff options
context:
space:
mode:
Diffstat (limited to 'docsrc/xlisp/xlisp-doc/examples/common-lisp/truncate.htm')
-rw-r--r--docsrc/xlisp/xlisp-doc/examples/common-lisp/truncate.htm135
1 files changed, 135 insertions, 0 deletions
diff --git a/docsrc/xlisp/xlisp-doc/examples/common-lisp/truncate.htm b/docsrc/xlisp/xlisp-doc/examples/common-lisp/truncate.htm
new file mode 100644
index 0000000..6032dd3
--- /dev/null
+++ b/docsrc/xlisp/xlisp-doc/examples/common-lisp/truncate.htm
@@ -0,0 +1,135 @@
+<html><head>
+
+<title>cl:truncate</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:truncate</h1>
+
+<hr>
+
+<p>The <nobr>cl:<b>truncate</b></nobr> function
+<a href="../../reference/truncate.htm">truncate</a>s an integer or
+<nobr>floating-point</nobr> number toward zero:</p>
+
+<p><div class="box">
+
+<dl>
+<dt>(cl:<b>truncate</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:truncate</font> (number &amp;optional (divisor (if (integerp number) 1 1.0)))
+ (let ((quotient (truncate (/ (float number) divisor))))
+ (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>truncate</b></nobr> function computes a quotient that has
+been truncated towards zero. <nobr>That is</nobr>, the quotient represents
+the mathematical integer of the same sign as the mathematical quotient, and
+that has the greatest integral magnitude not greater than that of 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:truncate 3.5) =&gt; 0 <font color="#008844">; *rslt* =&gt; ( 3 0.5)</font>
+(cl:truncate -3.5) =&gt; -3 <font color="#008844">; *rslt* =&gt; (-3 -0.5)</font>
+</pre>
+
+<p>Force an integer division:</p>
+
+<pre class="example">
+(cl:truncate 3.1 2.6) =&gt; 1 <font color="#008844">; *rslt* =&gt; (1 0.5)</font>
+(/ 3 2) =&gt; 1
+</pre>
+
+<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>