Python | ldexp() function Last Updated : 14 Feb, 2023 Comments Improve Suggest changes Like Article Like Report ldexp() function is one of the Standard math library function in Python, which returns x * (2**i). This is also called as inverse of Python frexp() function. Syntax: math.ldexp(x, i) Parameters: x : Any valid number (+ve or -ve) i : Any valid number (+ve or -ve) Returns : Returns the value of x * (2**i). Time Complexity: O(1) Auxiliary Space: O(1) For example, if x = 3 and i = 4 then, Math.ldexp(3, 4) = 3*16 = 48. Code #1: Python3 # Python3 code demonstrate ldexp() function # importing math library import math # ldexp() Function on +ve nd -ve Numbers print(math.ldexp(9, 3)) print(math.ldexp(-5, 2)) # ldexp() Function on fractional Number print(math.ldexp(3.5, 2)) print('%.2f' %math.ldexp(-6.8, 3)) Output: 72.0 -20.0 14.0 -54.40 Code #2: Python3 # Python3 code demonstrate ldexp() function # importing math library import math # Tuple Declaration tpl = (9, -5, 3.5, -6.8) # List Declaration lst = [13, 4, 8.4, -6.7] # ldexp() Function on +ve nd -ve Numbers print(math.ldexp(tpl[0], 3)) print(math.ldexp(tpl[3], 2)) # ldexp() Function on fractional Number print(math.ldexp(lst[1], 2)) print('%.2f' %math.ldexp(lst[2], 3)) Output: 72.0 -27.2 16.0 67.20 Code #3: If the X value or i value argument is not a number, ldexp() function will return TypeError. Python3 # Python3 code demonstrates when error occurs # importing the math library import math # string value taken print(math.ldexp('25', 5)) print(math.ldexp(25, '5')) Output: TypeError: a float is required TypeError: a float is required Comment More infoAdvertise with us J jana_sayantan Follow Improve Article Tags : Python Python-Library Python-Built-in-functions Python math-library Python math-library-functions +1 More Practice Tags : python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 6 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 6 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like