Méthode Python math.ldexp()

Python math 模块Module math de Python

Python math.ldexp(x, i)La méthode renvoie x * (2**i),math.frexp()la fonction inverse de.

Version de Python : 2.6

Syntaxe

La syntaxe de la méthode math.ldexp() est la suivante :

math.ldexp(x, i)

Description des paramètres :

  • x-- Obligatoire, un nombre positif ou négatif. Si la valeur n'est pas un nombre, une TypeError est renvoyée.
  • i-- Obligatoire, un nombre positif ou négatif. Si la valeur n'est pas un nombre, une TypeError est renvoyée.

Valeur de retour

Une valeur à virgule flottante, renvoie x * (2**i)

Exemple

L'exemple suivant calcule x * (2**i) :

Exemple

# Importer le package math
import math

# Renvoie x * (2**i)
print(math.ldexp(9, 3))
print(math.ldexp(-5, 2))
print(math.ldexp(15, 2))

Résultat de sortie :

72.0
-20.0
60.0

Python math 模块Module math de Python

Autres extensions