A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/python/python_math_frexp_method.htm below:

Python math.frexp() Method

Python math.frexp() Method

The Python math.frexp() method is used to decompose a floating-point number into its normalized fraction and exponent.

Mathematically, for a non-zero floating-point number x, it can be represented as −

x = m × 2e

Where, "m" is the normalized fraction and "e" is the exponent.

Syntax

Following is the basic syntax of the Python math.frexp() method −

math.frexp(x)
Parameters

This method accepts a numeric value as a parameter representing the floating-point number that you want to decompose.

Return Value

The method returns a tuple "(m, e)", where "m" is a float representing the normalized fraction and "e" is an integer representing the exponent.

The fraction "m" satisfies the condition "0.5 <= abs(m) < 1.0", and "x" is approximately equal to "m * 2**e". If "x" is zero, both "m" and "e" are zero. If "x" is a NaN or infinite, both "m" and "e" are NaN or infinite.

Example 1

In the following example, we are calculating the mantissa and exponent of the floating-point number 10 using the frexp() method −

import math
mantissa, exponent = math.frexp(10)
print("The result obtained is:",mantissa, exponent) 
Output

The output obtained is as follows −

The result obtained is: 0.625 4
Example 2

Here, we are calculating the mantissa and exponent of the negative floating-point number "-5" −

import math
mantissa, exponent = math.frexp(-5)
print("The result obtained is:",mantissa, exponent) 
Output

Following is the output of the above code −

The result obtained is: -0.625 3
Example 3

Now, we calculate the mantissa and exponent of a fractional number using the frexp() method −

import math
mantissa, exponent = math.frexp(0.75)
print("The result obtained is:",mantissa, exponent)  
Output

We get the output as shown below −

The result obtained is: 0.75 0
Example 4

In this example, we calculate the mantissa and exponent of the floating-point number 0. Since 0 has no magnitude, both the mantissa and exponent are 0 −

import math
mantissa, exponent = math.frexp(0)
print("The result obtained is:",mantissa, exponent)  
Output

The result produced is as shown below −

The result obtained is: 0.0 0

python_maths.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4