Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python ldexp() Function – Examples & Explanations

Python ldexp() function is a mathematical function. ldexp() returns the result of x * (2**i) which is an inverse of the frexp() function. You have to import math library before you use this function in your Python program.
Following are explanation and examples of this ldexp() function.

Python math.ldexp() Function

math.ldexp() function exists in Standard math Library of Python Programming Language. The purpose function.e of this function is to return a value like x * (2**i).


Python math.ldexp() Syntax

The syntax of math.ldexp() function in python is:
math.ldexp( x,i )



x is any valid Python number (positive or negative).
i is any valid Python number (positive or negative).
Note: if the x,i parameters is not a number, math.ldexp() function will return an TypeError.


Return Value

This function will return the value of x * (2**i)


Python math.ldexp() Function Examples

Output of Python math.ldexp() Function

Note that in output all the numbers (whether they are negative or positive) return value of x * (2**i) by using math.ldexp() function.


LearnAndLearn.com © 2018 - All rights reserved