Stephen Canon wrote that Arithmetic should refine ExpressibleByIntegerLiteral because of certain mathematical properties of rings. In that case, 0 and 1 would just be spelled in that way. Otherwise, +1.<br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 25, 2017 at 11:38 Anton Mironov via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">Hi everyone,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I want to suggest a tiny extension to an Arithmetic protocol. It would be nice to have an additive identity and a multiplicative identity constants. Basically zero and one.</div><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">```</div><div class="gmail_msg">protocol Arithmetic {</div><div class="gmail_msg"> /* ... */</div><div class="gmail_msg"> static var zero: Self { get } // additive identity: (value + .zero) == value</div><div class="gmail_msg"> static var one: Self { get } // multiplicative identity: (value * .one) == value</div><div class="gmail_msg">}</div></div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">These constants will ease implementation of math structures: vectors, matrices and etc.</div><div class="gmail_msg">I’m sorry if I’m duplicating someone’s suggestion. It is really hard to search for something in a long thread.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thanks,</div><div class="gmail_msg">Anton Mironov</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 13, 2017, at 10:47 PM, Max Moiseev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_3016805478697593964Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg">Hi everyone,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Back in June 2016 we discussed the new design of the integer types for the standard library. It even resulted in acceptance of <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md" class="gmail_msg" target="_blank">SE-0104</a> for Swift 3. Unfortunately we were not able to implement it in time for the release.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">But it was not forgotten, although, as time went by, a few changes needed to be made in order to reflect the current state of the language.</div><div class="gmail_msg">Without further introduction, please welcome the refined proposal to make integers in Swift more suitable for generic programming.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Available in this gist <a href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c" class="gmail_msg" target="_blank">https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c</a> and also inlined below.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Max</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><h1 style="box-sizing:border-box;margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.25;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:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255);margin-top:0px!important" class="gmail_msg">Protocol-oriented integers (take 2)</h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">Proposal: <a href="https://gist.github.com/moiseev/0000-even-more-improved-integers.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-NNNN</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Authors: <a href="https://github.com/dabrahams" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Dave Abrahams</a>, <a href="https://github.com/moiseev" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Maxim Moiseev</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Review Manager: TBD</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Status: <span style="box-sizing:border-box;font-weight:600" class="gmail_msg">Awaiting review</span></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Bug: <a href="https://bugs.swift.org/browse/SR-3196" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SR-3196</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Previous Proposal: <a href="https://gist.github.com/moiseev/0104-improved-integers.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-0104</a></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;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:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-introduction" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">This proposal is an evolution of <a href="https://gist.github.com/moiseev/0104-improved-integers.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-0104</a>. The goal is still to clean up Swifts integer APIs and make them more useful for generic programming.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The language has evolved in ways that affect integers APIs since the time the original proposal was approved for Swift 3. We also attempted to implement the proposed model in the standard library and found that some essential APIs were missing, whereas others could be safely removed.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Major changes to the APIs introduced by this proposal (as compared to <a href="https://gist.github.com/moiseev/0104-improved-integers.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-0104</a>) are listed in a <a href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#whats-new-since-se-0104" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">dedicated section</a>.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;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:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-motivation" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Swift's integer protocols don't currently provide a suitable basis for generic programming. See <a href="http://blog.krzyzanowskim.com/2015/03/01/swift_madness_of_generic_integer/" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">this blog post</a> for an example of an attempt to implement a generic algorithm over integers.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The way 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="gmail_msg">Arithmetic</code> protocol is defined, it does not generalize to floating point numbers and also slows down compilation by requiring every concrete type to provide an implementation of arithmetic operators, thus polluting the overload set.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Converting from one integer type to another is performed using the concept of the 'maximum width integer' (see <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="gmail_msg">MaxInt</code>), which is an artificial limitation. The very existence of <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="gmail_msg">MaxInt</code> makes it unclear what to do should someone implement <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="gmail_msg">Int256</code>, for example.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Another annoying problem is the inability to use integers of different types in comparison and bit-shift operations. For example, the following snippets won't compile:</p><div class="m_3016805478697593964highlight m_3016805478697593964highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,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;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;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-break:normal" class="gmail_msg"><span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> x<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Int8</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">42</span>
<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> y <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>
<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> z <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0</span>
x <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)"><<=</span> y <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">//</span> error: binary operator '<<=' cannot be applied to operands of type 'Int8' and 'Int'</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> x <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">></span> z { <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">...</span> } <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">//</span> error: binary operator '>' cannot be applied to operands of type 'Int8' and 'Int'</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Currently, bit-shifting a negative number of (or too many) bits causes a trap on some platforms, which makes low-level bit manipulations needlessly dangerous and unpredictable.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Finally, the current design predates many of the improvements that came since Swift 1, and hasn't been revised since then.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;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:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-proposed-solution" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#proposed-solution" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Proposed solution</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">We propose a new model that does not have above mentioned problems and is more easily extensible.</p><pre style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;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;color:rgb(51,51,51)" class="gmail_msg"><code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal" class="gmail_msg"> +--------------+ +-------------+
+------>+ Arithmetic | | Comparable |
| | (+,-,*,/) | | (==,<,>,...)|
| +-------------++ +---+---------+
| ^ ^
+-------+------------+ | |
| SignedArithmetic | +-+-------+-----------+
| (unary -) | | BinaryInteger |
+------+-------------+ |(words,%,bitwise,...)|
^ ++---+-----+----------+
| +-----------^ ^ ^---------------+
| | | |
+------+---------++ +---------+---------------+ +--+----------------+
| SignedInteger | | FixedWidthInteger | | UnsignedInteger |
| | |(endianness,overflow,...)| | |
+---------------+-+ +-+--------------------+--+ +-+-----------------+
^ ^ ^ ^
| | | |
| | | |
++--------+-+ +-+-------+-+
|Int family |-+ |UInt family|-+
+-----------+ | +-----------+ |
+-----------+ +-----------+
</code></pre><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">There are several benefits provided by this model over the old one:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">It allows mixing integer types in generic functions.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">The possibility to initialize instances of any concrete integer type with values of any other concrete integer type enables writing functions that operate on more than one type conforming 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="gmail_msg">BinaryInteger</code>, such as heterogeneous comparisons or bit shifts, described later.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">It removes the overload resolution overhead.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Arithmetic and bitwise operations can now be defined as generic operators on protocols. This approach significantly reduces the number of overloads for those operations, which used to be defined for every single concrete integer type.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">It enables protocol sharing between integer and floating point types.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Note the exclusion of 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="gmail_msg">%</code> operation from <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="gmail_msg">Arithmetic</code>. Its behavior for floating point numbers is sufficiently different from the one for integers that using it in generic context would lead to confusion. 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="gmail_msg">FloatingPoint</code> protocol introduced by <a href="https://gist.github.com/moiseev/0067-floating-point-protocols.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-0067</a> should now refine <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="gmail_msg">SignedArithmetic</code>.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">It makes future extensions possible.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">The proposed model eliminates the 'largest integer type' concept previously used to interoperate between integer types (see <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="gmail_msg">toIntMax</code> in the current model) and instead provides access to machine words. It also introduces 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="gmail_msg">doubleWidthMultiply</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="gmail_msg">doubleWidthDivide</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="gmail_msg">quotientAndRemainder</code> methods. Together these changes can be used to provide an efficient implementation of bignums that would be hard to achieve otherwise.</p></li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The implementation of proposed model in the standard library is available <a href="https://github.com/apple/swift/tree/new-integer-protocols" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">in the new-integer-protocols branch</a>.</p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-a-note-on-bit-shifts" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#a-note-on-bit-shifts" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>A note on bit shifts</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">This proposal introduces the concepts of <em style="box-sizing:border-box" class="gmail_msg">smart shifts</em> and <em style="box-sizing:border-box" class="gmail_msg">masking shifts</em>.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The semantics of shift operations are <a href="http://llvm.org/docs/LangRef.html#bitwise-binary-operations" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">often undefined</a> in under- or over-shift cases. <em style="box-sizing:border-box" class="gmail_msg">Smart shifts</em>, implemented 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="gmail_msg">>></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="gmail_msg"><<</code>, are designed to address this problem and always behave in a well defined way, as shown in the examples below:</p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">x << -2</code> is equivalent 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="gmail_msg">x >> 2</code></p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">(1 as UInt8) >> 42)</code> will evaluate 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="gmail_msg">0</code></p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">(-128 as Int8) >> 42)</code> will evaluate 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="gmail_msg">0xff</code> or <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="gmail_msg">-1</code></p></li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">In most scenarios, the right hand operand is a literal constant, and branches for handling under- and over-shift cases can be optimized away. For other cases, this proposal provides <em style="box-sizing:border-box" class="gmail_msg">masking shifts</em>, implemented 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="gmail_msg">&>></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="gmail_msg">&<<</code>. A masking shift logically preprocesses the right hand operand by masking its bits to produce a value in the range <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="gmail_msg">0...(x-1)</code> where <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="gmail_msg">x</code> is the number of bits in the left hand operand. On most architectures this masking is already performed by the CPU's shift instructions and has no cost. Both kinds of shift avoid undefined behavior and produce uniform semantics across architectures.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;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:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-detailed-design" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#detailed-design" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Detailed design</h2><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-whats-new-since-se-0104" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#whats-new-since-se-0104" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>What's new since SE-0104</h3><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><a href="https://gist.github.com/moiseev/0091-improving-operators-in-protocols.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-0091</a> removed the necessity to dispatch generic operators through special methods.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">All operators are now declared by protocols 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="gmail_msg">static func</code>s.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Standard Library no longer provides <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="gmail_msg">+</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="gmail_msg">-</code> operators for <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="gmail_msg">Strideable</code> types.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">They were problematic, as one could have written mixed-type code like <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="gmail_msg">let x: Int64 = 42; x += (1 as Int)</code>, which would compile, but shouldn't. Besides, since 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="gmail_msg">Stride</code> of an unsigned type is signed, Standard Library had to implement a hack to make code like <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="gmail_msg">let x: UInt = 42; x += (1 as Int)</code> ambiguous. These operators were only necessary because they made advancing collection indices convenient, which is no longer the case since the introduction of the <a href="https://gist.github.com/moiseev/0065-collections-move-indices.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">new indexing model</a> in Swift 3.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Shifts and other bitwise operations were moved from <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="gmail_msg">FixedWidthInteger</code> 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="gmail_msg">BinaryInteger</code>.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Left shift operation on an unbounded integer should infinitely extend the number, and never drop set bits when they reach the most significant position in the underlying representation.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">BitwiseOperations</code> protocol was deprecated.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">We believe there are no useful entities that support bitwise operations, but at the same time are not binary integers.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">minimumSignedRepresentationBitWidth</code> property was removed.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">trailingZeros</code> property was added to 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="gmail_msg">BinaryInteger</code> protocol.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg"><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="gmail_msg">leadingZeros</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="gmail_msg">popcount</code> properties are still defined by 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="gmail_msg">FixedWidthInteger</code> protocol.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Endian-converting initializers and properties were added to 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="gmail_msg">FixedWidthInteger</code> protocol.</p></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg"><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">Standard library introduces the new type <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="gmail_msg">DoubleWidth<T></code>.</p><p style="box-sizing:border-box;margin-top:16px;margin-bottom:16px" class="gmail_msg">See <a href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#doublewidth" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">this section</a> for more details.</p></li></ul><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-protocols" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#protocols" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Protocols</h3><h4 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:16px;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-arithmetic" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#arithmetic" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a><code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:inherit;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="gmail_msg">Arithmetic</code></h4><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">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="gmail_msg">Arithmetic</code> protocol declares binary arithmetic operators – such 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="gmail_msg">+</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="gmail_msg">-</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="gmail_msg">*</code> — and their mutating counterparts.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">It provides a suitable basis for arithmetic on scalars such as integers and floating point numbers.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Both mutating and non-mutating operations are declared in the protocol, however only the mutating ones are required, as default implementations of the non-mutating ones are provided by a protocol extension.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">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="gmail_msg">Magnitude</code> associated type is able to hold the absolute value of any possible value of <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="gmail_msg">Self</code>. Concrete types do not have to provide a type alias for it, as it can be inferred from 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="gmail_msg">magnitude</code> property. This property can be useful in operations that are simpler to implement in terms of unsigned values, for example, printing a value of an integer, which is just printing a '-' character in front of an absolute value.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Please note that for ordinary work, 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="gmail_msg">magnitude</code> property <span style="box-sizing:border-box;font-weight:600" class="gmail_msg">should not</span> be preferred to 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="gmail_msg">abs(_)</code> function, whose return value is of the same type as its argument.</p><div class="m_3016805478697593964highlight m_3016805478697593964highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,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;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;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-break:normal" class="gmail_msg"><span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Arithmetic</span> : <span class="m_3016805478697593964pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Equatable</span>, <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">ExpressibleByIntegerLiteral</span> </span>{
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Creates a new instance from the given integer, if it can be represented</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> exactly.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> If the value passed as `source` is not representable exactly, the result</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> is `nil`. In the following example, the constant `x` is successfully</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> created from a value of `100`, while the attempt to initialize the</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> constant `y` from `1_000` fails because the `Int8` type can represent</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> `127` at maximum:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x = Int8(exactly: 100)</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // x == Optional(100)</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let y = Int8(exactly: 1_000)</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // y == nil</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> - Parameter source: A floating-point value to convert to an integer.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">init?</span><<span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">T</span> : <span class="m_3016805478697593964pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">BinaryInteger</span>>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">exactly</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">source</span>: T)
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> A type that can represent the absolute value of any possible value of the</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> conforming type.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">associatedtype</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Magnitude</span> : <span class="m_3016805478697593964pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Equatable</span>, <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">ExpressibleByIntegerLiteral</span></span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> The magnitude of this value.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> For any numeric value `x`, `x.magnitude` is the absolute value of `x`.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> You can use the `magnitude` property in operations that are simpler to</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> implement in terms of unsigned values, such as printing the value of an</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> integer, which is just printing a '-' character in front of an absolute</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> value.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x = -200</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // x.magnitude == 200</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> The global `abs(_:)` function provides more familiar syntax when you need</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> to find an absolute value. In addition, because `abs(_:)` always returns</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> a value of the same type, even in a generic context, using the function</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> instead of the `magnitude` property is encouraged.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> - SeeAlso: `abs(_:)`</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> magnitude<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Magnitude { <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">get</span> }
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Returns the sum of the two given values.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> The sum of `lhs` and `rhs` must be representable in the same type. In the</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> following example, the result of `100 + 200` is greater than the maximum</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> representable `Int8` value:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x: Int8 = 10 + 21</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // x == 31</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let y: Int8 = 100 + 121</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // Overflow error</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">+</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">rhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>) <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Adds the given value to this value in place.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> For example:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> var x = 15</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> y += 7</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // y == 22</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">+=</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">inout</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">rhs</span></span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>)
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Returns the difference of the two given values.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> The difference of `lhs` and `rhs` must be representable in the same type.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> In the following example, the result of `10 - 21` is less than zero, the</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> minimum representable `UInt` value:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x: UInt = 21 - 10</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // x == 11</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let y: UInt = 10 - 21</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // Overflow error</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">-</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">rhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>) <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Subtracts the given value from this value in place.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> For example:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> var x = 15</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> y -= 7</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // y == 8</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">-=</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">inout</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">rhs</span></span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>)
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Returns the product of the two given values.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> The product of `lhs` and `rhs` must be representable in the same type. In</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> the following example, the result of `10 * 50` is greater than the</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> maximum representable `Int8` value.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x: Int8 = 10 * 5</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // x == 50</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let y: Int8 = 10 * 50</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // Overflow error</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">*</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">rhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>) <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Multiples this value by the given value in place.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> For example:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> var x = 15</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> y *= 7</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // y == 105</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">*=</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">inout</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">rhs</span></span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>)
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Returns the quotient of dividing the first value by the second.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> For integer types, any remainder of the division is discarded.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x = 21 / 5</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // x == 4</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">/</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">rhs</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>) <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Divides this value by the given value in place.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> For example:</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> var x = 15</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> y /= 7</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // y == 2</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">/=</span>(<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">lhs</span>: <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">inout</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>, <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">rhs</span></span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>)
}
<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Arithmetic</span> {
<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">init</span>() { <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">self</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0</span> }
<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">prefix</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">+</span> (<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">x</span></span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>) <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span> {
<span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> x
}
}</pre></div><h4 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:16px;line-height:1.25;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_3016805478697593964user-content-signedarithmetic" class="m_3016805478697593964anchor gmail_msg" href="https://gist.github.com/moiseev/62ffe3c91b66866fdebf6f3fcc7cad8c#signedarithmetic" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a><code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:inherit;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="gmail_msg">SignedArithmetic</code></h4><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">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="gmail_msg">SignedArithmetic</code> protocol is for numbers that can be negated.</p><div class="m_3016805478697593964highlight m_3016805478697593964highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,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;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;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-break:normal" class="gmail_msg"><span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">SignedArithmetic</span> : <span class="m_3016805478697593964pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Arithmetic </span>{
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> Returns the additive inverse of this value.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let x = 21</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> let y = -x</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> // y == -21</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> - Returns: The additive inverse of this value.</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)">///</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box">///</span> - SeeAlso: `negate()`</span>
<span class="m_3016805478697593964pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">prefix</span> <span class="m_3016805478697593964pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">-</span> (<span class="m_3016805478697593964pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_3016805478697593964pl-smi gmail_msg" style="box-sizing:border-box">operand</span>: <span class="m_3016805478697593964pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span></pre></div></div></div></div></blockquote></div></div></blockquote></div>