diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-16 17:02:57 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-16 17:02:57 -0400 |
| commit | 987e6890f78e54402b1355201d45e2fbce1fd992 (patch) | |
| tree | b3f4ffce7d5c96854c103d418e7c7e4d21b35081 /docs/spec/primitive.html | |
| parent | 66097b4135773acefcb19ab031212e532546d2f7 (diff) | |
Allow higher-precision implementations of √ and |
Diffstat (limited to 'docs/spec/primitive.html')
| -rw-r--r-- | docs/spec/primitive.html | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/docs/spec/primitive.html b/docs/spec/primitive.html index 05ed2dcc..728f473e 100644 --- a/docs/spec/primitive.html +++ b/docs/spec/primitive.html @@ -25,6 +25,7 @@ </ul> <p>In the first two cases, if the result would not be a valid Unicode code point, then an error results. The remaining cases of <code><span class='Function'>+</span></code> and <code><span class='Function'>-</span></code> (adding two characters; negating a character or subtracting it from a number) are not allowed.</p> <p>Additionally, the <strong>Floor</strong> function <code><span class='Function'>⌊</span></code> returns the largest integer smaller than or equal to the argument, or the argument itself if it is <code><span class='Number'>¯∞</span></code> or <code><span class='Number'>∞</span></code>. It's needed because the arithmetic operations give no fixed-time way to determine if a value is an integer. Floor gives an error if the argument is an atom other than a number.</p> +<p>The functions <strong>Modulus</strong> <code><span class='Function'>|</span></code>, and <strong>Square Root</strong> and <strong>Root</strong> <code><span class='Function'>√</span></code>, defined in reference.bqn may also be implemented as basic arithmetic rather than using the definitions in terms of the functions above, as this can allow for higher precision (it shouldn't affect other definitions, as these only use integer <code><span class='Function'>|</span></code>, which is exact). Any replacements should approximate the definition computed with infinite precision. This is particularly recommended for Modulus in a typical floating-point implementation, because the definition with <code><span class='Function'>÷</span></code> loses precision when <code><span class='Value'>𝕩</span></code> is much larger than <code><span class='Value'>𝕨</span></code> and is less useful for some numerical applications.</p> <h3 id="comparison"><a class="header" href="#comparison">Comparison</a></h3> <p>Two kinds of comparison are needed to define BQN's primitives: <em>equality</em> comparison and <em>ordered</em> comparison.</p> <p>Ordered comparison is simpler and is provided by the dyadic Less than or Equal to (<code><span class='Function'>≤</span></code>) function. This function gives an error if either argument is an operation, so it needs to be defined only for numbers and characters. For numbers it is defined by the number system, and for characters it returns <code><span class='Number'>1</span></code> if the left argument's code point is less than that of the right argument. Characters are considered greater than numbers, so that <code><span class='Value'>n</span><span class='Function'>≤</span><span class='Value'>c</span></code> is <code><span class='Number'>1</span></code> and <code><span class='Value'>c</span><span class='Function'>≤</span><span class='Value'>n</span></code> is <code><span class='Number'>0</span></code> if <code><span class='Value'>c</span></code> is a character and <code><span class='Value'>n</span></code> is a number.</p> @@ -100,13 +101,13 @@ <p>Arithmetic functions not already provided are defined in layer 1. These definitions, like the provided functions, apply to atoms only; they should be extended to arrays using the <code><span class='Modifier'>_perv</span></code> modifier from layer 2.</p> <ul> <li><strong>Sign</strong> (<code><span class='Function'>×</span></code>) </li> -<li><strong>Square Root</strong> and <strong>Root</strong> (<code><span class='Function'>√</span></code>) are defined in terms of Power. If a dedicated implementation is used for square roots, then Power should check for a right argument of <code><span class='Number'>0.5</span></code> and use this implementation in order to maintain consistency.</li> +<li><strong>Square Root</strong> and <strong>Root</strong> (<code><span class='Function'>√</span></code>) are defined in terms of Power, but a higher-precision native implementation is allowed.</li> <li><strong>Ceiling</strong> (<code><span class='Function'>⌈</span></code>) is like Floor, but rounds up instead of down.</li> <li><strong>Not</strong> (<code><span class='Function'>¬</span></code>) is a linear extension of logical negation, and <strong>Span</strong> (<code><span class='Function'>¬</span></code>) adds the left argument.</li> <li><strong>And</strong> (<code><span class='Function'>∧</span></code>) and <strong>Or</strong> (<code><span class='Function'>∨</span></code>) are bilinear extensions of the boolean functions.</li> <li><strong>Minimum</strong> (<code><span class='Function'>⌊</span></code>) and <strong>Maximum</strong> (<code><span class='Function'>⌈</span></code>) return the smaller or larger of the arguments, respectively. They are <em>not required</em> to be implemented for character arguments, and may give an error if either argument is a character.</li> <li><strong>Absolute Value</strong> (<code><span class='Function'>|</span></code>)</li> -<li><strong>Modulus</strong> (<code><span class='Function'>|</span></code>) is an extension of modular division to real numbers. As it uses floor instead of truncation, it's not the same as the <code><span class='Value'>%</span></code> operator from C or other languages when <code><span class='Value'>𝕨</span><span class='Function'><</span><span class='Number'>0</span></code>.</li> +<li><strong>Modulus</strong> (<code><span class='Function'>|</span></code>) is an extension of modular division to real numbers. As it uses floor instead of truncation, it's not the same as the <code><span class='Value'>%</span></code> operator from C or other languages when <code><span class='Value'>𝕨</span><span class='Function'><</span><span class='Number'>0</span></code>. A higher-precision native implementation is allowed.</li> <li>Comparisons <strong>Less Than</strong> (<code><span class='Function'><</span></code>), <strong>Greater Than</strong> (<code><span class='Function'>></span></code>), <strong>Greater Than or Equal to</strong> (<code><span class='Function'>≥</span></code>), and <strong>Not Equals</strong> (<code><span class='Function'>≠</span></code>) are defined in terms of the two provided comparisons.</li> </ul> <h3 id="iteration-modifiers"><a class="header" href="#iteration-modifiers">Iteration modifiers</a></h3> |
