Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate a logarithm in iOS? [duplicate]

I want to calculate a logarithm in iOS. Can Objective-C do this?

like image 898
Kuldeep Singh Avatar asked Sep 24 '10 05:09

Kuldeep Singh


People also ask

Is there a scientific calculator on iPhone?

In the Calculator app , you can perform basic arithmetic calculations with the standard calculator. Or use the scientific calculator for exponential, logarithmic, and trigonometric functions. Siri: Say something like: “What's 74 times 9?” or “What's 18 percent of 225?” Learn how to use Siri.


2 Answers

You can use the C functions for calculating logarithms

#import <math.h>
double myLog = log(10);

You can also see here: What kind of logarithm functions / methods are available in objective-c / cocoa-touch?

like image 163
Brock Woolf Avatar answered Oct 03 '22 14:10

Brock Woolf


We can use the same math functions which are available in C to do math operations in Objective-C.

I have used the following functions to do mathematical operations. Here the return type of these functions is double and argument should also be of double type... so

double number;

display.text = [NSString stringWithFormat:@"%f" ,log(number)];  
display.text = [NSString stringWithFormat:@"%f" ,log2(number)]; 

display.text = [NSString stringWithFormat:@"%f" ,log10(number)];
display.text = [NSString stringWithFormat:@"%f" ,exp(number)];
like image 24
ram Avatar answered Oct 03 '22 14:10

ram