Mathematical functions in Swift

后端 未结 6 2301
花落未央
花落未央 2020-11-30 23:04

How do I use mathematical functions like sqrt(), floor(), round(), sin(), etc?


When doing:

         


        
6条回答
  •  执笔经年
    2020-12-01 00:00

    You can use them right inline:

    var square = 9.4
    var floored = floor(square)
    var root = sqrt(floored)
    
    println("Starting with \(square), we rounded down to \(floored), then took the square root to end up with \(root)")
    

提交回复
热议问题