How Can You Use Ln Function in C Programing?

Header file math.h is for mathematical functions like cos,sin, tan.. But how to write the ln function and not log?

7

3 Answers

The C function log is the natural logarithm, which mathematicians usually write as "ln".

The C function log10 is the logarithm base 10, which is sometimes written "log".

Remember math at school: logA_B = logA_C/logB_C

double ln(double x) { return log(x); }

Or in a pinch

#define ln(x) log(x)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest