# frexp() in C++

The frexp() function breaks the floating point number x into its binary significand i., e., floating point with an absolute value between [0.5, 1.0) and an integral exponent for 2.

x = significand * (2^exponent).

It used to :

```1. It is used to find significand which is always between 0.5 and 1.0
2. It is used to find exponent which is power of 2.
```

Syntax:

```double frexp (double x);
float frexp (float x);
long double frexp (long double x);
```

Parameter:

• The frexp() function takes a single argument.
• Return:

• The frexp() function returns the binary significand whose absolute value lies in the interval [0.5, 1).
• If x is zero, both significand and exponent are zero.

Error and Exception:

1. It is mandatory to give both the arguments otherwise it will give error no matching function for call to ‘frexp()’.
2. If we pass a string as an argument we will get an error no matching function for call to ‘frexp(const char [n]).
• If x=0 then significand is zero and exponent is zero
• x >= 1 then significand is positive number and exponent is positive number
• x <= -1 then significand is negative number and exponent is positive number
• -1 < x < 0 then significand is negative number and exponent is negative number
• 0 < x < 1 then significand is positive number and exponent is negative number

# CODE 1

 `// CPP implementation of  ` `// above function ` `#include ` `#include ` ` `  `using` `namespace` `std; ` ` `  `// Driver program ` `int` `main() ` `{ ` `    ``double` `x = 5.35, significand; ` `    ``int` `exponent; ` `    ``significand = ``frexp``(x, &exponent); ` `    ``cout << x << ``" = "` `<< significand  ` `         ``<< ``" * 2^"` `<< exponent << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```5.35 = 0.66875 * 2^3
```

# CODE 2

 `// CPP implementation of the  ` `// above function ` `#include ` `#include ` ` `  `using` `namespace` `std; ` ` `  `// Driver program ` `int` `main() ` `{ ` `    ``double` `significand; ` `    ``int` `exponent, x = 5; ` `    ``significand = ``frexp``(x, &exponent); ` `    ``cout << x << ``" = "` `<< significand  ` `         ``<< ``" * 2^"` `<< exponent << endl; ` ` `  `    ``return` `0; ` `} `

Output:

```5 = 0.625 * 2^3
```

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.