Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Cube Root in xcode?

Tags:

xcode

iphone

I've been trying to make a specific calculation in xcode with user defined variables. Here's what I have:

-(IBAction)calculate:(id)sender{
    NSString *oneField = self.one.text;
    NSString *twoField = self.two.text;
    double resultInNum;
    double onedouble = [oneField doubleValue];
    double twodouble = [twoField doubleValue];

And what I need to do, is cube root the outcome of

(twodouble/onedouble)

I can't quite find away. Any ideas?

like image 271
Robb Avatar asked Jul 22 '11 04:07

Robb


3 Answers

Use the pow function from math.h

pow(x, 1.0/3.0)
like image 174
Anton Avatar answered Oct 01 '22 08:10

Anton


Swift

Swift has cubic root functions built in. Here are the signatures:

public func cbrt(_: Double) -> Double public func cbrtf(_: Float) -> Float

The definitions are located in Darwin module on OS X and Glibc module on Linux.

like image 38
mklbtz Avatar answered Oct 01 '22 07:10

mklbtz


Include math.h and call pow():

 pow(twodouble/onedouble,1.0/3);
like image 43
Mitch Wheat Avatar answered Oct 01 '22 07:10

Mitch Wheat