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?
Use the pow
function from math.h
pow(x, 1.0/3.0)
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.
Include math.h
and call pow()
:
pow(twodouble/onedouble,1.0/3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With