Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-26 Thread Philippe Hausler via swift-evolution
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) Sent from my iPhone > On Apr 20, 2017, at 11:29 AM, Martin R wrote: > > So is it correct to say that for all types T which NSNumber can hold

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-20 Thread Martin R via swift-evolution
So is it correct to say that for all types T which NSNumber can hold (Double, Float, Int, UInt, ... ) T(exactly: someNSNumber) will succeed if and only if NSNumber(value: T(truncating: someNSNumber)) == someNSNumber holds? > On 20. Apr 2017, at 18:10, Philippe Hausler

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-20 Thread Xiaodi Wu via swift-evolution
Right. I think we're in vigorous agreement. On Thu, Apr 20, 2017 at 11:11 Philippe Hausler wrote: > On Apr 19, 2017, at 6:09 PM, Xiaodi Wu wrote: > > > > On Wed, Apr 19, 2017 at 6:35 PM, Philippe Hausler > wrote: > >> >> >> On Apr

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-20 Thread Philippe Hausler via swift-evolution
> On Apr 19, 2017, at 6:09 PM, Xiaodi Wu wrote: > > > > On Wed, Apr 19, 2017 at 6:35 PM, Philippe Hausler > wrote: > > >> On Apr 19, 2017, at 16:17, Xiaodi Wu > > wrote:

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-19 Thread Xiaodi Wu via swift-evolution
On Wed, Apr 19, 2017 at 6:35 PM, Philippe Hausler wrote: > > > On Apr 19, 2017, at 16:17, Xiaodi Wu wrote: > > On Wed, Apr 19, 2017 at 6:00 PM, Philippe Hausler w > rote: > >> >> On Apr 19, 2017, at 3:23 PM, Xiaodi Wu

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-19 Thread Philippe Hausler via swift-evolution
> On Apr 19, 2017, at 16:17, Xiaodi Wu wrote: > > On Wed, Apr 19, 2017 at 6:00 PM, Philippe Hausler > wrote: > >> On Apr 19, 2017, at 3:23 PM, Xiaodi Wu > > wrote: >> >>

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-19 Thread Xiaodi Wu via swift-evolution
On Wed, Apr 19, 2017 at 6:00 PM, Philippe Hausler wrote: > > On Apr 19, 2017, at 3:23 PM, Xiaodi Wu wrote: > > On Wed, Apr 19, 2017 at 3:19 PM, Martin R wrote: > >> On 19. Apr 2017, at 01:48, Xiaodi Wu wrote:

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-19 Thread Philippe Hausler via swift-evolution
> On Apr 19, 2017, at 3:23 PM, Xiaodi Wu wrote: > > On Wed, Apr 19, 2017 at 3:19 PM, Martin R > wrote: >> On 19. Apr 2017, at 01:48, Xiaodi Wu > > wrote: >> >> So, as I

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-19 Thread Xiaodi Wu via swift-evolution
On Wed, Apr 19, 2017 at 3:19 PM, Martin R wrote: > On 19. Apr 2017, at 01:48, Xiaodi Wu wrote: > > 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

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-19 Thread Martin R via swift-evolution
> On 19. Apr 2017, at 01:48, Xiaodi Wu wrote: > > 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

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-18 Thread Xiaodi Wu via swift-evolution
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. On Tue, Apr 18, 2017 at 11:43 AM, Philippe Hausler

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-18 Thread Philippe Hausler via swift-evolution
> On Apr 18, 2017, at 9:22 AM, Stephen Canon wrote: > >> >> On Apr 18, 2017, at 12:17 PM, Joe Groff wrote: >> >> >>> On Apr 17, 2017, at 5:56 PM, Xiaodi Wu via swift-evolution >>> wrote: >>> >>> It seems Float.init(exactly:

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-18 Thread Stephen Canon via swift-evolution
> On Apr 18, 2017, at 12:17 PM, Joe Groff wrote: > > >> On Apr 17, 2017, at 5:56 PM, Xiaodi Wu via swift-evolution >> wrote: >> >> It seems Float.init(exactly: NSNumber) has not been updated to behave >> similarly? >> >> I would have to say, I

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-18 Thread Joe Groff via swift-evolution
> On Apr 17, 2017, at 5:56 PM, Xiaodi Wu via swift-evolution > wrote: > > It seems Float.init(exactly: NSNumber) has not been updated to behave > similarly? > > I would have to say, I would naively expect "exactly" to behave exactly as it > says, exactly. I don't

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-18 Thread Philippe Hausler via swift-evolution
The unit tests seem to show that is not needed due to the internal implementation of NSNumber. > On Apr 17, 2017, at 17:56, Xiaodi Wu wrote: > > It seems Float.init(exactly: NSNumber) has not been updated to behave > similarly? > > I would have to say, I would naively

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-17 Thread Xiaodi Wu via swift-evolution
It seems Float.init(exactly: NSNumber) has not been updated to behave similarly? 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:)). On Mon, Apr 17, 2017 at 19:24 Philippe Hausler via

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-17 Thread Philippe Hausler via swift-evolution
I posted my branch and fixed up the Double case to account for your concerns (with a few inspired unit tests to validate) https://github.com/phausler/swift/tree/safe_nsnumber There is a builtin assumption here though: it does presume that

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-16 Thread Martin R via swift-evolution
> On 15. Apr 2017, at 22:12, Philippe Hausler wrote: > > > >> On Apr 14, 2017, at 22:51, Martin R > > wrote: >> >> Thank you for the response, but I have more questions. Will >> >> Float(exactly: NSNumber(value:

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-15 Thread Philippe Hausler via swift-evolution
> On Apr 14, 2017, at 22:51, Martin R wrote: > > Thank you for the response, but I have more questions. Will > > Float(exactly: NSNumber(value: Double.pi)) This will succeed in that the value is representable without loosing mantissa > > fail because Float

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-14 Thread Martin R via swift-evolution
Thank you for the response, but I have more questions. Will Float(exactly: NSNumber(value: Double.pi)) fail because Float cannot represent the number Double.pi exactly? Or Double(exactly: NSDecimalNumber(string: "1.9")) because Double cannot represent the decimal fraction 1.9

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-14 Thread Matthew Johnson via swift-evolution
> > • What is your evaluation of the proposal? +1. I have run into problems with the current behavior a few times. This proposal brings the behavior in-line with what I believe is best. > • Is the problem being addressed significant enough to warrant a change > to Swift? Yes.

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-14 Thread Philippe Hausler via swift-evolution
> On Apr 14, 2017, at 2:11 PM, Martin R via swift-evolution > wrote: > > Apologies if I am overlooking something, but it seems to me that the proposal > does not clearly define the behavior of the "exact" conversions between > integer and floating point values.

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-14 Thread Martin R via swift-evolution
Apologies if I am overlooking something, but it seems to me that the proposal does not clearly define the behavior of the "exact" conversions between integer and floating point values. Does Int(exactly: NSNumber(value: 12.34)) fail because Int cannot represent the number exactly? Or are

Re: [swift-evolution] SE-0170: NSNumber bridging and Numeric types

2017-04-14 Thread Ben Cohen via swift-evolution
Apologies, if you are reading this in HTML the links appear to be pointing to the incorrect proposal. Here is the corrected link: https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md > On Apr 14, 2017, at 11:30 AM, Ben Cohen wrote: > >