MentOS  0.8.0
The Mentoring Operating System
Macros | Functions
math.h File Reference

Mathematical constants and functions. More...

Go to the source code of this file.

Macros

#define abs(a)   (((a) < 0) ? -(a) : (a))
 The absolute value.
 
#define max(a, b)   (((a) > (b)) ? (a) : (b))
 The max of the two values.
 
#define min(a, b)   (((a) < (b)) ? (a) : (b))
 The min of the two values.
 
#define sign(x)   ((x < 0) ? -1 : ((x > 0) ? 1 : 0))
 The sign the the passed value.
 
#define round_up(number, base)   (((number) + (base)-1) & ~((base)-1))
 Returns a rounded up, away from zero, to the nearest multiple of b.
 
#define M_E   2.7182818284590452354
 e
 
#define M_LOG2E   1.4426950408889634074
 log_2 e
 
#define M_LOG10E   0.43429448190325182765
 log_10 e
 
#define M_LN2   0.69314718055994530942
 log_e 2
 
#define M_LN10   2.30258509299404568402
 log_e 10
 
#define M_PI   3.14159265358979323846
 pi
 
#define M_PI_2   1.57079632679489661923
 pi / 2
 
#define M_PI_4   0.78539816339744830962
 pi / 4
 
#define M_1_PI   0.31830988618379067154
 1 / pi
 
#define M_2_PI   0.63661977236758134308
 2 / pi
 
#define M_2_SQRTPI   1.12837916709551257390
 2 / sqrt(pi)
 
#define M_SQRT2   1.41421356237309504880
 sqrt(2)
 
#define M_SQRT1_2   0.70710678118654752440
 1 / sqrt(2)
 

Functions

double round (double x)
 Returns the integral value that is nearest to x, with halfway cases rounded away from zero. More...
 
double ceil (double x)
 Rounds x upward, returning the smallest integral value that is not less than x. More...
 
double floor (double x)
 Rounds x downward, returning the largest integral value that is not greater than x. More...
 
double pow (double base, double exponent)
 Returns base raised to the power exponent: More...
 
double exp (double x)
 Returns the base-e exponential function of x, which is e raised to the power x: e^x. More...
 
double fabs (double x)
 Returns the absolute value of x: |x|. More...
 
float fabsf (float x)
 Returns the absolute value of x: |x|. More...
 
double sqrt (double x)
 Returns the square root of x. More...
 
float sqrtf (float x)
 Returns the square root of x. More...
 
int isinf (double x)
 Checks if the input value is Infinite (INF). More...
 
int isnan (double x)
 Checks if the input value is Not A Number (NAN). More...
 
double log10 (double x)
 Logarithm function in base 10. More...
 
double ln (double x)
 Natural logarithm function. More...
 
double logx (double x, double y)
 Logarithm function in base x. More...
 
double modf (double x, double *intpart)
 Breaks x into an integral and a fractional part, both parts have the same sign as x. More...
 

Detailed Description

Mathematical constants and functions.

Function Documentation

◆ ceil()

double ceil ( double  x)

Rounds x upward, returning the smallest integral value that is not less than x.

Parameters
xValue to round up.
Returns
The smallest integral value that is not less than x (as a floating-point value).

◆ exp()

double exp ( double  x)

Returns the base-e exponential function of x, which is e raised to the power x: e^x.

Parameters
xValue of the exponent.
Returns
Exponential value of x.

If the magnitude of the result is too large to be represented by a value of the return type, the function returns HUGE_VAL (or HUGE_VALF or HUGE_VALL) with the proper sign, and an overflow range error occurs and the global variable errno is set to ERANGE.

◆ fabs()

double fabs ( double  x)

Returns the absolute value of x: |x|.

Parameters
xValue whose absolute value is returned.
Returns
The absolute value of x.

◆ fabsf()

float fabsf ( float  x)

Returns the absolute value of x: |x|.

Parameters
xValue whose absolute value is returned.
Returns
The absolute value of x.

◆ floor()

double floor ( double  x)

Rounds x downward, returning the largest integral value that is not greater than x.

Parameters
xValue to round down.
Returns
The value of x rounded downward (as a floating-point value).

◆ isinf()

int isinf ( double  x)

Checks if the input value is Infinite (INF).

Parameters
xThe value to check.
Returns
1 if INF, 0 otherwise.

◆ isnan()

int isnan ( double  x)

Checks if the input value is Not A Number (NAN).

Parameters
xThe value to check.
Returns
1 if NAN, 0 otherwise.

◆ ln()

double ln ( double  x)

Natural logarithm function.

Parameters
xTopic of the logarithm function.
Returns
Return the result.

◆ log10()

double log10 ( double  x)

Logarithm function in base 10.

Parameters
xTopic of the logarithm function.
Returns
Return the result.

◆ logx()

double logx ( double  x,
double  y 
)

Logarithm function in base x.

Parameters
xBase of the logarithm.
yTopic of the logarithm function.
Returns
Return the result.

◆ modf()

double modf ( double  x,
double *  intpart 
)

Breaks x into an integral and a fractional part, both parts have the same sign as x.

Parameters
xThe value we want to break.
intpartWhere we store the integer part.
Returns
the fractional part.

◆ pow()

double pow ( double  base,
double  exponent 
)

Returns base raised to the power exponent:

Parameters
baseBase value.
exponentExponent value.
Returns
The result of raising base to the power exponent.

If the base is finite negative and the exponent is finite but not an integer value, it causes a domain error. If both base and exponent are zero, it may also cause a domain error on certain implementations. If base is zero and exponent is negative, it may cause a domain error or a pole error (or none, depending on the library implementation). The function may also cause a range error if the result is too great or too small to be represented by a value of the return type.

◆ round()

double round ( double  x)

Returns the integral value that is nearest to x, with halfway cases rounded away from zero.

Parameters
xValue to round.
Returns
The value of x rounded to the nearest integral (as a floating-point value).

◆ sqrt()

double sqrt ( double  x)

Returns the square root of x.

Parameters
xValue whose square root is computed.
Returns
Square root of x. If x is negative, the global variable errno is set to EDOM.

◆ sqrtf()

float sqrtf ( float  x)

Returns the square root of x.

Parameters
xValue whose square root is computed.
Returns
Square root of x. If x is negative, the global variable errno is set to EDOM.