[swift-evolution] [swift-users] Implementing signum
Jacob Bandes-Storch
jtbandes at gmail.com
Sun Nov 20 02:09:19 CST 2016
On Sat, Nov 19, 2016 at 11:59 PM, Adrian Zubarev via swift-evolution <
swift-evolution at swift.org> wrote:
> 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
>
Just played with this and it turns out that due to the implicit nature of
IntegerLiteralConvertible, you don't need any of the "as Self"s:
extension SignedNumber{
var sign: Self {
if self == 0 {
return 0
} else if self > 0 {
return 1
}
return -1
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161120/70dead26/attachment.html>
More information about the swift-evolution
mailing list