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:

  1. set errno to zero, and
  2. 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 x is NaN, a NaN shall be returned.
  • if x is Β±0, Β±0 shall be returned.
  • if x is -Inf, -1 shall be returned.
  • if x is +Inf, x shall be returned.

and the spicy one 🌢️:

  • if x is subnormal, a range error may occur and x should be returned.
  • if x is not returned, expm1(), expm1f(), and expm1l() shall return an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_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, then errno shall be set to [ERANGE]. if the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow floating-point exception shall be raised.

these functions may fail if:

  • Range Error β€” the value of x is subnormal.
    • if the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [ERANGE]. if the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the underflow floating-point exception shall be raised.

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>.


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 🫢✨