I want to calculate a logarithm in iOS. Can Objective-C do this?
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.
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?
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)];
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