This blog is under construction

Monday, 30 April 2012

frexp example in C

Header file:

     double frexp(double x, int *exp);

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

frexp function C example:

  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;

  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