How would a programmer like m开发者_运维技巧yself learn how to find an inverse exponential of a number? on my calculator 2nd LN or e^x. It is similar in concept to the neperien function on calculator e.g. the log of 2 is about 0.3 and the inverse log or 10^x of 0.3 is 2.)
Note: This is to be used within an iPhone project using iPhone SDK
Note: Here is an example of what I am needing to compute: then 0.91831 is raised to the power of the inverse exponential of .773848284, or, 0.91831^2.168332164 = 0.831282.
It's not clear what you mean by "inverse exponential", but I'm going to list all of the potentially relevant math library functions and hopefully you can figure out which one you actually need.
exp(x)
returnse^x
(wheree
is the base of the natural logarithm, 2.71828...).exp2(x)
returns2^x
.log(x)
returns the natural logarithm ofx
(the numbera
that satisfiese^a = x
).log2(x)
returns the base-2 logarithm ofx
.log10(x)
returns the base-10 logarithm ofx
.pow(x,y)
returns x^y.
All of these functions are available on the iPhone. In order to get the prototypes, you will need to include the header that defines them. Add the line #include <math.h>
to the beginning of your source file to do so.
If you need a more precise explanation of exactly what any of these functions do, or examples of their use, let me know.
It's the exp
function in <math.h>
. Or if you're looking for ln(x), use the log function in math.h
with log(number)
.
double pow(double x, double y);
The
pow()
function returns the value of x raised to the power of y.
double exp(double x);
The
exp()
function returns the value of e (the base of natural logarithms) raised to the power of x.
So you want
pow(0.91831, exp(.773848284));
Simple answer: use the log() function from <math.h>. Or are you interested in an algorithm to compute it yourself?
Well, I haven't fully understood if you want to find the log or the exp. If don't want to use C's math library, you can write your own functions using a series expansion for approximation (for both functions).
You can find the general idea for Taylor series here.
For efficient log series you could read the "Series for calculating the natural logarithm" section here.
man exp
man log
精彩评论