Section courante

A propos

Section administrative du site

LOG

Logarithme
MySQL  

Syntaxe

Log([base,]Nombre)

Paramètres

Nom Description
base Ce paramètre permet d'indiquer en quel base est effectué le logarithme
Nombre Ce paramètre permet d'indiquer une expression représentant un nombre à traiter

Description

Cette fonction retourne le logarithme naturel (base e).

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 permet d'afficher les logarithmes inférieurs à 2 :

  1. DROP PROCEDURE IF EXISTS WHILELOG;
  2. CREATE PROCEDURE WHILELOG()
  3. BEGIN
  4. DECLARE R DOUBLE  DEFAULT 0.0;
  5. WHILE R < 2 DO
  6. SELECT CONCAT("Log(",R,")=",log(R));
  7.         SET R = R + 0.1;
  8. END WHILE;
  9. END;
  10.  
  11. CALL WHILELOG();

on obtiendra le résultat suivant :

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| NULL |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.1)=-2.30258509299405 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.2)=-1.6094379124341 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.3)=-1.20397280432594 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.4)=-0.916290731874155 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.5)=-0.693147180559945 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.6)=-0.510825623765991 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.7)=-0.356674943938732 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.8)=-0.22314355131421 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(0.9)=-0.105360515657826 |
+------------------------------+

+-------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+-------------------------------+
| Log(1)=-1.11022302462516e-016 |
+-------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.1)=0.0953101798043247 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.2)=0.182321556793955 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.3)=0.262364264467491 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.4)=0.336472236621213 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.5)=0.405465108108165 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.6)=0.470003629245736 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.7)=0.530628251062171 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.8)=0.587786664902119 |
+------------------------------+

+------------------------------+
| CONCAT("Log(",R,")=",log(R)) |
+------------------------------+
| Log(1.9)=0.641853886172395 |
+------------------------------+

Voir également

Article - Les géants de l'informatique - Oracle

Références

MySQL - Référence, Edition Micro Application, Nicolas Rivereau, Antoine Pichot, 2002, ISBN: 2-7429-2560-0, page 927.
MySQL: The definitive guide to using, programming, and administering MySQL 4 databases - Second Edition, Paul Dubois, 2003, ISBN: 0-7357-1212-3, page 805

Dernière mise à jour : Mercredi, le 29 avril 2015