Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

# What is math.ldexp(x, i) in Python? Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The math.ldexp() method is used to compute the expression x * (2**i).

ldexp() is the inverse function of frexp().

The frexp() method takes one argument and returns mantissa m and exponent e as a tuple (m,e).

### Syntax

math.ldexp(x, i)


### Parameters

ldexp takes two signed numbers as parameters:

• x (float value): the first argument is basically mantissa m.
• i (integer value): the second argument is basically exponent e.

To understand this concept, learn about the frexp() method first.

### Return value

This method calculates and returns the value of this expression: x * (2**i).

### Example

In the code snippet below, we pass two arguments to the math.ldexp() method, which returns the result of x * (2**i) on different argument values.

# Load maths module
import math
x=2
i=4
# demo examples
print(math.ldexp(x, i))
print(math.ldexp(8, 4))
print(math.ldexp(12, -3))
print(math.ldexp(-7, 2))

RELATED TAGS

python
communitycreator

CONTRIBUTOR Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 