Explanation:
Step 1: Import the Math Module
import math
- The math module provides mathematical functions in Python.
- It includes functions for calculations involving powers, logarithms, square roots, and more.
Step 2: Use the math.ldexp() Function
print(math.ldexp(1.5, 3))
- ldexp() takes two arguments:
- First argument: 1.5 (floating-point number).
- Second argument: 3 (power of 2).
- It calculates the following:
\[
\text{ldexp}(x, i) = x \times 2^i
\]
Substitute the values:
\[
1.5 \times 2^3
\]
\[
1.5 \times 8 = 12.0
\]
3. Final Output
Output: 12.0
12.0
.png)

0 Comments:
Post a Comment