Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Pelle Gelderblom
Pelle Gelderblom
4,517 Points

Math in swift

How can I get math functions in swift, like Square root, cosine, sine and Pi or round a decimal down to a whole number? And how can I doing this in swift: 2 ^ 3 = 8

Rob Parmenter
Rob Parmenter
5,641 Points

I'm not familiar with math functions beyond basic operators. A quick search in the documentation in Swift should help. I searched arithmetic and it brought up various search terms. It did bring up the NSDecimalNumber class and various other terms. Everything else is beyond my capability! I hope this helped in any way.

1 Answer

Swift Operators by NSHipster here

prefix operator  {}
prefix func  (number: Double) -> Double {
    return sqrt(number)