1, abs( x) function
Format: intabs (int I);
Function: Find the absolute value of an integer.
Example:
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
# include & ltmath.h & gt
Master ()
{
int a = 1,b =-2;
Printf ("the absolute value of %d is% d and the absolute value of% d is %d\n", a, abs( a), b, ABS (b));
}
The running result is: the absolute value of 1 is 1, and the absolute value of -2 is 2.
2.fabs( x) function
Format: float fabs (float I); /double fab (double x);
Function: Find the absolute value of floating-point number.
Example:
# include & ltstdio.h & gt
# include & ltmath.h & gt
Master ()
{
float a = 1.4,b =-2.7;
Printf ("the absolute value of f is %f, and the absolute value of f is %f\n", a, fabs( a), b, fabs (b));
}
The running results are: the absolute value of 1.400000 is 1.400000, and the absolute value of -2.700000 is 2.700000.
Extended data:
Other math.h header files contain function descriptions:
1, trigonometric function
Double); crime; sine
Double cos (double); cosine
Shuangtan (double); tangent
2. Inverse trigonometric function
double asin(double); The result is between [-PI/2, PI/2]
Double acos (double); The result is between [0, PI]
Double (double); Arctangent (principal value), the result is between [-PI/2, PI/2]
double atan2 (double,double); Arctangent (integer value), the result is between [-PI, PI]
3. Hyperbolic trigonometric functions
Double sinh (double);
Double cosh (double);
Double tanh (double);
4. Exponents and Logarithms
double frexp(double value,int * exp); This is a method to split a value into a fractional part f and an exponential part exp (base 2), and return the fractional part f, that is, f * 2 exp. Where the value of f is in the range of 0.5~ 1.0 or 0.
double ldexp(double x,int exp); This function is just the opposite of the frexp function above, and the return value is x * 2 exp.
double modf(double value,double * iptr); Split a value and return its fractional part, with iptr pointing to the integer part.
Double; Logarithm based on e
double log 10(double); Logarithm based on 10
Double power (double x, double y); Calculate the y power of x
Floating point powf (floating point x, floating point y); This function is the same as pow, except that the input and output are single-precision floating-point numbers.
Double exp (double); Find the power of natural number e
double sqrt(double); square root
5, rounding
Double ceiling (double); Rounds up and returns the smallest integer not less than x.
Double floor (double); Take the integer down and return the largest integer not greater than x, which is the Gaussian function [x]