320 lines
13 KiB
HTML
320 lines
13 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Protocols Reference</title>
|
||
<link rel="stylesheet" type="text/css" href="css/highlight.css">
|
||
<link rel="stylesheet" type="text/css" href="css/jazzy.css">
|
||
<script src="js/jquery.min.js" defer></script>
|
||
<script src="js/jazzy.js" defer></script>
|
||
|
||
</head>
|
||
<body>
|
||
<a title="Protocols Reference"></a>
|
||
<header>
|
||
<p class="primary">
|
||
<a href="index.html">NumericAnnex Reference</a>
|
||
(100% documented)
|
||
</p>
|
||
<p>
|
||
<a href="https://github.com/xwu/NumericAnnex">View on GitHub</a>
|
||
</p>
|
||
<p>
|
||
<a href="dash-feed://https%3A%2F%2Fxwu%2Egithub%2Eio%2FNumericAnnex%2Fdocsets%2FNumericAnnex%2Exml">Install in Dash</a>
|
||
</p>
|
||
</header>
|
||
<div class="wrapper">
|
||
<nav>
|
||
<ul>
|
||
<li>
|
||
<p><a href="Classes.html">Classes</a></p>
|
||
<ul>
|
||
<li>
|
||
<a href="Classes/Random.html">Random</a>
|
||
</li>
|
||
<li>
|
||
<a href="Classes/Random/Xoroshiro.html">– Xoroshiro</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<p><a href="Extensions.html">Extensions</a></p>
|
||
<ul>
|
||
<li>
|
||
<a href="Extensions/BinaryInteger.html">BinaryInteger</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Double.html">Double</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/DoubleWidth.html">DoubleWidth</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Float.html">Float</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/FloatingPoint.html">FloatingPoint</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Int.html">Int</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Int16.html">Int16</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Int32.html">Int32</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Int64.html">Int64</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/Int8.html">Int8</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/UInt.html">UInt</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/UInt16.html">UInt16</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/UInt32.html">UInt32</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/UInt64.html">UInt64</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/UInt8.html">UInt8</a>
|
||
</li>
|
||
<li>
|
||
<a href="Extensions/UnsignedInteger.html">UnsignedInteger</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<p><a href="Functions.html">Functions</a></p>
|
||
<ul>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex3absAA7ComplexVyxGAeA4RealRzs9DecodableRzs9EncodableRzs33_ExpressibleByBuiltinFloatLiteralRzlF">abs(_:)</a>
|
||
</li>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex3absAA8RationalVyxGAEs9DecodableRzs9EncodableRzs13SignedIntegerRzs021_ExpressibleByBuiltinH7LiteralRzs08UnsignedH09Magnitudes0A0PRpzAkM_AKQZANRSlF">abs(_:)</a>
|
||
</li>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex4ceilAA8RationalVyxGAEs9DecodableRzs9EncodableRzs13SignedIntegerRzs021_ExpressibleByBuiltinH7LiteralRzs08UnsignedH09Magnitudes0A0PRpzAkM_AKQZANRSlF">ceil(_:)</a>
|
||
</li>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex5floorAA8RationalVyxGAEs9DecodableRzs9EncodableRzs13SignedIntegerRzs021_ExpressibleByBuiltinH7LiteralRzs08UnsignedH09Magnitudes0A0PRpzAkM_AKQZANRSlF">floor(_:)</a>
|
||
</li>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex5roundAA8RationalVyxGAEs9DecodableRzs9EncodableRzs13SignedIntegerRzs021_ExpressibleByBuiltinH7LiteralRzs08UnsignedH09Magnitudes0A0PRpzAkM_AKQZANRSlF">round(_:)</a>
|
||
</li>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex4sqrtAA7ComplexVyxGAeA4RealRzs9DecodableRzs9EncodableRzs33_ExpressibleByBuiltinFloatLiteralRzlF">sqrt(_:)</a>
|
||
</li>
|
||
<li>
|
||
<a href="Functions.html#/s:12NumericAnnex5truncAA8RationalVyxGAEs9DecodableRzs9EncodableRzs13SignedIntegerRzs021_ExpressibleByBuiltinH7LiteralRzs08UnsignedH09Magnitudes0A0PRpzAkM_AKQZANRSlF">trunc(_:)</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<p><a href="Protocols.html">Protocols</a></p>
|
||
<ul>
|
||
<li>
|
||
<a href="Protocols/Math.html">Math</a>
|
||
</li>
|
||
<li>
|
||
<a href="Protocols/PRNG.html">PRNG</a>
|
||
</li>
|
||
<li>
|
||
<a href="Protocols/Real.html">Real</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<p><a href="Structs.html">Structures</a></p>
|
||
<ul>
|
||
<li>
|
||
<a href="Structs/Complex.html">Complex</a>
|
||
</li>
|
||
<li>
|
||
<a href="Structs/Rational.html">Rational</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li>
|
||
<p><a href="Typealiases.html">Type Aliases</a></p>
|
||
<ul>
|
||
<li>
|
||
<a href="Typealiases.html#/s:12NumericAnnex12RoundingRulea">RoundingRule</a>
|
||
</li>
|
||
<li>
|
||
<a href="Typealiases.html#/s:12NumericAnnex4Signa">Sign</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</nav>
|
||
<article>
|
||
<section>
|
||
<div class="wrapper">
|
||
<div class="overview">
|
||
<h1>Protocols</h1>
|
||
<p>The following protocols are available globally.</p>
|
||
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section class="toc">
|
||
<details open>
|
||
<summary>Topics</summary>
|
||
<div class="wrapper">
|
||
<ul>
|
||
<li><a href="#/s:12NumericAnnex4PRNGP">PRNG</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li><a href="#/s:12NumericAnnex4RealP">Real</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li><a href="#/s:12NumericAnnex4MathP">Math</a></li>
|
||
</ul>
|
||
</div>
|
||
</details>
|
||
</section>
|
||
<section>
|
||
<div class="wrapper">
|
||
<div class="group">
|
||
<ul>
|
||
<li>
|
||
<div>
|
||
<a name="/s:12NumericAnnex4PRNGP"></a>
|
||
<a name="//apple_ref/swift/Protocol/PRNG" class="dashAnchor"></a>
|
||
<h4>
|
||
<code>PRNG</code>
|
||
</h4>
|
||
</div>
|
||
<div class="abstract">
|
||
<p>A pseudo-random number generator (PRNG).</p>
|
||
|
||
<p>Reference types that conform to <code>PRNG</code> are infinite sequences of
|
||
pseudo-random elements. Protocol extension methods iterate over such a
|
||
sequence as necessary to generate pseudo-random values from the desired
|
||
distribution.</p>
|
||
<h2 id='considerations-for-conforming-types' class='heading'>Considerations for Conforming Types</h2>
|
||
|
||
<p>For clarity to end users, custom PRNGs may be implemented in an extension to
|
||
<code><a href="Classes/Random.html">Random</a></code>. For instance, the <code>xoroshiro128+</code> algorithm is implemented in a
|
||
final class named <code><a href="Classes/Random/Xoroshiro.html">Random.Xoroshiro</a></code>.</p>
|
||
|
||
<p>The static methods <code>_entropy(_:)</code> and <code>_entropy(_:count:)</code> return
|
||
cryptographically secure random bytes that may be useful for seeding your
|
||
custom PRNG. However, these methods may return <code>nil</code> if the requested number
|
||
of random bytes is not available, and they are not recommended as a routine
|
||
source of random data.</p>
|
||
<h2 id='adding-other-probability-distributions' class='heading'>Adding Other Probability Distributions</h2>
|
||
|
||
<p>Many built-in protocol extension methods make use of the primitive,
|
||
overloaded method <code>_random(_:bitCount:)</code>. You may wish to use the same
|
||
method in new protocol extension methods that return pseudo-random
|
||
values from other probability distributions.</p>
|
||
|
||
<p>The method <code>_random(_:bitCount:)</code> generates uniformly distributed binary
|
||
floating-point values in the half-open range [0, 1) with a precision of
|
||
either <code>bitCount</code> or the significand bit count of the floating-point type,
|
||
whichever is less. Additionally, this method generates uniformly distributed
|
||
unsigned integers in the half-open range [0, 2 ** <em>x</em>), where ** is the
|
||
exponentiation operator and <em>x</em> is the lesser of <code>bitCount</code> and the bit
|
||
width of the integer type.</p>
|
||
|
||
<p>For end users, however, the recommended spelling for a uniformly distributed
|
||
numeric value is <code>uniform()</code>; that method is overloaded to permit custom
|
||
minimum and maximum values for the uniform distribution.</p>
|
||
|
||
<a href="Protocols/PRNG.html">See more…</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h5>Declaration</h5>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">PRNG</span> <span class="p">:</span> <span class="kd">class</span><span class="p">,</span> <span class="kt">IteratorProtocol</span><span class="p">,</span> <span class="kt">Sequence</span>
|
||
<span class="k">where</span> <span class="kt">Element</span> <span class="p">:</span> <span class="kt">FixedWidthInteger</span> <span class="o">&</span> <span class="kt">UnsignedInteger</span><span class="p">,</span>
|
||
<span class="kt">SubSequence</span> <span class="p">:</span> <span class="kt">Sequence</span><span class="p">,</span>
|
||
<span class="kt">Element</span> <span class="o">==</span> <span class="kt">SubSequence</span><span class="o">.</span><span class="kt">Element</span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="group">
|
||
<ul>
|
||
<li>
|
||
<div>
|
||
<a name="/s:12NumericAnnex4RealP"></a>
|
||
<a name="//apple_ref/swift/Protocol/Real" class="dashAnchor"></a>
|
||
<h4>
|
||
<code>Real</code>
|
||
</h4>
|
||
</div>
|
||
<div class="abstract">
|
||
<p>A floating-point type that supports elementary functions and a selection of
|
||
special functions.</p>
|
||
|
||
<p>The <code>Real</code> protocol provides a suitable basis for writing functions that
|
||
work on any floating-point type that supports the required functions.</p>
|
||
|
||
<a href="Protocols/Real.html">See more…</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h5>Declaration</h5>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">Real</span> <span class="p">:</span> <span class="kt"><a href="Protocols/Math.html">Math</a></span><span class="p">,</span> <span class="kt">FloatingPoint</span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="group">
|
||
<ul>
|
||
<li>
|
||
<div>
|
||
<a name="/s:12NumericAnnex4MathP"></a>
|
||
<a name="//apple_ref/swift/Protocol/Math" class="dashAnchor"></a>
|
||
<h4>
|
||
<code>Math</code>
|
||
</h4>
|
||
</div>
|
||
<div class="abstract">
|
||
<p>A signed numeric type that supports elementary functions.</p>
|
||
|
||
<p>The <code>Math</code> protocol provides a suitable basis for writing functions that
|
||
work on any real or complex floating-point type that supports the required
|
||
functions.</p>
|
||
|
||
<a href="Protocols/Math.html">See more…</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h5>Declaration</h5>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">protocol</span> <span class="kt">Math</span> <span class="p">:</span> <span class="kt">SignedNumeric</span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</article>
|
||
</div>
|
||
<footer>
|
||
<p>© 2017 <a class="link" href="https://diploid.ca" target="_blank" rel="external">Xiaodi Wu</a>. All rights reserved. (Last updated: 2017-09-30)</p>
|
||
<p>Generated by <a href="https://github.com/realm/jazzy" target="_blank" rel="external">Jazzy</a> v0.8.4, a <a href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
|
||
</footer>
|
||
</body>
|
||
</div>
|
||
</html>
|