# Thread: Implementation of the math.h libary

1. ## Implementation of the math.h libary

Hello I would like to know how to implement the "ln" function in the math.h libary. I would like to implement the equation ln(a^2-d/2a) I would appriciate any help that anyone give me.

2. Code:
```double foo(double a, double d)
{
return log(exp(a * a) - d / (2 * a));
}```
?

3. ## Having problems implementing

Hello thanks for that but i'am still having problems implementing it. I want to implement the equation ln((8*L-1)/D) the code below is what i have that is not working

Code:
`	b=log(exp((8*L)-1/ D));`

4. Learn about the change of base rule

Quick tip: ((8*L-1)/D), as stated in your question, is not the same as ((8*L)-1/ D)

Another quick tip: stick to one equation, as you have now posted 3 different
equations.

5. All you need to know is basic math to figure out this one. * before / before + before -

Thus, if you removed all of the parenthesis, and just relied on basic math properties, you would get:

A = 8 * L resolved first.
B = 1 / D resolved next.
C = A - B resolved last.

This is why we have the phrase, "When in doubt, use lots of parenthesis!" Or something to that effect.

Quzah.

6. Studying an operator precedence table might help: http://www.isthe.com/chongo/tech/com...recedence.html

7. ## Still not working

I corrected my mistake but the problem now is that the ln function which I wrote as log(exp) is not giving me a proper value I checked it

b=log(exp((8*L-1)/D));

if L=3
D=7

I will be very greatful if someone can help me.

8. Do I have to do everything for you? I already posted a link for you to look
at the change of base rule. By applying that, using log () - which is base 10,
to get a result in ln you do this:

Code:
```#include <stdio.h>
#include <math.h>

int main (void)
{
double b, L = 3, D = 7;

b=(log((8*L-1)/D))/(log (exp (1.0)));

printf ("b is %f", b);

return 0;
}```
Now go away.

9. Originally Posted by Richie T
log () - which is base 10
Hmm?
The log functions compute the base-e (natural) logarithm of x.
The log10 functions compute the base-10 (common) logarithm of x.

10. Oops! My mistake, should have looked that up before I submitted, nonetheless
the code I posted gives the right answer since it ends up dividing by 1!