The exp () function and ldexp () function of C language and the Frexp () function _c language

Source: Internet
Author: User

C language exp () function: The second power function of E (the x-th square value at the end of E)
header file:

#include <math.h>

EXP () is used to calculate the X-square value, the ex value, at the base of E, and then return the result. Its prototype is:

  Double exp (double x);

return value returns the X-square calculation of E.

Note that when compiling with GCC, please join-LM.

"Instance" calculates the value of the 10-second side of E.

#include <math.h>
Main () {
  double answer;
  Answer = exp (ten);
  printf ("e^10 =%f\n", answer);
}

Run Result:

E^10 = 22026.465795

C language Ldexp () function: Returns the value of the exp second square on x multiplied by 2
header file:

#include <math.h>

Ldexp () is used to find the value of the exp second side of a number multiplied by 2, and the prototype is:

Double Ldexp (double x, int exp);

"Parameter" x is the mantissa, and exp is the power number.

Set the return value to RET, then ret = x * 2exp

Return value returns the RET.

Note that when compiling with GCC, please join-LM.

The "example" computes the value of 3* (2^2).

#include <math.h>
Main () {
  int exp;
  Double x, answer;
  Answer = LDEXP (3, 2);
  printf ("3*2^ (2) =%f\n", answer);
}

Operation Result:

3*2^ (2) = 12.000000

C language Frexp () function: To decompose a floating-point number into mantissa and exponent
header file:

#include <math.h>

Frexp () is used to decompose a number into mantissa and exponent, and its prototype is:

  Double Frexp (double x, int *exp);

"Parameter" x is a floating-point number to be decomposed, and exp is a pointer to the storage index.

Set the return value to RET, then x = ret * 2exp, where exp is an integer, and the absolute value of the RET is between 0.5 (inclusive) and 1 (not included).

If x = 0, then ret = exp = 0

Return value returns the MANTISSA ret.

Note that when compiling with GCC, please join-LM.

Take a look at the following code:

#include <stdio.h>   /* printf
/#include <math.h>    /* frexp
/int main ()
{
  double param, result;
  int n;
  param = 8.0;
  result = Frexp (param, &n);
  printf ("%f =%f * 2^%d\n", param, result, n);
  return 0;
}

Output results:

8.000000 = 0.500000 * 2^4

To change the value of line 7th param to 242.354, the output is:
242.354000 = 0.946695 * 2^8
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.