SQL HTML CSS Javascript Python Java C C++ PHP Scala
Arduino - Math Library
The Arduino Math library (math.h) includes a number of useful mathematical
functions for manipulating floating-point numbers.
Library Macros
Following are the macros defined in the header math.h −
Given below is the list of macros defined in the header math.h
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 1 of 15
:
Macros Value Description
M_E 2.7182818284590452354 The constant e.
1.4426950408889634074
The logarithm of the e to
M_LOG2E
/* log_2 e */ base 2
0.31830988618379067154
M_1_PI The constant 1/pi
/* 1/pi */
0.63661977236758134308
M_2_PI The constant 2/pi
/* 2/pi */
1.12837916709551257390
M_2_SQRTPI The constant 2/sqrt(pi)
/* 2/sqrt(pi) */
2.30258509299404568402
The natural logarithm of the
M_LN10
/* log_e 10 */ 10
0.69314718055994530942
The natural logarithm of the
M_LN2
/* log_e 2 */ 2
0.43429448190325182765
The logarithm of the e to
M_LOG10E
/* log_10 e */ base 10
3.14159265358979323846
M_PI The constant pi
/* pi */
3.3V1.57079632679489661923
M_PI_2 The constant pi/2
/* pi/2 */
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 2 of 15
:
0.78539816339744830962
M_PI_4 The constant pi/4
/* pi/4 */
0.70710678118654752440
M_SQRT1_2 The constant 1/sqrt(2)
/* 1/sqrt(2) */
1.41421356237309504880
M_SQRT2 The square root of 2
/* sqrt(2) */
acosf - The alias for acos() function
asinf - The alias for asin() function
The alias for atan2()
atan2f
Home Whiteboard -
Online Compilers Practice Articles Jobs
function
Learn more
cbrtf Chapters - The alias forCategories
cbrt() function
ceilf - The alias for ceil() function
The alias for copysign()
copysignf -
function
coshf - The alias for cosh() function
expf - The alias for exp() function
fabsf - The alias for fabs() function
fdimf - The alias for fdim() function
floorf - The alias for floor() function
The alias for fmax()
fmaxf -
function
fminf - The alias for fmin() function
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 3 of 15
:
fmodf - The alias for fmod()
function
The alias for frexp()
frexpf -
function
The alias for hypot()
hypotf -
function
INFINITY - INFINITY constant
The alias for isfinite()
isfinitef -
function
isinff - The alias for isinf() function
The alias for isnan()
isnanf -
function
The alias for ldexp()
ldexpf -
function
The alias for log10()
log10f -
function
logf - The alias for log() function
lrintf - The alias for lrint() function
The alias for lround()
lroundf -
function
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 4 of 15
:
Powered by:
00:00
Library Functions
The following functions are defined in the header math.h −
Given below is the list of functions are defined in the header math.h
S.No. Library Function & Description
double acos (double __x)
The acos() function computes the principal value of the arc cosine of
1
__x. The returned value is in the range [0, pi] radians. A domain
error occurs for arguments not in the range [-1, +1].
double asin (double __x)
The asin() function computes the principal value of the arc sine of
2
__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].
double atan (double __x)
3 The atan() function computes the principal value of the arc tangent
of __x. The returned value is in the range [-pi/2, pi/2] radians.
double atan2 (double __y, double __x)
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 5 of 15
:
The atan2() function computes the principal value of the arc tangent
4 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.
double cbrt (double __x)
5
The cbrt() function returns the cube root of __x.
double ceil (double __x)
6 The ceil() function returns the smallest integral value greater than or
equal to __x, expressed as a floating-point number.
static double copysign (double __x, double __y)
7 The copysign() function returns __x but with the sign of __y. They
work even if __x or __y are NaN or zero.
double cos(double __x)
8
The cos() function returns the cosine of __x, measured in radians.
double cosh (double __x)
9
The cosh() function returns the hyperbolic cosine of __x.
double exp (double __x)
10
The exp() function returns the exponential value of __x.
double fabs (double __x)
11 The fabs() function computes the absolute value of a floating-point
number __x.
double fdim (double __x, double __y)
12 The fdim() function returns max(__x - __y, 0). If __x or __y or both
are NaN, NaN is returned.
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 6 of 15
:
double floor (double __x)
13 The floor() function returns the largest integral value less than or
equal to __x, expressed as a floating-point number.
double fma (double __x, double __y, double __z)
The fma() function performs floating-point multiply-add. This is the
14 operation (__x * __y) + __z, but the intermediate result is not
rounded to the destination type. This can sometimes improve the
precision of a calculation.
double fmax (double __x, double __y)
The fmax() function returns the greater of the two values __x and
15
__y. If an argument is NaN, the other argument is returned. If both
the arguments are NaN, NaN is returned.
double fmin (double __x, double __y)
The fmin() function returns the lesser of the two values __x and __y.
16
If an argument is NaN, the other argument is returned. If both the
arguments are NaN, NaN is returned.
double fmod (double __x, double__y)
17 The function fmod() returns the floating-point remainder of __x /
__y.
double frexp (double __x, int * __pexp)
The frexp() 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 frexp() 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
18 raised to the power __pexp. If __x is zero, both parts of the result
are zero. If __x is not a finite number, the frexp() returns __x as is
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 7 of 15
:
and stores 0 by __pexp.
Note − This implementation permits a zero pointer as a directive to
skip a storing the exponent.
double hypot (double __x, double__y)
The hypot() function returns sqrt(__x*__x + __y*__y). This is the
length of the hypotenuse of a right triangle with sides of length __x
19 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.
static int isfinite (double __x)
20 The isfinite() function returns a nonzero value if __x is finite: not
plus or minus infinity, and not NaN.
int isinf (double __x)
The function isinf() returns 1 if the argument __x is positive infinity,
21 -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).
int isnan (double __x)
22 The function isnan() returns 1 if the argument __x represents a
"not-a-number" (NaN) object, otherwise 0.
double ldexp (double __x, int __exp )
The ldexp() function multiplies a floating-point number by an integral
23
power of 2. It returns the value of __x times 2 raised to the power
__exp.
double log (double __x)
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 8 of 15
:
24 The log() function returns the natural logarithm of argument __x.
double log10(double __x)
25 The log10() function returns the logarithm of argument __x to base
10.
long lrint (double __x)
The lrint() 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 rint() function,
but it differs in type of return value and in that an overflow is
26 possible.
Returns
The rounded long integer value. If __x is not a finite number or an
overflow, this realization returns the LONG_MIN value
(0x80000000).
long lround (double __x)
The lround() 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 round() function, but it differs in
type of return value and in that an overflow is possible.
27
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).
double modf (double __x, double * __iptr )
The modf() 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.
28
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 9 of 15
:
The modf() 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.
float modff (float __x, float * __iptr)
29
The alias for modf().
double pow (double __x, double __y)
30
The function pow() returns the value of __x to the exponent __y.
double round (double __x)
The round() function rounds __x to the nearest integer, but rounds
halfway cases away from zero (instead of to the nearest even
integer). Overflow is impossible.
31
Returns
The rounded value. If __x is an integral or infinite, __x itself is
returned. If __x is NaN, then NaN is returned.
int signbit (double __x)
The signbit() function returns a nonzero value if the value of __x has
32 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.
double sin (double __x)
33
The sin() function returns the sine of __x, measured in radians.
double sinh (double __x)
34
The sinh() function returns the hyperbolic sine of __x.
double sqrt (double __x)
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 10 of 15
:
35
The sqrt() function returns the non-negative square root of __x.
double square (double __x)
36 The function square() returns __x * __x.
Note − This function does not belong to the C standard definition.
double tan (double __x)
37
The tan() function returns the tangent of __x, measured in radians.
double tanh ( double __x)
38
The tanh() function returns the hyperbolic tangent of __x.
double trunc (double __x)
39 The trunc() function rounds __x to the nearest integer not larger in
absolute value.
Example
The following example shows how to use the most common math.h library
functions −
double double__x = 45.45 ;
double double__y = 30.20 ;
void setup() {
Serial.begin(9600);
Serial.print("cos num = ");
Serial.println (cos (double__x) ); // returns cosine of x
Serial.print("absolute value of num = ");
Serial.println (fabs (double__x) ); // absolute value of a
float
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 11 of 15
:
Serial.print("floating point modulo = ");
Serial.println (fmod (double__x, double__y)); // floating
point modulo
Serial.print("sine of num = ");
Serial.println (sin (double__x) ) ;// returns sine of x
Serial.print("square root of num : ");
Serial.println ( sqrt (double__x) );// returns square root
of x
Serial.print("tangent of num : ");
Serial.println ( tan (double__x) ); // returns tangent of x
Serial.print("exponential value of num : ");
Serial.println ( exp (double__x) ); // function returns the
exponential value of x.
Serial.print("cos num : ");
Serial.println (atan (double__x) ); // arc tangent of x
Serial.print("tangent of num : ");
Serial.println (atan2 (double__y, double__x) );// arc
tangent of y/x
Serial.print("arc tangent of num : ");
Serial.println (log (double__x) ) ; // natural logarithm of
x
Serial.print("cos num : ");
Serial.println ( log10 (double__x)); // logarithm of x to
base 10.
Serial.print("logarithm of num to base 10 : ");
Serial.println (pow (double__x, double__y) );// x to power
of y
Serial.print("power of num : ");
Serial.println (square (double__x)); // square of x
}
void loop() {
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 12 of 15
:
}
Result
cos num = 0.10
absolute value of num = 45.45
floating point modulo =15.25
sine of num = 0.99
square root of num : 6.74
tangent of num : 9.67
exponential value of num : ovf
cos num : 1.55
tangent of num : 0.59
arc tangent of num : 3.82
cos num : 1.66
logarithm of num to base 10 : inf
power of num : 2065.70
TOP TUTORIALS
Python Tutorial
Java Tutorial
C++ Tutorial
C Programming Tutorial
C# Tutorial
PHP Tutorial
R Tutorial
HTML Tutorial
CSS Tutorial
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 13 of 15
:
JavaScript Tutorial
SQL Tutorial
TRENDING TECHNOLOGIES
Cloud Computing Tutorial
Amazon Web Services Tutorial
Microsoft Azure Tutorial
Git Tutorial
Ethical Hacking Tutorial
Docker Tutorial
Kubernetes Tutorial
DSA Tutorial
Spring Boot Tutorial
SDLC Tutorial
Unix Tutorial
CERTIFICATIONS
Business Analytics Certification
Java & Spring Boot Advanced Certification
Data Science Advanced Certification
Cloud Computing And DevOps
Advanced Certification In Business Analytics
Artificial Intelligence And Machine Learning
DevOps Certification
Game Development Certification
Front-End Developer Certification
AWS Certification Training
Python Programming Certification
COMPILERS & EDITORS
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 14 of 15
:
COMPILERS & EDITORS
Online Java Compiler
Online Python Compiler
Online Go Compiler
Online C Compiler
Online C++ Compiler
Online C# Compiler
Online PHP Compiler
Online MATLAB Compiler
Online Bash Terminal
Online SQL Compiler
Online Html Editor
ABOUT US | OUR TEAM | CAREERS | JOBS | CONTACT US |
TERMS OF USE | PRIVACY POLICY | REFUND POLICY | COOKIES POLICY | FAQ'S
Tutorials Point is a leading Ed Tech company striving to provide the best learning
material on technical and non-technical subjects.
© Copyright 2025. All Rights Reserved.
https://www.tutorialspoint.com/arduino/arduino_math_library.htm 8/21/25, 08 35
Page 15 of 15
: