C Language Pow () function: To find X's y-square (Power)
header file:
The POW () function is used to find the Y power of X (the second side), and its prototype is:
Double pow (double x, double y);
POW () is used to calculate Y-square values with x as the base, and then returns the result. Set the return value to RET, then ret = xy.
Conditions that may cause an error:
- If base x is negative and exponent y is not an integer, it will cause a domain error error.
- If both base x and exponent y are 0, it may or may not be the domain error error, which is related to the library implementation.
- If base x is 0, exponential y is a negative number and may cause domain error or pole error errors, or not;
- If the return value RET is too large or too small, it will cause a range error error.
Error code:
- If a domain error error occurs, the global variable errno is set to EDOM;
- If a pole error or range error error occurs, the global variable errno is set to Erange.
Note that when compiling with GCC, please join-LM.
"Instance" see the code below.
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("7 ^ 3 =%f\n", pow (7.0, 3.0));
printf ("4.73 ^ =%f\n", pow (4.73, 12.0));
printf ("32.01 ^ 1.54 =%f\n", pow (32.01, 1.54));
return 0;
}
Output results:
7 ^ 3 = 343.000000
4.73 ^ a = 125410439.217423
32.01 ^ 1.54 = 208.036691
C language sqrt () function: To find the square root of a given value
header file:
sqrt () is used to find the square root of a given value, and its prototype is:
The "parameter" x is the value to compute the square root.
If x < 0, the domain error error is caused and the value of the global variable errno is set to EDOM.
return value returns the X square root.
Note that when compiling with GCC, please join-LM.
The instance calculates the square root of 200. 】
#include <math.h>
Main () {
double root;
root = sqrt (m);
printf ("Answer is%f\n", root);
}
Output results: