EXPM1(3POSIX)
π EXPM1(3POSIX) π
okay bestie, pull up a chair (or a terminal, same thing) π this one's from the POSIX Programmer's Manual β that's the manual name, it's on the tin β and we're about to talk about expm1, expm1f, and expm1l. it's giving "math but make it β¨preciseβ¨". let's go π¦
πΈ PROLOG πΈ
real talk first: this page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go read the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux at all π. vibe check your platform first, no cap.
π NAME π
expm1, expm1f, expm1l β compute exponential functions. that's the whole name section, she's brief but she ate π₯
β¨ SYNOPSIS β¨
#include <math.h>
double expm1(double x);
float expm1f(float x);
long double expm1l(long double x);
look at them. three little sisters, one job, different float sizes π
π¦ DESCRIPTION π¦
so, the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between the requirements written here and the ISO C standard, that conflict is unintentional β nobody's starting drama on purpose. this volume of POSIX.1β2017 defers to the ISO C standard, periodt.
these functions shall compute e^x-1.0. that's it. that's the whole function. iconic behavior honestly.
now, the important bit π an application wishing to check for error situations should:
- set
errnoto zero, and - call
feclearexcept(FE_ALL_EXCEPT)before calling these functions.
then, on return: if errno is non-zero, or if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred. congrats, you found the error, bestie π
π RETURN VALUE π
upon successful completion, these functions return e^x-1.0. slay.
if the correct value would cause overflow, a range error shall occur and expm1(), expm1f(), and expm1l() shall return the value of the macro HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively. big numbers, big feelings π₯
then the special cases, in order, because they're all main characters:
- if
xis NaN, a NaN shall be returned. - if
xis Β±0, Β±0 shall be returned. - if
xis -Inf, -1 shall be returned. - if
xis +Inf,xshall be returned.
and the spicy one πΆοΈ:
- if
xis subnormal, a range error may occur andxshould be returned. - if
xis not returned,expm1(),expm1f(), andexpm1l()shall return an implementation-defined value no greater in magnitude thanDBL_MIN,FLT_MIN, andLDBL_MIN, respectively.
ngl that last pair is the "it depends" of this whole page. read it twice. it's fine. it's fine π
π ERRORS π
these functions shall fail if:
- Range Error β the result overflows.
- if the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[ERANGE]. if the integer expression(math_errhandling & MATH_ERREXCEPT)is non-zero, then the overflow floating-point exception shall be raised.
- if the integer expression
these functions may fail if:
- Range Error β the value of
xis subnormal.- if the integer expression
(math_errhandling & MATH_ERRNO)is non-zero, thenerrnoshall be set to[ERANGE]. if the integer expression(math_errhandling & MATH_ERREXCEPT)is non-zero, then the underflow floating-point exception shall be raised.
- if the integer expression
and jsyk: the following sections are informative. (translation: the vibes are loose from here on, but we still keep every crumb π)
π EXAMPLES π
None. not a single one. she said "figure it out bestie" π (but fr fr, the APPLICATION USAGE section below has your back)
π§ APPLICATION USAGE π§
the value of expm1(x) may be more accurate than exp(x)-1.0 for small values of x. like, this is the whole reason she exists. precision queen π
the expm1() and log1p() functions are useful for financial calculations of ((1+x)^n-1)/x, namely:
expm1(n * log1p(x))/x
when x is very small (for example, when calculating small daily interest rates β yes, your savings account is living in this manpage πΈ). these functions also simplify writing accurate inverse hyperbolic functions.
on error, the expressions (math_errhandling & MATH_ERRNO) and (math_errhandling & MATH_ERREXCEPT) are independent of each other, but at least one of them must be non-zero. so like, they don't text each other, but one of them always shows up to the function π
β RATIONALE β
None.
πΈ FUTURE DIRECTIONS πΈ
None.
π₯ SEE ALSO π₯
exp()feclearexcept()fetestexcept()ilogb()log1p()
and from the Base Definitions volume of POSIX.1β2017: Section 4.20, Treatment of Error Conditions for Mathematical Functions, and <math.h>.
π COPYRIGHT π
okay, legal moment, but make it cute. portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document π (she's the final boss, no arguing). the original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html.
aaaand that's the whole page, bestie π this one came to you from IEEE/The Open Group, dated 2017 β so if you ever see EXPM1(3POSIX) floating around, you'll know exactly what's up. go forth and compute e^x-1.0 accurately, you absolute legend π«Άβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms