1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <stdio.h>
#include <stdlib.h>
# include <math.h>
double f(double x)
{
return 1/x;
}
double integrale_trapezes (double a, double b, int n, double f(double))
{
double h=(b-a)/n;
int i;
double s;
for (i=0,s=0;i<n;s+=h*(f(a+i*h)+f(a+(i++)*h))/2);
return s;
}
int pow2_exp(double x)
{
int n;
for (n=0;x>2;x=x/2,n++);
return n;
}
double pow2_mant(double x)
{
while (x>2)
x/=2;
return x;
}
double monlog_entre_1_et_2(double x)
{
return integrale_trapezes(1,x,1000000,f);
}
double monlog_plus_grand_que_2(double x)
{
return pow2_exp(x)*monlog_entre_1_et_2(2)+monlog_entre_1_et_2(pow2_mant(x));
}
double monlog_plus_grand_que_1(double x)
{
if (x<=2) return monlog_entre_1_et_2(x);
else
return monlog_plus_grand_que_2(x);
}
double monlog_plus_petit_que_1(double x)
{
if (x>=1) return monlog_plus_grand_que_1(x);
else
return -monlog_plus_grand_que_1(1/x);
}
double monlog(double x)
{
if (x<1) return monlog_plus_petit_que_1(x);
else return monlog_plus_grand_que_1(x);
}
int main()
{
printf("%lf\n",monlog(0.1));
printf("%lf\n",log(0.1));
printf("%lf\n",monlog(0.5));
printf("%lf\n",log(0.5));
printf("%lf\n",monlog(1));
printf("%lf\n",log(1));
printf("%lf\n",monlog(1.5));
printf("%lf\n",log(1.5));
printf("%lf\n",monlog(2));
printf("%lf\n",log(2));
printf("%lf\n",monlog(10));
printf("%lf\n",log(10));
printf("%lf\n",monlog(1000));
printf("%lf\n",log(1000));
return 0;
} |
Partager