TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ Math frexp() Function

C++ Math frexp() Function with tutorial for beginners and professionals with examples on isgreaterequal(), less(), islessequal(), islessgreater(), isunordered(), exp(), frexp(), ldexp(), log(), log10(), modf(), exp2(), expm1(), log1p(), log2(), logb(), scalbn(), scalbln() etc.

<< Back to CPP

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':

float frexp(float x, int* exp);
double frexp(double x, int* exp);
long double frexp(long double x, int* exp);
double frexp(integral x, int* 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.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double x=2;
    int* e;
    cout<<"Value of x is : "<<x<<'\n';
    double significand = frexp(x,e);
    std::cout <<x<<"="<<significand<<" * "<<"2^"<<*e;
    return 0;
}

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

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double x=0;
    int* e;
    cout<<"Value of x is : "<<x<<'\n';
    double significand = frexp(x,e);
    std::cout <<x<<"="<<significand<<" * "<<"2^"<<*e;
    return 0;
}

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.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double x=0.4;
    int* e;
    cout<<"Value of x is : "<<x<<'\n';
    double significand = frexp(x,e);
    std::cout <<x<<"="<<significand<<" * "<<"2^"<<*e;
    return 0;
}

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.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double x= -0.1;
    int* e;
    cout<<"Value of x is : "<<x<<'\n';
    double significand = frexp(x,e);
    std::cout <<x<<"="<<significand<<" * "<<"2^"<<*e;
    return 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.

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    double x= -5;
    int* e;
    cout<<"Value of x is : "<<x<<'\n';
    double significand = frexp(x,e);
    std::cout <<x<<"="<<significand<<" * "<<"2^"<<*e;
    return 0;
}

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




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf