<div dir="ltr">On Wed, May 24, 2017 at 01:55 Martin R &lt;<a href="mailto:martinr448@gmail.com" target="_blank">martinr448@gmail.com</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On 24. May 2017, at 04:34, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-2997976364646739396m_7205747758231860039Apple-interchange-newline"><div><div style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Yes. First, the Foundation initializer converting from NSNumber has the same behavior:</div><div style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">```</div><div style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">import Foundation</div><div style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">let x = Int(42.5 as NSNumber) // x == 42</div><div style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">```</div></div></blockquote></div><br></div><div style="word-wrap:break-word"><div>As of SE-170 (which is implemented in Swift 4), the label &quot;truncating&quot; is also used for conversions which loose precision:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> x = </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">42.5</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">NSNumber</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">) </span><span style="font-variant-ligatures:no-common-ligatures">// // warning: &#39;init&#39; is deprecated</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> y = </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(truncating: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">42.5</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">NSNumber</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400">// 42</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> z = </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures">(exactly: </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">42.5</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">NSNumber</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400">// nil</span></div></div></div></blockquote><div><br></div><div>...it is true that SE-0170 gives you a labeled initializer called `truncating`, but in this case it really does mean truncating the bit pattern. If the argument is a floating point value, then rounding towards zero happens before truncating the bit pattern, but this is not why it&#39;s labeled as truncating:</div><div><br></div><div>```</div><div>import Foundation</div><div><br></div><div>let x = Int8(truncating: 442.5 as NSNumber) // -70</div><div>let y = Int8(truncating: 442 as NSNumber) // -70</div><div>let z = Int8(extendingOrTruncating: 442 as Int) // -70</div><div><br></div><div>let a = Int8(442.5) // fatal error</div><div>```</div><div><br></div><div>This is very important because, if an NSNumber were converted by truncating the bit pattern if a whole number, but only by rounding if floating point, then two very close values could be converted very differently. Instead, this initializer does what it says on the tin: it always truncates the bit pattern of the value rounded toward zero in order to be representable. Again, illustrating the importance of consistent usage of this term; truncating here really does mean truncating the bit pattern.</div><div><br></div></div></div>