C Language: ldexp function(Combine Fraction and Exponent)

C Programming allows us to perform mathematical operations through the functions defined in header file. The header file contains various methods for performing mathematical operations such as sqrt(), pow(), ceil(), floor() etc.

C Math Functions

In the C Programming Language, the ldexp function combines a fraction and an exponent into a floating-point value.

Syntax

The syntax for the ldexp function in the C Language is:




double ldexp(double fraction, int exp);



Parameters or Arguments

fraction

The fractional part of the value.

exp

The exponent part of the value.

Returns

The ldexp function returns a floating-point value combining a fraction and an exponent based on the equation: fraction x 2 exponent

Required Header

In the C Language, the required header for the ldexp function is:




#include <math.h>



Applies To

In the C Language, the ldexp function can be used in the following versions:

  • ANSI/ISO 9899-1990

ldexp Example




/* Example using ldexp by c programming */

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    /* Define temporary variables */
    double value;
    int e;
    double result;

    /* Assign the value and exponential we will use to find the ldexp */
    value = 1.5;
    e = 2;

    /* Calculate the ldexp of the value and the exponential */
    result = ldexp(value, e);

    /* Display the result of the calculation */
    printf("The ldexp of %f with exponential %d is %f\n", value, e, result);

    return 0;
}



When compiled and run, this application will output:

The ldexp of 1.500000 with exponential 2 is 6.000000




Instagram