Section courante

A propos

Section administrative du site

LOG

Logarithme
Langage C math.h

Syntaxe

double log(double n);

Paramètres

Nom Description
n Ce paramètre permet d'indiquer l'expression contenant le nombre à traiter

Description

Cette fonction retourne le logarithme naturel ou népérien.

Algorithme

MODULE SQRT(X)
   SI X = 0.0 ALORS
      RETOURNE 0.0
   SINON
      M ← 1.0
      XNX
      BOUCLE FAIRE TANT QUE XN >= 2.0
         XN ← 0.25 x XN
         M ← 2.0 x M
      FIN BOUCLE FAIRE TANT QUE
      BOUCLE FAIRE TANT QUE XN < 0.5
         XN ← 4.0 x XN
         M ← 0.5 x M
      FIN BOUCLE FAIRE TANT QUE
      AXN
      B ← 1.0 - XN
      BOUCLE REPETER
         AA x (1.0 + 0.5 x B)
         B ← 0.25 x (3.0 + B) x B x B
      FIN BOUCLE JUSQU'A B ← 1.0E - 15
      RETOURNE A x M
   FIN SI

MODULE LOG(x)
   negatif ← faux
   fois ← 1
   ajout ← 0
   SI x <= 0.0 ALORS
      RETOURNE 0
   FIN SI
   SI x < 1.0 ALORS
      negatif ← vrai
      x ← 1.0 / x
   FIN SI
   BOUCLE FAIRE TANT QUE x >= 10.0
      xx / 10.0
      ajoutajout + 2.302585092994046
   FIN BOUCLE FAIRE TANT QUE
   BOUCLE FAIRE TANT QUE x >= 1.1
      x ← SQRT(x)
      foisfois x 2
   FIN BOUCLE FAIRE TANT QUE
   xx - 1
   savxx
   i ← 2
   xpx x x
   quotient ← (xp / i)
   dlx - quotient
   BOUCLE FAIRE TANT QUE 1.0E-15 ← quotient
      ii + 1
      xpxp x x
      dldl + (xp / i)
      ii + 1
      xpxp x x
      quotient ← (xp / i)
      dldl - quotient
   FIN BOUCLE FAIRE TANT QUE
   dldl x fois
   dldl + ajout
   SI negatif ALORS
      dl ← -dl
   FIN SI
   RETOURNE dl

Exemple

Voici un exemple permettant d'afficher le logarithme inférieurs à 2 :

Essayer maintenant !
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     float I;
  8.     for(I = 0.1; I <= 2.0;I += 0.1) {
  9.         printf("LOG(%f)=%f\n",I,log(I));
  10.     }
  11.     return 0;
  12. }

on obtiendra le résultat suivant :

LOG(0.100000)=-2.302585
LOG(0.200000)=-1.609438
LOG(0.300000)=-1.203973
LOG(0.400000)=-0.916291
LOG(0.500000)=-0.693147
LOG(0.600000)=-0.510826
LOG(0.700000)=-0.356675
LOG(0.800000)=-0.223143
LOG(0.900000)=-0.105360
LOG(1.000000)=0.000000
LOG(1.100000)=0.095310
LOG(1.200000)=0.182322
LOG(1.300000)=0.262364
LOG(1.400000)=0.336472
LOG(1.500000)=0.405465
LOG(1.600000)=0.470004
LOG(1.700000)=0.530628
LOG(1.800000)=0.587787
LOG(1.900000)=0.641854

Voir également

Langage de programmation - C - Référence de procédures et fonctions - exp
Langage de programmation - C - Référence de procédures et fonctions - pow
Langage de programmation - C - Référence de procédures et fonctions - sqrt
Langage de programmation - C++ - Référence de procédures et fonctions - log

Références

Langage C, Edition Micro-Application, Gehard Willms, 2001, ISBN: 2-7429-2008-0, page 733.
Borland C++ for Windows 4.0, Library Reference, Edition Borland, 1993, Part # BCP1240WW21772, page 162.

Dernière mise à jour : Mardi, le 28 juillet 2015