<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Provided that T is one of the supported types yes that does hold true (and is in the unit tests I have on the pending commit)<br><br>Sent from my iPhone</div><div><br>On Apr 20, 2017, at 11:29 AM, Martin R <<a href="mailto:martinr448@gmail.com">martinr448@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">So is it correct to say that for all types T which NSNumber can hold (Double, Float, Int, UInt, ... )</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">(exactly: someNSNumber)</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></p><div class="">will succeed if and only if</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSNumber</span><span style="font-variant-ligatures: no-common-ligatures" class="">(value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">(truncating: someNSNumber)) == someNSNumber</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">holds? </div><br class=""><div><blockquote type="cite" class=""><div class="">On 20. Apr 2017, at 18:10, Philippe Hausler <<a href="mailto:phausler@apple.com" class="">phausler@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Apr 19, 2017, at 6:09 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br class="" style="font-family: Helvetica; font-size: 12px; 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; -webkit-text-stroke-width: 0px;"><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; 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; -webkit-text-stroke-width: 0px;">On Wed, Apr 19, 2017 at 6:35 PM, Philippe Hausler<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:phausler@apple.com" target="_blank" class="">phausler@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><br class=""><div class=""><div class=""><div class="gmail-h5"><br class=""><blockquote type="cite" class=""><div class="">On Apr 19, 2017, at 16:17, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="gmail-m_-8343307845527599891Apple-interchange-newline"><div class=""><div dir="ltr" class="" style="font-family: helvetica; font-size: 12px; 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;">On Wed, Apr 19, 2017 at 6:00 PM, Philippe Hausler<span class="gmail-m_-8343307845527599891Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:phausler@apple.com" target="_blank" class="">phausler@apple.com</a>></span><span class="gmail-m_-8343307845527599891Apple-converted-space"> </span>w<wbr class="">rote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><br class=""><div class=""><span class="gmail-m_-8343307845527599891gmail-"><blockquote type="cite" class=""><div class="">On Apr 19, 2017, at 3:23 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-interchange-newline"><div class=""><div dir="ltr" class="" style="font-family: helvetica; font-size: 12px; 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;">On Wed, Apr 19, 2017 at 3:19 PM, Martin R<span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:martinr448@gmail.com" target="_blank" class="">martinr448@gmail.com</a>></span><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span>wrote<wbr class="">:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><span class=""><blockquote type="cite" class=""><div class="">On 19. Apr 2017, at 01:48, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521Apple-interchange-newline"><div class=""><div dir="ltr" class="">So, as I understand it, `Float.init(exactly: Double.pi) == nil`. I would expect NSNumber to behave similarly (a notion with which Martin disagrees, I guess). I don't see a test that shows whether NSNumber behaves or does not behave in that way.</div></div></blockquote><div class=""><br class=""></div></span><div class="">At present they behave differently: </div><div class=""><br class=""></div><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">print</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Float</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(exactly: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Double</span><span class="" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);"><wbr class="">pi</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">as</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">Any</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">// nil</span></div></div><span class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">print</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Float</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(exactly: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">NSNumbe<wbr class="">r</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(value: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Double</span><span class="" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">pi</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)) </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">as</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">Any</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div></span><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">// Optional(3.14159274)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);"><span class="">I realize that identical behavior would be logical and least surprising. My only concern was about cases like</span></div></div><div class=""><span class=""><br class=""></span></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span>num = ...<span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures;">// some NSNumber from a JSON deserialization</span></div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span>fval =<span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Float</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(exactly:<span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">num</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;">where one cannot know how the number is represented internally and what precision it needs. But then one could use the truncating conversion or `.floatValue` instead.</div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">JSON numbers are double-precision floating point, unless I'm misunderstanding something. If someone writes `Float(exactly: valueParsedFromJSON)`, surely, that can only mean that they *really, really* prefer nil over an imprecise value. I can see no other reason to insist on using both Float and .init(exactly:).</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">JSON does not claim 32 or 64 bit floating point, or for that matter 128 or infinite bit floating point :(</div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Oops, you're right. I see they've wanted to future-proof this. That said, RFC 7159 *does* say:</div><div class=""><br class=""></div><div class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">This specification allows implementations to set limits on the range</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">and precision of numbers accepted. Since software that implements</blockquote><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">IEEE 754-2008 binary64 (double precision) numbers [IEEE754] is<br class="">generally available and widely used, good interoperability can be<br class="">achieved by implementations that expect no more precision or range<br class="">than these provide, in the sense that implementations will<br class="">approximate JSON numbers within the expected precision.</blockquote></div><div class=""><br class=""></div><div class="">So JSON doesn't set limits on how numbers are represented, but JSON implementations are permitted to (and I'd imagine that all in fact do). A user of a JSON deserialization library can rightly expect to know the numeric limits of that implementation; for the purposes of bridging NSNumber, if the answer is that the implementation parses JSON numbers as double-precision values, Double(exactly:) would be the right choice; otherwise, if it's 80-bit values, then Float80(exactly:) would be the right choice, etc.</div><div class=""><br class=""></div></div></div></div></div></blockquote><div class=""><br class=""></div></div></div><div class="">Float80 is not compatible with NSNumber; and is well out of scope for this proposal.</div></div></div></blockquote><div class=""><br class=""></div><div class="">OK, so Double is the largest floating point type compatible with NSNumber? It stands to reason that any Swift JSON implementation that uses NSNumber for parsed floating point values would at most have that much range and precision, right?</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; -webkit-text-stroke-width: 0px;" class=""><br class=""></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; -webkit-text-stroke-width: 0px;" class="">For JSONSerialization (which I am most familiar with and ships with Foundation); it can emit both NSNumbers and NSDecimalNumber. A rough approximation of the behavior: if it can store the value in an integer type it stores it as such in a NSNumber (iirc up to UINT64_MAX) and then if it has a decimal point it will attempt to parse as a double but if that is not enough storage it will store the best possible value into NSDecimalNumber. </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; -webkit-text-stroke-width: 0px;" class=""><br class=""></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; -webkit-text-stroke-width: 0px;" class="">So NSNumber itself (excluding subclasses) can only store up to a 64 bit value. </div><br class="" 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; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; 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; -webkit-text-stroke-width: 0px;"><div class=""><br class=""></div><div class="">If so, then every floating point value parsed by any such Swift JSON implementation would be exactly representable as a Double: regardless of whether that specific implementation uses Float or Double under the hood, every Float can be represented exactly as a Double. If a user is trying to bridge such a NSNumber instance specifically to *Float* instead of Double, and they are asking for an exact value, there's no a priori reason to think that this user would be more likely to care only about the range and not the precision, or vice versa. Which is to say, I don't think you'll get too many bug reports :)</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; -webkit-text-stroke-width: 0px;" class=""><br class=""></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; -webkit-text-stroke-width: 0px;" class="">In my mind there are two considerations here; balance against the surprise from new developers learning their first programming language versus consistency. In the end even if I believe the behavior is sub-par I would rather it be consistent. Primarily consistency is easier to teach even if it is derived from a standard developed with legacy behavior of C at its heart.</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; -webkit-text-stroke-width: 0px;" class=""><br class=""></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; -webkit-text-stroke-width: 0px;" class="">Perhaps in the future we might want to eventually allow conversions to and from NSNumber via the Integer and FloatingPoint protocols; however I would guess that there needs to be a lot more thought and perhaps some modifications there to pull that off. Not to sound like a broken record, but again that it is out of scope for right now.</div><br class="" 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; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; 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; -webkit-text-stroke-width: 0px;"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><span class="gmail-"><blockquote type="cite" class=""><div class=""><div dir="ltr" class="" style="font-family: helvetica; font-size: 12px; 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 class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class=""></div><div class="">After thinking about it more; it seems reasonable to restrict it to the behavior of Float(exactly: Double(…)). I am certain this will probably in the end cause more bugs for me to have to address and mark as “behaves correctly” and confuse a few new developers - but in the end they chose Swift and the consistent story would be the current behavior of Float(exactly: Double).</div><span class="gmail-m_-8343307845527599891gmail-"><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="" style="font-family: helvetica; font-size: 12px; 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 class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"></div></div></div><span class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Apr 18, 2017 at 11:43 AM, Philippe Hausler<span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:phausler@apple.com" target="_blank" class="">phausler@apple.com</a>></span><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029Apple-converted-space"> </span>w<wbr class="">rote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 18, 2017, at 9:22 AM, Stephen Canon <<a href="mailto:scanon@apple.com" target="_blank" class="">scanon@apple.com</a>> wrote:</div><br class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: helvetica; font-size: 12px; 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 class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-interchange-newline">On Apr 18, 2017, at 12:17 PM, Joe Groff <<a href="mailto:jgroff@apple.com" target="_blank" class="">jgroff@apple.com</a>> wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Apr 17, 2017, at 5:56 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">It seems Float.init(exactly: NSNumber) has not been updated to behave similarly?<br class=""><br class="">I would have to say, I would naively expect "exactly" to behave exactly as it says, exactly. I don't think it should be a synonym for Float(Double(exactly:)).<br class="">On Mon, Apr 17, 2017 at 19:24 Philippe Hausler via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class="">I posted my branch and fixed up the Double case to account for your concerns (with a few inspired unit tests to validate)<br class=""><br class=""><a href="https://github.com/phausler/swift/tree/safe_nsnumber" target="_blank" class="">https://github.com/phausler/sw<wbr class="">ift/tree/safe_nsnumber</a><br class=""><br class="">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.<br class=""></blockquote><br class=""></blockquote></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div></span><div class="">Even with the updated code at <a href="https://github.com/phausler/swift/tree/safe_nsnumber" target="_blank" class="">https://github.com/phausler<wbr class="">/swift/tree/safe_nsnumber</a><span class=""><div class=""><br class=""></div><div class=""><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);">print</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Double</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">(exactly: </span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">NSNumb<wbr class="">er</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">(value: </span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int64</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">90000000000000<wbr class="">00001</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">))) </span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">as</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">Any</span><span class="" style="font-family: menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">)</span></div></span><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">// Optional(9e+18)</span></div><div class=""><br class=""></div><div class="">still succeeds, however the reason seems to be an error in the `init(exactly value: someIntegerType)` inititializers of Float/Double, I have submitted a bug report: <a href="https://bugs.swift.org/browse/SR-4634" target="_blank" class="">https://bugs.swift.org<wbr class="">/browse/SR-4634</a>.</div><div class=""><br class=""></div></div></div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521h5"><div class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" class="" style="font-family: helvetica; font-size: 12px; 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;">(+Steve Canon) What is the behavior of Float.init(exactly: Double)? NSNumber's behavior would ideally be consistent with that.<br class=""></blockquote><br class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">The implementation is essentially just:</span><br class="" style="font-family: helvetica; font-size: 12px; 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 class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-tab-span" style="font-family: helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; word-spacing: 0px;">        </span><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">self.init(other)</span><br class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-tab-span" style="font-family: helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; word-spacing: 0px;">        </span><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">guard Double(self) == other else {</span><br class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-tab-span" style="font-family: helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; word-spacing: 0px;">        </span><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-tab-span" style="font-family: helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; word-spacing: 0px;">        </span><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">return nil</span><br class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="gmail-m_-8343307845527599891gmail-m_7495023967066920029m_2570945702166324521m_-6340981287830468260Apple-tab-span" style="font-family: helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; word-spacing: 0px;">        </span><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">}</span><br class="" style="font-family: helvetica; font-size: 12px; 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 class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">i.e. if the result is not equal to the source when round-tripped back to double (which is always exact), the result is nil.</span><br class="" style="font-family: helvetica; font-size: 12px; 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 class="" style="font-family: helvetica; font-size: 12px; 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;"><span class="" style="font-family: helvetica; font-size: 12px; 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; float: none; display: inline;">– Steve</span></div></blockquote></div><br class=""></div></div><div class="">Pretty much the same trick inside of CFNumber/NSNumber</div></div></blockquote></div></div></div></div></blockquote></span></div></div></blockquote></div></div></div></div></blockquote></span></div></div></blockquote></div></div></div></div></blockquote></span></div></div></blockquote></div></div></blockquote></div></blockquote></div><br class=""></div></blockquote></body></html>