It seems Float.init(exactly: NSNumber) has not been updated to behave similarly?<br><br>I would have to say, I would naively expect &quot;exactly&quot; to behave exactly as it says, exactly. I don&#39;t think it should be a synonym for Float(Double(exactly:)).<br><div class="gmail_quote"><div dir="ltr">On Mon, Apr 17, 2017 at 19:24 Philippe Hausler via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; 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;line-break:after-white-space"><div>I posted my branch and fixed up the Double case to account for your concerns (with a few inspired unit tests to validate)</div><div><br></div><div><a href="https://github.com/phausler/swift/tree/safe_nsnumber" target="_blank">https://github.com/phausler/swift/tree/safe_nsnumber</a></div><div><br></div><div>There is a builtin assumption here though: it does presume that the swift’s representation of Double and Float are IEEE compliant. However that is a fairly reasonable assumption in the tests.</div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><br><blockquote type="cite"><div>On Apr 15, 2017, at 13:12, Philippe Hausler &lt;<a href="mailto:phausler@apple.com" target="_blank">phausler@apple.com</a>&gt; wrote:</div><br class="m_8621715137279291112Apple-interchange-newline"><div><div style="word-wrap:break-word;line-break:after-white-space"><br><div><br><blockquote type="cite"><div>On Apr 14, 2017, at 22:51, Martin R &lt;<a href="mailto:martinr448@gmail.com" target="_blank">martinr448@gmail.com</a>&gt; wrote:</div><br class="m_8621715137279291112Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>Thank you for the response, but I have more questions. Will</div><div><br></div><div>    Float(exactly: NSNumber(value: Double.pi))</div></div></div></blockquote><div><br></div><div>This will succeed in that the value is representable without loosing mantissa</div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div>    </div><div>fail because Float cannot represent the number Double.pi exactly? Or</div><div><br></div><div>    Double(exactly: NSDecimalNumber(string: &quot;1.9”))</div></div></div></blockquote><div><br></div><div>Again it would be representable without losing mantissa but… </div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div>    </div><div>because Double cannot represent the decimal fraction 1.9 exactly?</div></div></div></blockquote><div><br></div><div>Neither can NSDecimalNumber btw ;X and NSDecimalNumber is not in the scope of this proposal (it is it’s own type and bridges to Decimal)</div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div>I find it difficult to evaluate the proposal without a description of the intended behavior of the &quot;exact&quot; conversions which covers all possible combinations (integers, floating point values, booleans). At present, the behavior is described only for stored integer types.</div></div></div></blockquote><div><br></div><div>I can post the patch but the real machinery is in NSNumber itself. The primary test is that if the value can round trip as the expected type and evaluate to equal to a NSNumber it will.</div><div><br></div><div>The conversion roughy is a cast to and from the stored type;</div><div><br></div><div>extension Double {</div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>init?(exactly number: NSNumber) {</div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">                </span>let value = number.doubleValue</div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">                </span>guard NSNumber(value: value) == number else { return nil }</div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">                </span>self = value</div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div>}</div><div><br></div><div>The effective result of this is a verification of the stored type being equal to the fetched value. But specifically this only traverses via tagged pointers (if the are present). It is worth noting that this is not the exact implementation but an approximation with public apis.</div><div><br></div><div>Overall this is by far a better behavior than just permissively allowing all conversions (which is the current alternative of doing nothing…). As one of the responsible maintainers for NSNumber I would claim that a generally permissive cast as it is today is incorrect usage of NSNumber.</div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div>Regards, Martin</div><div><font face="Menlo"><span style="font-size:11px"><br></span></font><div><blockquote type="cite"><div>On 14. Apr 2017, at 23:23, Philippe Hausler &lt;<a href="mailto:phausler@apple.com" target="_blank">phausler@apple.com</a>&gt; wrote:</div><br class="m_8621715137279291112Apple-interchange-newline"><div><blockquote type="cite" 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><br class="m_8621715137279291112Apple-interchange-newline">On Apr 14, 2017, at 2:11 PM, Martin R via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_8621715137279291112Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>Apologies if I am overlooking something, but it seems to me that the proposal does not clearly define the behavior of the &quot;exact&quot; conversions between integer and floating point values. Does</div><div><br></div><div>    Int(exactly: NSNumber(value: 12.34))</div></div></div></blockquote><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">The exact value of a float or double constructed NSNumber will only happen for integral values: e.g. 1.0, -32.0 etc</div><br 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"><blockquote type="cite" 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="word-wrap:break-word"><div><br></div><div>fail because Int cannot represent the number exactly? Or are floating point values truncated silently and the conversion to an integer fails only if it overflows? And the other way around: Does</div><div><br></div><div>    Double(exactly: NSNumber(value: Int64(9000000000000000001)))</div><div>    </div><div>fail because Double cannot represent the number exactly?</div></div></div></blockquote><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">I believe this will fail because the Int64 value will exceed the mantissa representation of the Double from my current implementation. </div><br 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"><blockquote type="cite" 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="word-wrap:break-word"><div><br></div><div>Regards, Martin</div><div><br></div><div><blockquote type="cite"><div>On 14. Apr 2017, at 20:45, Ben Cohen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_8621715137279291112Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>Apologies, if you are reading this in HTML the links appear to be pointing to the incorrect proposal. </div><div><br></div><div>Here is the corrected link:</div><div><br></div><div><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md</a></div><div><br></div><div><blockquote type="cite"><div>On Apr 14, 2017, at 11:30 AM, Ben Cohen &lt;<a href="mailto:ben_cohen@apple.com" target="_blank">ben_cohen@apple.com</a>&gt; wrote:</div><br class="m_8621715137279291112Apple-interchange-newline"><div><div style="word-wrap:break-word">Hello Swift community,<br><br>The review of “SE-0170: NSNumber bridging and Numeric types&quot; begins now and runs through the Friday after next, April 14th. The proposal is available here:<div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md</a></div></div></div></blockquote><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div><div>Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at</div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div><div>or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:</div><div><br><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>Proposal link: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md</a></div><div><br></div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>Reply text</div><div><br><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>Other replies</div><div><br></div><div><b>What goes into a review?</b><br><br>The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:<br><br><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>• What is your evaluation of the proposal?<br></div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>• Is the problem being addressed significant enough to warrant a change to Swift?<br></div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>• Does this proposal fit well with the feel and direction of Swift?<br></div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?<br></div><div><span class="m_8621715137279291112Apple-tab-span" style="white-space:pre-wrap">        </span>• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?<br></div><div><br></div>More information about the Swift evolution process is available at <a href="https://github.com/apple/swift-evolution/blob/master/process.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/process.md</a><div><br><div>Thank you,</div><div><br></div><div>Ben Cohen</div><div>Review Manager</div><div><br></div><div><br></div></div></div></div></div></div></blockquote></div><br></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>