This question I have didn't fully help me, although it gave me a few details.
My current based code:
#define e 2.7182818284590452353602874713527
double logarithm(long double dec) {
// return log10f(dec);
return result;
}
What I learned from the linked question:
- Logarithmic functions use e as base. Stated by the accepted answer.
- Also by the accepted answer,
^
is not for exponents (and I'm planning on making this syntax an exponential form, which might mean abandoning thepower()
function), rather it's an XOR operator. - Someone answered my question but got deleted. It is about the
log10f
source code, but it's kinda confusing, so not worth it for me.
Now the criteria I have for this function is that it is made from scratch, no multiple functions, and make it a simple sort (even though I doubt that logarithm isn't even simple).
The answer's code:
#include <math.h>
float log_num(int num) {
return log10f(num);
}
Yes, fairly simple, but as a challenge, I want to not use the log()
functions themselves though I'm still relying on <math.h>
's functions.
Question: What's a simple form of making a logarithm function in scratch without the built-in logarithm functions? If without using <math.h>
, then how is that?