Math Functions in Swift

Hi,

Is there math functions in Swift built in, such as Sin, Cos, Log etc ?

Kindest Regards

Answered by ssmith_c in 767337022

not in the language itself. There are trigonometric functions in the CoreGraphics framework.

Accepted Answer

not in the language itself. There are trigonometric functions in the CoreGraphics framework.

This works directly in SwiftUI or playground or UIKit app as well:

let x = sin(.pi / 6)

Yes.

Just create a new project in SwiftUI:

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world! \(sin(Float.pi/3))")
        }
        .padding()
    }
}

And get this:

Thanks allot

Math Functions in Swift
 
 
Q