Skip to main content

libm (baremetal)

Baremetal math library implementation, providing C99 standard math functions for use without an operating system. Each function has both double and float (f suffix) variants.

Mathematical Constants

MacroValueMeaning
M_E2.71828...e
M_LOG2E1.44269...log2(e)
M_LOG10E0.43429...log10(e)
M_LN20.69314...ln(2)
M_LN102.30258...ln(10)
M_PI3.14159...π
M_PI_21.57079...π/2
M_PI_40.78539...π/4
M_1_PI0.31830...1/π
M_2_PI0.63661...2/π
M_2_SQRTPI1.12837...2/√π
M_SQRT21.41421...√2
M_SQRT1_20.70710...1/√2

Special Values

MacroMeaning
NANNot a Number
INFINITYPositive infinity
HUGE_VALFfloat positive infinity
HUGE_VALdouble positive infinity
HUGE_VALLlong double positive infinity

FP Classification

MacroMeaning
fpclassify(x)Returns FP_NAN/FP_INFINITE/FP_ZERO/FP_SUBNORMAL/FP_NORMAL
isinf(x)Is infinite
isnan(x)Is NaN
isnormal(x)Is normal value
isfinite(x)Is finite
signbit(x)Is negative

Comparison Macros

MacroMeaning
isgreater(x, y)x > y
isgreaterequal(x, y)x >= y
isless(x, y)x < y
islessequal(x, y)x <= y
islessgreater(x, y)x < y or x > y
isunordered(x, y)Either is NaN

Trigonometric Functions

double acos(double); float acosf(float);
double asin(double); float asinf(float);
double atan(double); float atanf(float);
double atan2(double, double); float atan2f(float, float);
double cos(double); float cosf(float);
double sin(double); float sinf(float);
double tan(double); float tanf(float);

Hyperbolic Functions

double acosh(double); float acoshf(float);
double asinh(double); float asinhf(float);
double atanh(double); float atanhf(float);
double cosh(double); float coshf(float);
double sinh(double); float sinhf(float);
double tanh(double); float tanhf(float);

Exponential and Logarithmic Functions

double exp(double); float expf(float);
double exp2(double); float exp2f(float);
double expm1(double); float expm1f(float);
double log(double); float logf(float);
double log10(double); float log10f(float);
double log1p(double); float log1pf(float);
double log2(double); float log2f(float);

Power and Root Functions

double pow(double, double); float powf(float, float);
double sqrt(double); float sqrtf(float);
double cbrt(double); float cbrtf(float);
double hypot(double, double); float hypotf(float, float);

Error Functions

double erf(double); float erff(float);
double erfc(double); float erfcf(float);

Rounding and Remainder

double ceil(double); float ceilf(float);
double floor(double); float floorf(float);
double rint(double); float rintf(float);
double round(double); float roundf(float);
double trunc(double); float truncf(float);
double fmod(double, double); float fmodf(float, float);
double modf(double, double *); float modff(float, float *);

Absolute Value, Min, Max

double fabs(double); float fabsf(float);
double fmax(double, double); float fmaxf(float, float);
double fmin(double, double); float fminf(float, float);
double fdim(double, double); float fdimf(float, float);

Floating-Point Manipulation

double frexp(double, int *); float frexpf(float, int *);
double ldexp(double, int); float ldexpf(float, int);
double scalbn(double, int); float scalbnf(float, int);
double scalbln(double, long); float scalblnf(float, long);