Home » C++ Math frexp() Function

C++ Math frexp() Function

by Online Tutorials Library

C++ Math frexp()

This function breaks the floating point number into the binary significand and an integral exponent.

Let the floating point number be x then,

x = (significand)*2e

where, ‘e’ is the exponent and ‘significand’ is the binary significand

Syntax

Suppose a floating point number be ‘x’ and pointer be ‘exp’:

Parameter

x: The value which is to be decomposed into the binary significand.

exp: It is a pointer to an int, where the value of exponent is stored.

Return value

It returns the binary significand which is the absolute value lies between 0.5(included) and 1(excluded).

Parameter Significand exponent
x=0 zero zero
x>=1 positive number positive number
x>= -1 negative number positive number
-1<x<0 negative number negative number
0<x<1 positive number negative number

Example 1

Let’s see a simple example when the value of x is greater than 1.

Output:

Value of x is : 2  2=0.5 * 2^2  

In this example, frexp() function calculates the binary significand of a floating point number when the value of x is greater than 1.

Example 2

Let’s see a simple example when the value of x is zero

Output:

Value of x is : 0  0=0 * 2^0  

In this example, frexp() function calculates the binary significand of a floating point number when the value of x is zero.

Example 3

Let’s see a simple example when the value of x lies between 0 and 1.

Output:

Value of x is : 0.4  0.4=0.8 * 2^-1  

In this example, frexp() function calculates the binary significand of a floating point number when the value of x lies between 0 and 1.

Example 4

Let’s see a simple example when the value of x lies between -1 and 0.

Output:

Value of x is : -0.1  -0.1=-0.8 * 2^-3  

In this example, frexp() function calculates the binary significand of a floating point number when the value of x lies between -1 and 0.

Example 5

Let’s see the simple example when the value of x is less than -1.

Output:

Value of x is : -5  -5=-0.625 * 2^3  

In this example, frexp() function calculates the binary significand of a floating point nmber when the value of x is less than -1.

Next TopicC++ Math Functions

You may also like