summaryrefslogtreecommitdiff
path: root/devdocs/elisp/numeric-conversions.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/numeric-conversions.html')
-rw-r--r--devdocs/elisp/numeric-conversions.html58
1 files changed, 58 insertions, 0 deletions
diff --git a/devdocs/elisp/numeric-conversions.html b/devdocs/elisp/numeric-conversions.html
new file mode 100644
index 00000000..4680b19d
--- /dev/null
+++ b/devdocs/elisp/numeric-conversions.html
@@ -0,0 +1,58 @@
+ <h3 class="section">Numeric Conversions</h3> <p>To convert an integer to floating point, use the function <code>float</code>. </p> <dl> <dt id="float">Function: <strong>float</strong> <em>number</em>
+</dt> <dd><p>This returns <var>number</var> converted to floating point. If <var>number</var> is already floating point, <code>float</code> returns it unchanged. </p></dd>
+</dl> <p>There are four functions to convert floating-point numbers to integers; they differ in how they round. All accept an argument <var>number</var> and an optional argument <var>divisor</var>. Both arguments may be integers or floating-point numbers. <var>divisor</var> may also be <code>nil</code>. If <var>divisor</var> is <code>nil</code> or omitted, these functions convert <var>number</var> to an integer, or return it unchanged if it already is an integer. If <var>divisor</var> is non-<code>nil</code>, they divide <var>number</var> by <var>divisor</var> and convert the result to an integer. If <var>divisor</var> is zero (whether integer or floating point), Emacs signals an <code>arith-error</code> error. </p> <dl> <dt id="truncate">Function: <strong>truncate</strong> <em>number &amp;optional divisor</em>
+</dt> <dd>
+<p>This returns <var>number</var>, converted to an integer by rounding towards zero. </p> <div class="example"> <pre class="example">(truncate 1.2)
+ ⇒ 1
+(truncate 1.7)
+ ⇒ 1
+(truncate -1.2)
+ ⇒ -1
+(truncate -1.7)
+ ⇒ -1
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="floor">Function: <strong>floor</strong> <em>number &amp;optional divisor</em>
+</dt> <dd>
+<p>This returns <var>number</var>, converted to an integer by rounding downward (towards negative infinity). </p> <p>If <var>divisor</var> is specified, this uses the kind of division operation that corresponds to <code>mod</code>, rounding downward. </p> <div class="example"> <pre class="example">(floor 1.2)
+ ⇒ 1
+(floor 1.7)
+ ⇒ 1
+(floor -1.2)
+ ⇒ -2
+(floor -1.7)
+ ⇒ -2
+(floor 5.99 3)
+ ⇒ 1
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="ceiling">Function: <strong>ceiling</strong> <em>number &amp;optional divisor</em>
+</dt> <dd>
+<p>This returns <var>number</var>, converted to an integer by rounding upward (towards positive infinity). </p> <div class="example"> <pre class="example">(ceiling 1.2)
+ ⇒ 2
+(ceiling 1.7)
+ ⇒ 2
+(ceiling -1.2)
+ ⇒ -1
+(ceiling -1.7)
+ ⇒ -1
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="round">Function: <strong>round</strong> <em>number &amp;optional divisor</em>
+</dt> <dd>
+<p>This returns <var>number</var>, converted to an integer by rounding towards the nearest integer. Rounding a value equidistant between two integers returns the even integer. </p> <div class="example"> <pre class="example">(round 1.2)
+ ⇒ 1
+(round 1.7)
+ ⇒ 2
+(round -1.2)
+ ⇒ -1
+(round -1.7)
+ ⇒ -2
+</pre>
+</div> </dd>
+</dl><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
+ <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Numeric-Conversions.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Numeric-Conversions.html</a>
+ </p>
+</div>