Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-25 Thread Haravikk via swift-evolution
> On 25 May 2016, at 16:51, Jeremy Pereira > wrote: >> On 24 May 2016, at 12:33, Haravikk via swift-evolution >> wrote: >>> On 23 May 2016, at 20:19, Dany St-Amant via swift-evolution >>> wrote: >>> >>>

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-25 Thread Jeremy Pereira via swift-evolution
> On 24 May 2016, at 12:33, Haravikk via swift-evolution > wrote: > > >> On 23 May 2016, at 20:19, Dany St-Amant via swift-evolution >> wrote: >> >> Challenge accepted… Removed the if/else if, at the cost of double function >> call to

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-25 Thread Charlie Monroe via swift-evolution
Ok, how about this? The compiler currently crashes when compiling this, but IMHO it is (or should be) valid code. enum IntegerSign: NumberType { case Negative = -1 case Zero = 0 case Positive = 1 var signum: NumberType { return self.rawValue } }

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-24 Thread David Sweeris via swift-evolution
The RawValue is an Int, but signum is a T, which I thought was the point. I tried saying `T: IntegerLiteralConvertible`, and making RawValue = T, but the playground didn’t like that. Maybe with some of Swift 3’s generic enhancements, it could be that simple. In any case, it sounds like this

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-24 Thread Charlie Monroe via swift-evolution
Yes, but here, the rawValue is Int - in my code, the rawValue is NumberType, which IMHO makes more sense... > On May 24, 2016, at 7:36 AM, David Sweeris wrote: > > Sorry, I misspoke. I just meant define it like this: > public enum IntegerSign : Int { > case Negative =

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-23 Thread David Sweeris via swift-evolution
Sorry, I misspoke. I just meant define it like this: public enum IntegerSign : Int { case Negative = -1 case Zero = 0 case Positive = 1 public var signum: T { return T(self.rawValue.toIntMax()) } } Although, come to think of it, I’m not sure if that’s an exact drop-in

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-23 Thread Charlie Monroe via swift-evolution
Sure, that's a good idea, though I'd personally use the signum var, since using rawValue seems like a bit of an abuse of the fact the enum is defined this way and doesn't help readability of the code: enum IntegerSign: RawRepresentable { case Negative case Zero case Positive

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-23 Thread David Sweeris via swift-evolution
Can we make it RawRepresentable? That way signum can just return self.rawValue Sent from my iPhone > On May 23, 2016, at 06:05, Charlie Monroe via swift-evolution > wrote: > > The clean way would be to make it an enum with var signum that would return > -1, 0, 1: >

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-23 Thread Dany St-Amant via swift-evolution
> Le 22 mai 2016 à 03:07, Adam Nemecek via swift-evolution > a écrit : > > Howdy, > I think that the SignedNumberType should implement a method called sign that > will return -1 for negative numbers, 0 for 0 and 1 for positive numbers. This > is similar to the

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-23 Thread Charlie Monroe via swift-evolution
The clean way would be to make it an enum with var signum that would return -1, 0, 1: enum IntegerSign { case Negative case Zero case Positive var signum: NumberType { switch self { case .Negative: return -1 as NumberType case .Zero:

Re: [swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-22 Thread Adrian Zubarev via swift-evolution
Whoops didn’t check that your example worked as well :D --  Adrian Zubarev Sent with Airmail Am 22. Mai 2016 bei 10:27:17, Adrian Zubarev (adrian.zuba...@devandartist.com) schrieb: This should do the trick: extension SignedNumberType { var sign: Self { if self

[swift-evolution] [Pitch] Add the sign method to the SignedNumberType protocol.

2016-05-22 Thread Adam Nemecek via swift-evolution
Howdy, I think that the SignedNumberType should implement a method called sign that will return -1 for negative numbers, 0 for 0 and 1 for positive numbers. This is similar to the signum method in e.g. Java and similarly called methods in other languages. The implementation is fairly straight