mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Implemented math.h
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include <math.h>
|
||||
|
||||
#define _LOG_TERMS 20
|
||||
|
||||
double log(double x) {
|
||||
if (x <= 0.0) return -INFINITY;
|
||||
|
||||
double result = 0.0;
|
||||
double term = (x - 1.0) / (x + 1.0);
|
||||
double termSquared = term*term;
|
||||
double numerator = term;
|
||||
|
||||
for (int i = 1; i < _LOG_TERMS; i++) {
|
||||
result += numerator / (double)i;
|
||||
numerator *= termSquared;
|
||||
}
|
||||
|
||||
return 2.0 * result;
|
||||
}
|
||||
|
||||
double log2(double x) {
|
||||
if (x <= 0.0) return -INFINITY;
|
||||
return log(x) / M_LN2;
|
||||
}
|
||||
|
||||
double log10(double x) {
|
||||
if (x <= 0.0) return -INFINITY;
|
||||
return log(x) / M_LN10;
|
||||
}
|
||||
|
||||
double logn(double x, double n) {
|
||||
if (x <= 0.0) return -INFINITY;
|
||||
return log(x) / log(n);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user