diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/numeric-conversions.html | |
new repository
Diffstat (limited to 'devdocs/elisp/numeric-conversions.html')
| -rw-r--r-- | devdocs/elisp/numeric-conversions.html | 58 |
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 &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 &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 &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 &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 © 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> |
