This blog is under construction

Monday, 30 April 2012

frexp example in C

Header file:
    math.h

Synopsis:
     double frexp(double x, int *exp);

Description:
     It is used to split the number x into a fraction and exponent.  And this exponent is stored in exp.


frexp function C example:


  #include<stdio.h>
  #include<math.h>
  int main() {
        double x, res;
        int exp;
        printf("Enter the value for x:");
        scanf("%lf", &x);
        res = frexp(x, &exp);
        printf("Output: %lf\t exp:%d\n", res, exp);
        printf("res(%lf) * 2 ^ exp(%d) = x(%lf)\n", res, exp, res*pow(2,exp));
        return 0;
  }



  Output: 
  jp@jp-VirtualBox:~/cpgms/math$ ./a.out
  Enter the value for x:64
  Output: 0.500000     exp:7
  res(0.500000) * 2 ^ exp(7) = x(64.000000)


No comments:

Post a Comment