Skip to content

Instantly share code, notes, and snippets.

@matthewcheok
Created August 7, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewcheok/33e9e4f24a99f8b31cd4 to your computer and use it in GitHub Desktop.
Save matthewcheok/33e9e4f24a99f8b31cd4 to your computer and use it in GitHub Desktop.
Type promotion
// fill in the blanks with mismatched lhs and rhs types
func +(lhs: Int, rhs: Double) -> Double {
return Double(lhs) + rhs
}
func +(lhs: Double, rhs: Int) -> Double {
return lhs + Double(rhs)
}
func +(lhs: Int, rhs: Float) -> Float {
return Float(lhs) + rhs
}
func +(lhs: Float, rhs: Int) -> Float {
return lhs + Float(rhs)
}
let r = Int(1) + Double(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment