avr-libc  2.1.0
Standard C library for AVR-GCC

AVR Libc Home Page

AVRs

AVR Libc Development Pages

Main Page

User Manual

Library Reference

FAQ

Example Projects

Macros | Functions
<math.h>: Mathematics

Macros

#define M_E   2.7182818284590452354
 
#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) */
 
#define NAN   __builtin_nan("")
 
#define INFINITY   __builtin_inf()
 
#define __ASM_ALIAS(x)   __asm(#x)
 

Functions

float cosf (float __x)
 
double cos (double __x) __ASM_ALIAS(cosf)
 
float sinf (float __x)
 
double sin (double __x) __ASM_ALIAS(sinf)
 
float tanf (float __x)
 
double tan (double __x) __ASM_ALIAS(tanf)
 
static float fabsf (float __x)
 
static double fabs (double __x)
 
float fmodf (float __x, float __y)
 
double fmod (double __x, double __y) __ASM_ALIAS(fmodf)
 
float modff (float __x, float *__iptr)
 
double modf (double __x, double *__iptr) __ASM_ALIAS(modff)
 
float sqrtf (float __x)
 
double sqrt (double __x) __ASM_ALIAS(sqrtf)
 
float cbrtf (float __x)
 
double cbrt (double __x) __ASM_ALIAS(cbrtf)
 
float hypotf (float __x, float __y)
 
double hypot (double __x, double __y) __ASM_ALIAS(hypotf)
 
float squaref (float __x)
 
double square (double __x) __ASM_ALIAS(squaref)
 
float floorf (float __x)
 
double floor (double __x) __ASM_ALIAS(floorf)
 
float ceilf (float __x)
 
double ceil (double __x) __ASM_ALIAS(ceilf)
 
float frexpf (float __x, int *__pexp)
 
double frexp (double __x, int *__pexp) __ASM_ALIAS(frexpf)
 
float ldexpf (float __x, int __exp)
 
double ldexp (double __x, int __exp) __ASM_ALIAS(ldexpf)
 
float expf (float __x)
 
double exp (double __x) __ASM_ALIAS(expf)
 
float coshf (float __x)
 
double cosh (double __x) __ASM_ALIAS(coshf)
 
float sinhf (float __x)
 
double sinh (double __x) __ASM_ALIAS(sinhf)
 
float tanhf (float __x)
 
double tanh (double __x) __ASM_ALIAS(tanhf)
 
float acosf (float __x)
 
double acos (double __x) __ASM_ALIAS(acosf)
 
float asinf (float __x)
 
double asin (double __x) __ASM_ALIAS(asinf)
 
float atanf (float __x)
 
double atan (double __x) __ASM_ALIAS(atanf)
 
float atan2f (float __y, float __x)
 
double atan2 (double __y, double __x) __ASM_ALIAS(atan2f)
 
float logf (float __x)
 
double log (double __x) __ASM_ALIAS(logf)
 
float log10f (float __x)
 
double log10 (double __x) __ASM_ALIAS(log10f)
 
float powf (float __x, float __y)
 
double pow (double __x, double __y) __ASM_ALIAS(powf)
 
int isnanf (float __x)
 
int isnan (double __x) __ASM_ALIAS(isnanf)
 
int isinff (float __x)
 
int isinf (double __x) __ASM_ALIAS(isinff)
 
static int isfinitef (float __x)
 
static int isfinite (double __x)
 
static float copysignf (float __x, float __y)
 
static double copysign (double __x, double __y)
 
int signbitf (float __x)
 
int signbit (double __x) __ASM_ALIAS(signbitf)
 
float fdimf (float __x, float __y)
 
double fdim (double __x, double __y) __ASM_ALIAS(fdimf)
 
float fmaf (float __x, float __y, float __z)
 
double fma (double __x, double __y, double __z) __ASM_ALIAS(fmaf)
 
float fmaxf (float __x, float __y)
 
double fmax (double __x, double __y) __ASM_ALIAS(fmaxf)
 
float fminf (float __x, float __y)
 
double fmin (double __x, double __y) __ASM_ALIAS(fminf)
 
float truncf (float __x)
 
double trunc (double __x) __ASM_ALIAS(truncf)
 
float roundf (float __x)
 
double round (double __x) __ASM_ALIAS(roundf)
 
long lroundf (float __x)
 
long lround (double __x) __ASM_ALIAS(lroundf)
 
long lrintf (float __x)
 
long lrint (double __x) __ASM_ALIAS(lrintf)
 

Detailed Description

#include <math.h>

This header file declares basic mathematics constants and functions.

Notes:
  • In order to access the functions declared herein, it is usually also required to additionally link against the library libm.a. See also the related FAQ entry.
  • Math functions do not raise exceptions and do not change the errno variable. Therefore the majority of them are declared with const attribute, for better optimization by GCC.

Macro Definition Documentation

◆ INFINITY

#define INFINITY   __builtin_inf()

INFINITY constant.

◆ M_1_PI

#define M_1_PI   0.31830988618379067154 /* 1/pi */

The constant 1/pi.

◆ M_2_PI

#define M_2_PI   0.63661977236758134308 /* 2/pi */

The constant 2/pi.

◆ M_2_SQRTPI

#define M_2_SQRTPI   1.12837916709551257390 /* 2/sqrt(pi) */

The constant 2/sqrt(pi).

◆ M_E

#define M_E   2.7182818284590452354

The constant e.

◆ M_LN10

#define M_LN10   2.30258509299404568402 /* log_e 10 */

The natural logarithm of the 10.

◆ M_LN2

#define M_LN2   0.69314718055994530942 /* log_e 2 */

The natural logarithm of the 2.

◆ M_LOG10E

#define M_LOG10E   0.43429448190325182765 /* log_10 e */

The logarithm of the e to base 10.

◆ M_LOG2E

#define M_LOG2E   1.4426950408889634074 /* log_2 e */

The logarithm of the e to base 2.

◆ M_PI

#define M_PI   3.14159265358979323846 /* pi */

The constant pi.

◆ M_PI_2

#define M_PI_2   1.57079632679489661923 /* pi/2 */

The constant pi/2.

◆ M_PI_4

#define M_PI_4   0.78539816339744830962 /* pi/4 */

The constant pi/4.

◆ M_SQRT1_2

#define M_SQRT1_2   0.70710678118654752440 /* 1/sqrt(2) */

The constant 1/sqrt(2).

◆ M_SQRT2

#define M_SQRT2   1.41421356237309504880 /* sqrt(2) */

The square root of 2.

◆ NAN

#define NAN   __builtin_nan("")

NAN constant.

Function Documentation

◆ acos()

double acos ( double  __x)

The alias for acosf().

◆ acosf()

float acosf ( float  __x)

The acosf() function computes the principal value of the arc cosine of __x. The returned value is in the range [0, pi] radians. A domain error occurs for arguments not in the range [-1, +1].

◆ asin()

double asin ( double  __x)

The alias for asinf().

◆ asinf()

float asinf ( float  __x)

The asinf() function computes the principal value of the arc sine of __x. The returned value is in the range [-pi/2, pi/2] radians. A domain error occurs for arguments not in the range [-1, +1].

◆ atan()

double atan ( double  __x)

The alias for atanf().

◆ atan2()

double atan2 ( double  __y,
double  __x 
)

The alias for atan2f().

◆ atan2f()

float atan2f ( float  __y,
float  __x 
)

The atan2f() function computes the principal value of the arc tangent of __y / __x, using the signs of both arguments to determine the quadrant of the return value. The returned value is in the range [-pi, +pi] radians.

◆ atanf()

float atanf ( float  __x)

The atanf() function computes the principal value of the arc tangent of __x. The returned value is in the range [-pi/2, pi/2] radians.

◆ cbrt()

double cbrt ( double  __x)

The alias for cbrtf().

◆ cbrtf()

float cbrtf ( float  __x)

The cbrt() function returns the cube root of __x.

◆ ceil()

double ceil ( double  __x)

The alias for ceilf().

◆ ceilf()

float ceilf ( float  __x)

The ceilf() function returns the smallest integral value greater than or equal to __x, expressed as a floating-point number.

◆ copysignf()

static float copysignf ( float  __x,
float  __y 
)
static

The copysignf() function returns __x but with the sign of __y. They work even if __x or __y are NaN or zero.

◆ cos()

double cos ( double  __x)

The alias for cosf().

◆ cosf()

float cosf ( float  __x)

The cosf() function returns the cosine of __x, measured in radians.

◆ cosh()

double cosh ( double  __x)

The alias for coshf().

◆ coshf()

float coshf ( float  __x)

The coshf() function returns the hyperbolic cosine of __x.

◆ exp()

double exp ( double  __x)

The alias for expf().

◆ expf()

float expf ( float  __x)

The expf() function returns the exponential value of __x.

◆ fabsf()

static float fabsf ( float  __x)
static

The fabsf() function computes the absolute value of a floating-point number __x.

◆ fdim()

double fdim ( double  __x,
double  __y 
)

The alias for fdimf().

◆ fdimf()

float fdimf ( float  __x,
float  __y 
)

The fdimf() function returns maxf(__x - __y, 0). If __x or __y or both are NaN, NaN is returned.

◆ floor()

double floor ( double  __x)

The alias for floorf().

◆ floorf()

float floorf ( float  __x)

The floorf() function returns the largest integral value less than or equal to __x, expressed as a floating-point number.

◆ fma()

double fma ( double  __x,
double  __y,
double  __z 
)

The alias for fmaf().

◆ fmaf()

float fmaf ( float  __x,
float  __y,
float  __z 
)

The fmaf() function performs floating-point multiply-add. This is the operation (__x * __y) + __z, but the intermediate result is not rounded to the destination type. This can sometimes improve the precision of a calculation.

◆ fmax()

double fmax ( double  __x,
double  __y 
)

The alias for fmaxf().

◆ fmaxf()

float fmaxf ( float  __x,
float  __y 
)

The fmaxf() function returns the greater of the two values __x and __y. If an argument is NaN, the other argument is returned. If both arguments are NaN, NaN is returned.

◆ fmin()

double fmin ( double  __x,
double  __y 
)

The alias for fminf().

◆ fminf()

float fminf ( float  __x,
float  __y 
)

The fminf() function returns the lesser of the two values __x and __y. If an argument is NaN, the other argument is returned. If both arguments are NaN, NaN is returned.

◆ fmod()

double fmod ( double  __x,
double  __y 
)

The alias for fmodf().

◆ fmodf()

float fmodf ( float  __x,
float  __y 
)

The function fmodf() returns the floating-point remainder of __x / __y.

◆ frexp()

double frexp ( double  __x,
int *  __pexp 
)

The alias for frexpf().

◆ frexpf()

float frexpf ( float  __x,
int *  __pexp 
)

The frexpf() function breaks a floating-point number into a normalized fraction and an integral power of 2. It stores the integer in the int object pointed to by __pexp.

If __x is a normal float point number, the frexpf() function returns the value v, such that v has a magnitude in the interval [1/2, 1) or zero, and __x equals v times 2 raised to the power __pexp. If __x is zero, both parts of the result are zero. If __x is not a finite number, the frexpf() returns __x as is and stores 0 by __pexp.

Note
This implementation permits a zero pointer as a directive to skip a storing the exponent.

◆ hypot()

double hypot ( double  __x,
double  __y 
)

The alias for hypotf().

◆ hypotf()

float hypotf ( float  __x,
float  __y 
)

The hypotf() function returns sqrtf(__x*__x + __y*__y). This is the length of the hypotenuse of a right triangle with sides of length __x and __y, or the distance of the point (__x, __y) from the origin. Using this function instead of the direct formula is wise, since the error is much smaller. No underflow with small __x and __y. No overflow if result is in range.

◆ isfinite()

static int isfinite ( double  __x)
static
Parameters
__xThe alias for isfinitef().

◆ isfinitef()

static int isfinitef ( float  __x)
static

The isfinitef() function returns a nonzero value if __x is finite: not plus or minus infinity, and not NaN.

◆ isinf()

int isinf ( double  __x)

The alias for isinff().

◆ isinff()

int isinff ( float  __x)

The function isinff() returns 1 if the argument __x is positive infinity, -1 if __x is negative infinity, and 0 otherwise.

Note
The GCC 4.3 can replace this function with inline code that returns the 1 value for both infinities (gcc bug #35509).

◆ isnan()

int isnan ( double  __x)

The alias for isnanf().

◆ isnanf()

int isnanf ( float  __x)

The function isnanf() returns 1 if the argument __x represents a "not-a-number" (NaN) object, otherwise 0.

◆ ldexp()

double ldexp ( double  __x,
int  __exp 
)

The alias for ldexpf().

◆ ldexpf()

float ldexpf ( float  __x,
int  __exp 
)

The ldexpf() function multiplies a floating-point number by an integral power of 2. It returns the value of __x times 2 raised to the power __exp.

◆ log()

double log ( double  __x)

The alias for logf().

◆ log10()

double log10 ( double  __x)

The alias for log10f().

◆ log10f()

float log10f ( float  __x)

The log10f() function returns the logarithm of argument __x to base 10.

◆ logf()

float logf ( float  __x)

The logf() function returns the natural logarithm of argument __x.

◆ lrint()

long lrint ( double  __x)

The alias for lrintf().

◆ lrintf()

long lrintf ( float  __x)

The lrintf() function rounds __x to the nearest integer, rounding the halfway cases to the even integer direction. (That is both 1.5 and 2.5 values are rounded to 2). This function is similar to rintf() function, but it differs in type of return value and in that an overflow is possible.

Returns
The rounded long integer value. If __x is not a finite number or an overflow was, this realization returns the LONG_MIN value (0x80000000).

◆ lround()

long lround ( double  __x)

The alias for lroundf().

◆ lroundf()

long lroundf ( float  __x)

The lroundf() function rounds __x to the nearest integer, but rounds halfway cases away from zero (instead of to the nearest even integer). This function is similar to roundf() function, but it differs in type of return value and in that an overflow is possible.

Returns
The rounded long integer value. If __x is not a finite number or an overflow was, this realization returns the LONG_MIN value (0x80000000).

◆ modf()

double modf ( double  __x,
double *  __iptr 
)

An alias for modff().

◆ modff()

float modff ( float  __x,
float *  __iptr 
)

The modff() function breaks the argument __x into integral and fractional parts, each of which has the same sign as the argument. It stores the integral part as a double in the object pointed to by __iptr.

The modff() function returns the signed fractional part of __x.

Note
This implementation skips writing by zero pointer. However, the GCC 4.3 can replace this function with inline code that does not permit to use NULL address for the avoiding of storing.

◆ pow()

double pow ( double  __x,
double  __y 
)

The alias for powf().

◆ powf()

float powf ( float  __x,
float  __y 
)

The function powf() returns the value of __x to the exponent __y.

◆ round()

double round ( double  __x)

The alias for roundf().

◆ roundf()

float roundf ( float  __x)

The roundf() function rounds __x to the nearest integer, but rounds halfway cases away from zero (instead of to the nearest even integer). Overflow is impossible.

Returns
The rounded value. If __x is an integral or infinite, __x itself is returned. If __x is NaN, then NaN is returned.

◆ signbit()

int signbit ( double  __x)

The alias for signbitf().

◆ signbitf()

int signbitf ( float  __x)

The signbitf() function returns a nonzero value if the value of __x has its sign bit set. This is not the same as `__x < 0.0', because IEEE 754 floating point allows zero to be signed. The comparison `-0.0 < 0.0' is false, but `signbit (-0.0)' will return a nonzero value.

◆ sin()

double sin ( double  __x)

The alias for sinf().

◆ sinf()

float sinf ( float  __x)

The sinf() function returns the sine of __x, measured in radians.

◆ sinh()

double sinh ( double  __x)

The alias for sinhf().

◆ sinhf()

float sinhf ( float  __x)

The sinhf() function returns the hyperbolic sine of __x.

◆ sqrt()

double sqrt ( double  __x)

An alias for sqrtf().

◆ sqrtf()

float sqrtf ( float  __x)

The sqrtf() function returns the non-negative square root of __x.

◆ square()

double square ( double  __x)

The alias for squaref().

◆ squaref()

float squaref ( float  __x)

The function squaref() returns __x * __x.

Note
This function does not belong to the C standard definition.

◆ tan()

double tan ( double  __x)

The alias for tanf().

◆ tanf()

float tanf ( float  __x)

The tanf() function returns the tangent of __x, measured in radians.

◆ tanh()

double tanh ( double  __x)

The alias for tanhf().

◆ tanhf()

float tanhf ( float  __x)

The tanhf() function returns the hyperbolic tangent of __x.

◆ trunc()

double trunc ( double  __x)

The alias for truncf().

◆ truncf()

float truncf ( float  __x)

The truncf() function rounds __x to the nearest integer not larger in absolute value.