> 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:
>>>
>>> Challenge accepted… Removed the if/else if, at the cost of double function
>>> call to
> 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 a tri-op:
>>
>> extension Bool {
>> func as01() ->
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
}
}
extensi
That depends... Does “x = a ? b : c” and "if a {x = b} else {x = c}” compile
down to the same machine code? I know of one arch where “?:” takes 0 cycles,
but I don’t know if there’s a difference on x86 or ARM.
Either way, I’d think that just doing the comparison within `sign` would be
faster, s
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 mig
> 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 a tri-op:
>
> extension Bool {
> func as01() -> T { return self ? 1 : 0 }
> }
>
> extension SignedNumberType {
> var sign: S
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 = -1
> case Zero = 0
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
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
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:
>
> enum IntegerSign {
>
>
> 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 signum method in e.g. Java and s
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:
Oh and also machine learning. Search for sign or signum and machine
learning, you'll find a lot of results.
On Mon, May 23, 2016 at 1:26 AM, Adam Nemecek wrote:
> It's not for branching based on the value, it's for calculating
> mathematical functions with the sign retrieved from the value. So f
It's not for branching based on the value, it's for calculating
mathematical functions with the sign retrieved from the value. So for the
same reason, no it should not be an enum. It should be the same type as the
type it's called on. It's that way in Haskell as well
http://hackage.haskell.org/pac
Could you give an example of this method’s usage? Surely your value is either
positive, negative or zero already, so this method doesn’t return anything more
useful.
In other words, anywhere that I might do this:
if myValue.sign > 0 { … }
I could just as easily do:
if myValue
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 =
This should do the trick:
extension SignedNumberType {
var sign: Self {
if self == (0 as Self) {
return (0 as Self)
} else if self > (0 as Self) {
return (1 as Self)
}
return (-1 as Self)
}
}
--
Adrian Zubarev
Sent
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 forw
18 matches
Mail list logo