Built-In Function of Math:
The functions that are used to perform mathematical calculations are defined in “math.h” header file. The commonly used math library functions are discussed below.
The “pow” Function:
It is used to calculate the exponential power of a given integer number.
Its syntax is: pow (x ,y);
Where
x : is an integer number whose power is to be calculated.
y : is an integer number that represents the exponent of the number.
Example: If the value of 23 is to be calculated, the function is written as: pow (2, 3)
The “sqrt” Function:
It is used to calculate the square root of a given positive number. Its syntax is:
sqrt (x);
Where
x : is the positive number of type double (or variable). It also returns a value of type double.
Example: If x = 9.0 then sqrt (x) returns 3.0
The “floor” Function:
It is used to round a given float value to the integer value. The given float value is converted to the largest integer that is not greater than the given float value.
Its syntax is: floor(x);
Where
x: is a float or double value / variable.
Example: If x = 9.6 then floor(x) returns 9.0. If x= -9.6 then floor(x) returns -10.0.
The “ceil” Function:
It is similar to the “floor” function but it returns the rounded integer value greater than the given float or double number. Its syntax is: ceil (x);
Where
x : is the given float or double type given number or value.
Example: If x = 19.2 then ceil(x) returns 20.0. If x= -19.2 then ceil(x) returns -19.0.
The “fmod” Function:
It is used to calculate the remainder by dividing one floating number by another floating number. Its syntax is: fmod (x ,y);
x : represent the nominator. It is a floating number or variable.
y : represent the denominator. It is a floating number or variable.
Example: If x = 9.50 and y = 4.00 then fmod(x, y) returns 1.5. When y = 0, fmod returns 0.
The “cos” Function:
It is used to calculate the trigonometric cosine of a given angle. The angle is given in radians as a floating number. Its syntax is: cos (x);
Where:
x : represents an angle in radians.
Example: If x = 0.0 then cos (x) returns 1.0.
The “sin” Function:
It is used to calculate the trigonometric sine of a given floating number. The angle is given in radians as a floating number. Its syntax is: sin (x)
Where:
x : represents an angle or value in radians.
Example: if x = 0.0 then sin (x) returns 0.
The “tan” Functions:
It is used to calculate the trigonometric tangent of given floating number. The angle is given in radians as a floating number. Its syntax is: tan (x);
Where
x : represents an angle or value in radians
Example: If x = 0.0 then tan (x) returns 0.
The “log” Function:
It is used to calculate the natural logarithm (base e) or a given floating number. Its syntax is: log (x);
Where
x : represents a given floating number.
The “log10” Function:
It is used to calculate the logarithm (base 10) of a given floating number. Its syntax is: log10(x);
Where
x : represents a given floating number.
comment closed