To take the sine of a number in Swift, you can use the built-in sin()
function from the Foundation
module. Here's an example:
main.swift183 chars8 lines
In this example, we first import the Foundation
module. Then we define an angle in degrees (in this case, 45), and convert it to radians using the formula radians = angle * pi / 180
. Finally, we call the sin()
function with the angle in radians as its argument, and save the result to a constant called sine
. We then print the result to the console.
gistlibby LogSnag