<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><h1 style="box-sizing: border-box; font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">Enhanced floating-point protocols</h1><ul style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">SE-NNNN</a></li><li style="box-sizing: border-box;" class="">Author(s): <a href="https://github.com/stephentyrone" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">Stephen Canon</a></li><li style="box-sizing: border-box;" class="">Status: <strong style="box-sizing: border-box;" class="">Awaiting review</strong></li><li style="box-sizing: border-box;" class="">Review manager: TBD</li></ul><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-introduction" class="anchor" href="https://github.com/stephentyrone/swift-evolution/blob/master/NNNN-floating-point-protocols.md#introduction" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Introduction</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The current FloatingPoint protocol is quite limited, and provides only a small subset of the features expected of an IEEE 754 conforming type. This proposal expands the protocol to cover most of the expected basic operations, and adds a second protocol, BinaryFloatingPoint, that provides a number of useful tools for generic programming with the most commonly used types.</p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-motivation" class="anchor" href="https://github.com/stephentyrone/swift-evolution/blob/master/NNNN-floating-point-protocols.md#motivation" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Motivation</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Beside the high-level motivation provided by the introduction, the proposed prototype schema addresses a number of issues and requests that we've received from programmers:</p><ul style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">FloatingPoint should conform to Equatable, and Comparable</li><li style="box-sizing: border-box;" class="">FloatingPoint should conform to FloatLiteralConvertible</li><li style="box-sizing: border-box;" class="">Deprecate the <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">%</code> operator for floating-point types</li><li style="box-sizing: border-box;" class="">Provide basic constants (analogues of C's DBL_MAX, etc.)</li><li style="box-sizing: border-box;" class="">Make Float80 conform to FloatingPoint</li></ul><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">It also puts FloatingPoint much more tightly in sync with the work that is being done on protocols for Integers, which will make it easier to provide a uniform interface for arithmetic scalar types.</p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-detailed-design" class="anchor" href="https://github.com/stephentyrone/swift-evolution/blob/master/NNNN-floating-point-protocols.md#detailed-design" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Detailed design</h2><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">A new protocol, <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Arithmetic</code>, is introduced that provides the most basic operations (add, subtract, multiply and divide) as well as <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Equatable</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">IntegerLiteralConvertible</code>, and is conformed to by both integer and floating- point types.</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">There has been some resistance to adding such a protocol, owing to differences in behavior between floating point and integer arithmetic. While these differences make it difficult to write correct generic code that operates on all "arithmetic" types, it is nonetheless convenient to provide a single protocol that guarantees the availability of these basic operations. It is intended that "number-like" types should provide these APIs.</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Arithmetic protocol declares methods backing binary arithmetic operators,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// such as `+`, `-` and `*`; and their mutating counterparts. These methods</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// operate on arguments of the same type.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Both mutating and non-mutating operations are declared in the protocol, but</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// only the mutating ones are required. Should conforming type omit</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// non-mutating implementations, they will be provided by a protocol extension.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Implementation in that case will copy `self`, perform a mutating operation</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// on it and return the resulting value.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> Arithmetic: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Equatable</span>, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">IntegerLiteralConvertible</span> {
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Initialize to zero</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>()
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The sum of `self` and `rhs`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Arithmetic provides a default implementation of this method in terms</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// of the mutating `add` operation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">adding</span>(rhs: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Adds `rhs` to `self`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">add</span>(rhs: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The result of subtracting `rhs` from `self`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Arithmetic provides a default implementation of this method in terms</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// of the mutating `subtract` operation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">subtracting</span>(rhs: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Subtracts `rhs` from `self`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">subtract</span>(rhs: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The product of `self` and `rhs`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Arithmetic provides a default implementation of this method in terms</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// of the mutating `multiply` operation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">multiplied</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">by</span> <span class="pl-smi" style="box-sizing: border-box;">rhs</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Multiplies `self` by `rhs`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">multiply</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">by</span> <span class="pl-smi" style="box-sizing: border-box;">rhs</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The quotient of `self` dividing by `rhs`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Arithmetic provides a default implementation of this method in terms</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// of the mutating `divide` operation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">divided</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">by</span> <span class="pl-smi" style="box-sizing: border-box;">rhs</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Divides `self` by `rhs`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">divide</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">by</span> <span class="pl-smi" style="box-sizing: border-box;">rhs</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
}
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// SignedArithmetic protocol will only be conformed to by signed numbers,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// otherwise it would be possible to negate an unsigned value.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The only method of this protocol has the default implementation in an</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// extension, that uses a parameterless initializer and subtraction.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> SignedArithmetic <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">:</span> Arithmetic {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">negate</span>() <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The usual arithmetic operators are then defined in terms of the implementation hooks provided by <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Arithmetic</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">SignedArithmetic</code>, so providing those operations are all that is necessary for a type to present a "number-like" interface.</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">FloatingPoint</code> protocol is split into two parts; <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">FloatingPoint</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">BinaryFloatingPoint</code>, which conforms to <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">FloatingPoint</code>. If decimal types were added at some future point, they would conform to <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">DecimalFloatingPoint</code>.</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">FloatingPoint</code> is expanded to contain most of the IEEE 754 basic operations, as well as conformance to <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">SignedArithmetic</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Comparable</code>.</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A floating-point type that provides most of the IEEE 754 basic (clause 5)</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// operations. The base, precision, and exponent range are not fixed in</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// any way by this protocol, but it enforces the basic requirements of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// any IEEE 754 floating-point type.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The BinaryFloatingPoint protocol refines these requirements and provides</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// some additional useful operations as well.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> FloatingPoint: SignedArithmetic, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Comparable</span> {
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// An unsigned integer type that can represent the significand of any value.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The significand (<a href="http://en.wikipedia.org/wiki/Significand" class="">http://en.wikipedia.org/wiki/Significand</a>) is frequently</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// also called the "mantissa", but this terminology is slightly incorrect</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// (see the "Use of 'mantissa'" section on the linked Wikipedia page for</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// more details). "Significand" is the preferred terminology in IEEE 754.</span>
associatedtype RawSignificand: UnsignedInteger
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// 2 for binary floating-point types, 10 for decimal.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A conforming type may use any integer radix, but values other than</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// 2 or 10 are extraordinarily rare in practice.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> radix: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Positive infinity. Compares greater than all finite numbers.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> infinity: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A quiet NaN (not-a-number). Compares not equal to every value,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// including itself.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> nan: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// NaN with specified `payload`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Compares not equal to every value, including itself. Most operations</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// with a NaN operand will produce a NaN result. Note that it is generally</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// not the case that all possible significand values are valid</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// NaN `payloads`. `FloatingPoint` types should either treat inadmissible</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// payloads as zero, or mask them to create an admissible payload.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">nan</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">payload</span> <span class="pl-smi" style="box-sizing: border-box;">payload</span>: RawSignificand, signaling: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The greatest finite number.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Compares greater than or equal to all finite numbers, but less than</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// infinity. Corresponds to the C macros `FLT_MAX`, `DBL_MAX`, etc.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The naming of those macros is slightly misleading, because infinity</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// is greater than this value.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> greatestFiniteMagnitude: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// NOTE: Rationale for "ulp" instead of "epsilon":</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// We do not use that name because it is ambiguous at best and misleading</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// at worst:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">//</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// - Historically several definitions of "machine epsilon" have commonly</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// been used, which differ by up to a factor of two or so. By contrast</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// "ulp" is a term with a specific unambiguous definition.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">//</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// - Some languages have used "epsilon" to refer to wildly different values,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// such as `leastMagnitude`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">//</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// - Inexperienced users often believe that "epsilon" should be used as a</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// tolerance for floating-point comparisons, because of the name. It is</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// nearly always the wrong value to use for this purpose.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The unit in the last place of 1.0.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This is the weight of the least significant bit of the significand of 1.0,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// or the positive difference between 1.0 and the next greater representable</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// number. Corresponds to the C macros `FLT_EPSILON`, `DBL_EPSILON`, etc.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> ulp: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The unit in the last place of `self`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This is the unit of the least significant digit in the significand of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `self`. For most numbers `x`, this is the difference between `x` and</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// the next greater (in magnitude) representable number. There are some</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// edge cases to be aware of:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - `greatestFiniteMagnitude.ulp` is a finite number, even though</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// the next greater representable value is `infinity`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - `x.ulp` is `NaN` if `x` is not a finite number.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is very small in magnitude, then `x.ulp` may be a subnormal</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// number. On targets that do not support subnormals, `x.ulp` may be</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// flushed to zero.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This quantity, or a related quantity is sometimes called "epsilon" or</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// "machine epsilon". We avoid that name because it has different meanings</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// in different languages, which can lead to confusion, and because it</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// suggests that it is an good tolerance to use for comparisons,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// which is almost never is.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// (See <a href="https://en.wikipedia.org/wiki/Machine_epsilon" class="">https://en.wikipedia.org/wiki/Machine_epsilon</a> for more detail)</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> ulp: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The least positive normal number.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Compares less than or equal to all positive normal numbers. There may</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// be smaller positive numbers, but they are "subnormal", meaning that</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// they are represented with less precision than normal numbers.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Corresponds to the C macros `FLT_MIN`, `DBL_MIN`, etc. The naming of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// those macros is slightly misleading, because subnormals, zeros, and</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// negative numbers are smaller than this value.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> leastNormalMagnitude: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The least positive number.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Compares less than or equal to all positive numbers, but greater than</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// zero. If the target supports subnormal values, this is smaller than</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `leastNormalMagnitude`; otherwise they are equal.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> leastMagnitude: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `true` iff the signbit of `self` is set. Implements the IEEE 754</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `signbit` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Note that this is not the same as `self < 0`. In particular, this</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// property is true for `-0` and some NaNs, both of which compare not</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// less than zero.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// TODO: strictly speaking a bit and a bool are slightly different</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// concepts. Is another name more appropriate for this property?</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// `isNegative` is incorrect because of -0 and NaN. `isSignMinus` might</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// be acceptable, but isn't great. `signBit` is the IEEE 754 name.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> signBit: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The integer part of the base-r logarithm of the magnitude of `self`,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// where r is the radix (2 for binary, 10 for decimal). Implements the</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// IEEE 754 `logB` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Edge cases:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is zero, then `x.exponent` is `Int.min`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is +/-infinity or NaN, then `x.exponent` is `Int.max`</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> exponent: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The significand satisfies:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ~~~</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// self = (signBit ? -1 : 1) * significand * radix**exponent</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ~~~</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// If radix is 2 (the most common case), then for finite non-zero numbers</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `1 <= significand` and `significand < 2`. For other values of `x`,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `x.significand` is defined as follows:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is zero, then `x.significand` is 0.0.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is infinity, then `x.significand` is 1.0.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is NaN, then `x.significand` is NaN.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// For all floating-point `x`, if we define y by:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ~~~</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// let y = Self(signBit: x.signBit, exponent: x.exponent,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// significand: x.significand)</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ~~~</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// then `y` is equivalent to `x`, meaning that `y` is `x` canonicalized.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> significand: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Initialize from signBit, exponent, and significand.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The result is:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ~~~</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// (signBit ? -1 : 1) * significand * radix**exponent</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// ~~~</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// (where `**` is exponentiation) computed as if by a single correctly-</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// rounded floating-point operation. If this value is outside the</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// representable range of the type, overflow or underflow occurs, and zero,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// a subnormal value, or infinity may result, as with any basic operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Other edge cases:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `significand` is zero or infinite, the result is zero or infinite,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// regardless of the value of `exponent`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `significand` is NaN, the result is NaN.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Note that for any floating-point `x` the result of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `Self(signBit: x.signBit,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// exponent: x.exponent,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// significand: x.significand)`</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// is "the same" as `x`; it is `x` canonicalized.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Because of these properties, this initializer implements the IEEE 754</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `scaleB` operation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>(signBit: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>, exponent: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span>, significand: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A floating point value whose exponent and signficand are taken from</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `magnitude` and whose signBit is taken from `signOf`. Implements the</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// IEEE 754 `copysign` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// TODO: better argument names would be great.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>(magnitudeOf magnitude: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, signOf: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The least representable value that compares greater than `self`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is `-infinity`, then `x.nextUp` is `-greatestMagnitude`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is `-leastMagnitude`, then `x.nextUp` is `-0.0`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is zero, then `x.nextUp` is `leastMagnitude`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is `greatestMagnitude`, then `x.nextUp` is `infinity`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// - If `x` is `infinity` or `NaN`, then `x.nextUp` is `x`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> nextUp: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The greatest representable value that compares less than `self`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `x.nextDown` is equivalent to `-(-x).nextUp`</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> nextDown: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Remainder of `self` divided by `other`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// For finite `self` and `other`, the remainder `r` is defined by</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `r = self - other*n`, where `n` is the integer nearest to `self/other`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// (Note that `n` is *not* `self/other` computed in floating-point</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// arithmetic, and that `n` may not even be representable in any available</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// integer type). If `self/other` is exactly halfway between two integers,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `n` is chosen to be even.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// It follows that if `self` and `other` are finite numbers, the remainder</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `r` satisfies `-|other|/2 <= r` and `r <= |other|/2`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `formRemainder` is always exact, and therefore is not affected by</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// rounding modes.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">formRemainder</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">dividingBy</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Remainder of `self` divided by `other` using truncating division.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// If `self` and `other` are finite numbers, the truncating remainder</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `r` has the same sign as `other` and is strictly smaller in magnitude.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// It satisfies `r = self - other*n`, where `n` is the integral part</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// of `self/other`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `formTruncatingRemainder` is always exact, and therefore is not</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// affected by rounding modes.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">formTruncatingRemainder</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">dividingBy</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Mutating form of square root.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">formSquareRoot</span>( )
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Fused multiply-add, accumulating the product of `lhs` and `rhs` to `self`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">mutating</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">addProduct</span>(lhs: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">_</span> <span class="pl-smi" style="box-sizing: border-box;">rhs</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Remainder of `self` divided by `other`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">remainder</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">dividingBy</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Remainder of `self` divided by `other` using truncating division.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">truncatingRemainder</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">dividingBy</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Square root of `self`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">squareRoot</span>( ) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `self + lhs*rhs` computed without intermediate rounding.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">addingProduct</span>(lhs: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">_</span> <span class="pl-smi" style="box-sizing: border-box;">rhs</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The minimum of `x` and `y`. Implements the IEEE 754 `minNum` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Returns `x` if `x <= y`, `y` if `y < x`, and whichever of `x` or `y`</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// is a number if the other is NaN. The result is NaN only if both </span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// arguments are NaN.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This function is an implementation hook to be used by the free function</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// min(Self, Self) -> Self so that we get the IEEE 754 behavior with regard</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// to NaNs.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">minimum</span>(x: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">_</span> <span class="pl-smi" style="box-sizing: border-box;">y</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The maximum of `x` and `y`. Implements the IEEE 754 `maxNum` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Returns `x` if `x >= y`, `y` if `y > x`, and whichever of `x` or `y`</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// is a number if the other is NaN. The result is NaN only if both</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// arguments are NaN.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This function is an implementation hook to be used by the free function</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// max(Self, Self) -> Self so that we get the IEEE 754 behavior with regard</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// to NaNs.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">maximum</span>(x: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">_</span> <span class="pl-smi" style="box-sizing: border-box;">y</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Whichever of `x` or `y` has lesser magnitude. Implements the IEEE 754</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `minNumMag` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Returns `x` if abs(x) <= abs(y), `y` if abs(y) < abs(x), and whichever of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `x` or `y` is a number if the other is NaN. The result is NaN</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// only if both arguments are NaN.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">minimumMagnitude</span>(x: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">_</span> <span class="pl-smi" style="box-sizing: border-box;">y</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Whichever of `x` or `y` has greater magnitude. Implements the IEEE 754</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `maxNumMag` operation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Returns `x` if abs(x) >= abs(y), `y` if abs(y) > abs(x), and whichever of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `x` or `y` is a number if the other is NaN. The result is NaN</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// only if both arguments are NaN.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">maximumMagnitude</span>(x: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">_</span> <span class="pl-smi" style="box-sizing: border-box;">y</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> Self
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// IEEE 754 equality predicate.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// -0 compares equal to +0, and NaN compares not equal to anything,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// including itself.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isEqual</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">to</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// IEEE 754 less-than predicate.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// NaN compares not less than anything. -infinity compares less than</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// all values except for itself and NaN. Everything except for NaN and</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// +infinity compares less than +infinity.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isLess</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">than</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// IEEE 754 less-than-or-equal predicate.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// NaN compares not less than or equal to anything, including itself.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// -infinity compares less than or equal to everything except NaN.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Everything except NaN compares less than or equal to +infinity.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Because of the existence of NaN in FloatingPoint types, trichotomy does</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// not hold, which means that `x < y` and `!(y <= x)` are not equivalent.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This is why `isLessThanOrEqual(to:)` is a separate implementation hook</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// in the protocol.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Note that this predicate does not impose a total order. The `totalOrder`</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// predicate provides a refinement satisfying that criteria.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isLessThanOrEqual</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">to</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// IEEE 754 unordered predicate. True if either `self` or `other` is NaN,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// and false otherwise.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isUnordered</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">with</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is normal.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A normal number uses the full precision available in the format. Zero</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// is not a normal number.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isNormal: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is finite.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// If `x.isFinite` is `true`, then one of `x.isZero`, `x.isSubnormal`, or</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `x.isNormal` is also `true`, and `x.isInfinite` and `x.isNan` are</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `false`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isFinite: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True iff `self` is zero. Equivalent to `self == 0`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isZero: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is subnormal.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A subnormal number does not use the full precision available to normal</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// numbers of the same format. Zero is not a subnormal number.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isSubnormal: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is infinite.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Note that `isFinite` and `isInfinite` do not form a dichotomy, because</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// they are not total. If `x` is `NaN`, then both properties are `false`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isInfinite: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is NaN ("not a number").</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isNan: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is a signaling NaN.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isSignalingNan: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The IEEE 754 "class" of this type.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> floatingPointClass: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">FloatingPointClassification</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` is canonical.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Every floating-point value of type Float or Double is canonical, but</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// non-canonical values of type Float80 exist, and non-canonical values</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// may exist for other types that conform to FloatingPoint.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The non-canonical Float80 values are known as "pseudo-denormal",</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// "unnormal", "pseudo-infinity", and "pseudo-NaN".</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// (<a href="https://en.wikipedia.org/wiki/Extended_precision#x86_Extended_Precision_Format" class="">https://en.wikipedia.org/wiki/Extended_precision#x86_Extended_Precision_Format</a>)</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> isCanonical: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `self` preceeds `other` in the IEEE 754 total order</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// relation.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// This relation is a refinement of `<=` that provides a total order on all</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// values of type `Self`, including non-canonical encodings, signed zeros,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// and NaNs. Because it is used much less frequently than the usual</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// comparisons, there is no operator form of this relation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">totalOrder</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">with</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// True if and only if `abs(self)` preceeds `abs(other)` in the IEEE 754</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// total order relation.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">totalOrderMagnitude</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">with</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The closest representable value to the argument.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Source: Integer<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>(_ value: Source)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Fails if the argument cannot be exactly represented.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>?<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Source: Integer<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>(exactly value: Source)
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">The <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">BinaryFloatingPoint</code> protocol provides a number of additional APIs that only make sense for types with fixed radix 2:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;" class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// A radix-2 (binary) floating-point type that follows the IEEE 754 encoding</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// conventions.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">protocol</span> BinaryFloatingPoint: FloatingPoint {
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The number of bits used to represent the exponent.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Following IEEE 754 encoding convention, the exponent bias is:</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// bias = 2**(exponentBitCount-1) - 1</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The least normal exponent is `1-bias` and the largest finite exponent</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// is `bias`. The all-zeros exponent is reserved for subnormals and zeros,</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// and the all-ones exponent is reserved for infinities and NaNs.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> exponentBitCount: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// For fixed-width floating-point types, this is the number of fractional</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// significand bits.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// For extensible floating-point types, `significandBitCount` should be</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// the maximum allowed significand width (without counting any leading</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// integral bit of the significand). If there is no upper limit, then</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `significandBitCount` should be `Int.max`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Note that `Float80.significandBitCount` is 63, even though 64 bits</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// are used to store the significand in the memory representation of a</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `Float80` (unlike other floating-point types, `Float80` explicitly</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// stores the leading integral significand bit, but the</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `BinaryFloatingPoint` APIs provide an abstraction so that users don't</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// need to be aware of this detail).</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">static</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> significandBitCount: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The raw encoding of the exponent field of the floating-point value.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> exponentBitPattern: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">UInt</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The raw encoding of the significand field of the floating-point value.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `significandBitPattern` does *not* include the leading integral bit of</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// the significand, even for types like `Float80` that store it explicitly.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> significandBitPattern: RawSignificand { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Combines `signBit`, `exponent` and `significand` bit patterns to produce</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// a floating-point value.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>(signBit: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>,
exponentBitPattern: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">UInt</span>,
significandBitPattern: RawSignificand)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The least-magnitude member of the binade of `self`.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// If `x` is `+/-significand * 2**exponent`, then `x.binade` is</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `+/- 2**exponent`; i.e. the floating point number with the same sign</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// and exponent, but with a significand of 1.0.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> binade: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Self</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// The number of bits required to represent significand.</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">///</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// If `self` is not a finite non-zero number, `significandWidth` is</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `-1`. Otherwise, it is the number of bits required to represent the</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// significand exactly (less `1` because common formats represent one bit</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// implicitly).</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> significandWidth: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> { <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">get</span> }
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isEqual</span><Other: BinaryFloatingPoint>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">to</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: Other) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isLess</span><Other: BinaryFloatingPoint>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">than</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: Other) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isLessThanOrEqual</span><Other: BinaryFloatingPoint>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">to</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: Other) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">isUnordered</span><Other: BinaryFloatingPoint>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">with</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: Other) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">@warn_unused_result</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">totalOrder</span><Other: BinaryFloatingPoint>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">with</span> <span class="pl-smi" style="box-sizing: border-box;">other</span>: Other) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Bool</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// `value` rounded to the closest representable value.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Source: BinaryFloatingPoint<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>(_ value: Source)
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">/// Fails if `value` cannot be represented exactly as `Self`.</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">init</span>?<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>Source: BinaryFloatingPoint<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>(exactly value: Source)
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Float</code>, <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Double</code>, <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Float80</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">CGFloat</code> will conform to all of these protocols.</p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">A small portion of the implementation of these APIs is dependent on new Integer protocols that will be proposed separately. Everything else is implemented in draft form on the branch floating-point-revision of <a href="https://github.com/stephentyrone/swift" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none;" class="">my fork</a>.</p><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-impact-on-existing-code" class="anchor" href="https://github.com/stephentyrone/swift-evolution/blob/master/NNNN-floating-point-protocols.md#impact-on-existing-code" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Impact on existing code</h2><ol style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class=""><p style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;" class="">The <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">%</code> operator is no longer available for FloatingPoint types. We don't believe that it was widely used correctly, and the operation is still available via the <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">formTruncatingRemainder</code> method for people who need it.</p></li><li style="box-sizing: border-box;" class=""><p style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;" class="">To follow the naming guidelines, <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">NaN</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">isNaN</code> are replaced with <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">nan</code> and <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">isNan</code>.</p></li><li style="box-sizing: border-box;" class=""><p style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;" class="">The redundant property <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">quietNaN</code> is removed.</p></li><li style="box-sizing: border-box;" class=""><p style="box-sizing: border-box; margin-top: 16px; margin-bottom: 16px;" class=""><code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">isSignaling</code> is renamed <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">isSignalingNan</code>.</p></li></ol><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-alternatives-considered" class="anchor" href="https://github.com/stephentyrone/swift-evolution/blob/master/NNNN-floating-point-protocols.md#alternatives-considered" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192); text-decoration: none; display: inline-block; padding-right: 2px; margin-left: -18px; line-height: 1;"><svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg></a>Alternatives considered</h2><div style="box-sizing: border-box; margin-top: 0px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255); margin-bottom: 0px !important;" class="">N/A.</div></body></html>