frexp() in C++


The function frexp() is used to break the floating point number into its binary significand and integral exponent for 2. It returns the binary significand and its range is (0.5, 1). If we pass value zero, its significand and exponent value will be zero.

Here is the mathematical expression of frexp(),

x = significand * (2^exponent)

Here is the syntax of frexp() in C++ language,

float frexp(float variable_name, int* exponent);

Here,

  • variable_name  − Any name of variable which has floating number to be decomposed into binary significant.

  • exponent  − It is a pointer to int where value of exponent is stored.

Here is an example of frexp() in C++ language,

Example

 Live Demo

#include <iostream>
#include<math.h>
using namespace std;

int main() {
   double a = 4;
   int* b;

   cout<<"Value of a : "<< a <<'\n';
   double s = frexp(a, b);
   std::cout << a << " = " << s << " * " << "2^" << *b;

   return 0;
}

Output

Here is the output:

Value of a : 4
4 = 0.5 * 2^3

Updated on: 25-Jun-2020

65 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements