>From some older evolution-thread:
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 with Airmail
Am 20. November 2016 um 03:44:04, Rick Mann via swift-users
([email protected](mailto:[email protected])) schrieb:
>
> I'm trying to do this:
>
> protocol Signumable
> {
> func sgn() -> Self
> }
>
> extension Signumable
> {
> func
> sgn()
> -> Self
> {
> let pos = 0 < self // Error
> let neg = self < 0 // Error
> let p = pos ? Self(1) : Self(0)
> let n = neg ? Self(1) : Self(0)
> return p - n
> }
> }
>
>
> extension Double : Signumable {}
>
> But I get
>
> Binary operator '<' cannot be applied to operands of type 'Int' and 'Self'
>
> I figure there should be additional constraints on Signumable.
>
> Help would be much appreciated!
>
>
> --
> Rick Mann
> [email protected]
>
>
> _______________________________________________
> swift-users mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution