POW(3POSIX)

๐Ÿ’– POW(3POSIX) โ€” the POSIX Programmer's Manual ๐Ÿ’–

okay bestie, so this one is pow(3POSIX) from the POSIX Programmer's Manual โ€” yes that's the real manual name, we're not making it up. buckle up, it's giving math girlie energy and there's a LOT of edge cases. ๐Ÿงฎโœจ


๐Ÿšจ PROLOG ๐Ÿšจ

okay so first things first, real talk: this page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ โ€” so if you're on Linux, go peek at the corresponding Linux manual page for the deets on Linux behavior. OR. plot twist. the interface may not even be implemented on Linux at all. ๐Ÿ’€ so vibe check your platform first, bestie.


โœจ NAME โœจ

pow, powf, powl โ€” the power function, aka "x to the y, let's go" ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <math.h>

double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);

three flavors, one destiny: double, float, long double ๐Ÿ‘‘


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so the functionality on this reference page is aligned with the ISO C standard. and if there's any conflict between what's written here and the ISO C standard? that's unintentional, not a bit. this volume of POSIX.1โ€2017 defers to the ISO C standard, periodt.

so what do these do? they shall compute the value of x raised to the power y, aka x<sup>y</sup>. simple! iconic! ๐Ÿ”ฅ

BUT. if x is negative, the application shall ensure that y is an integer value. no cap. that's on you.

and if you're the kind of girlie who wants to check for error situations? here's the ritual ๐Ÿ•ฏ๏ธ: set errno to 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, then bestie... an error has occurred. ๐Ÿ˜ญ


๐Ÿ’€ RETURN VALUE ๐Ÿ’€

okay this is the long one, grab a snack ๐Ÿ“

upon successful completion, these functions shall return the value of x raised to the power y.

  • for finite values of x < 0, and finite non-integer values of y, a domain error shall occur and either a NaN (if representable), or an implementation-defined value shall be returned.
  • if the correct value would cause overflow, a range error shall occur and pow(), powf(), and powl() shall return ยฑHUGE_VAL, ยฑHUGE_VALF, and ยฑHUGE_VALL, respectively, with the same sign as the correct value of the function.
  • if the correct value would cause underflow, and is not representable, a range error may occur, and pow(), powf(), and powl() shall return 0.0, or (if IEC 60559 Floating-Point is not supported) an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN, respectively.
  • for y < 0, if x is zero, a pole error may occur and pow(), powf(), and powl() shall return ยฑHUGE_VAL, ยฑHUGE_VALF, and ยฑHUGE_VALL, respectively. on systems that support the IEC 60559 Floating-Point option, if x is ยฑ0, a pole error shall occur and pow(), powf(), and powl() shall return ยฑHUGE_VAL, ยฑHUGE_VALF, and ยฑHUGE_VALL, respectively if y is an odd integer, or HUGE_VAL, HUGE_VALF, and HUGE_VALL, respectively if y is not an odd integer.
  • if x or y is a NaN, a NaN shall be returned (unless specified elsewhere in this description). ๐Ÿ™ˆ
  • for any value of y (including NaN), if x is +1, 1.0 shall be returned.
  • for any value of x (including NaN), if y is ยฑ0, 1.0 shall be returned.
  • for any odd integer value of y > 0, if x is ยฑ0, ยฑ0 shall be returned.
  • for y > 0 and not an odd integer, if x is ยฑ0, +0 shall be returned.
  • if x is -1, and y is ยฑInf, 1.0 shall be returned.
  • for |x| < 1, if y is -Inf, +Inf shall be returned.
  • for |x| > 1, if y is -Inf, +0 shall be returned.
  • for |x| < 1, if y is +Inf, +0 shall be returned.
  • for |x| > 1, if y is +Inf, +Inf shall be returned.
  • for y an odd integer < 0, if x is -Inf, -0 shall be returned.
  • for y < 0 and not an odd integer, if x is -Inf, +0 shall be returned.
  • for y an odd integer > 0, if x is -Inf, -Inf shall be returned.
  • for y > 0 and not an odd integer, if x is -Inf, +Inf shall be returned.
  • for y < 0, if x is +Inf, +0 shall be returned.
  • for y > 0, if x is +Inf, +Inf shall be returned.
  • if the correct value would cause underflow, and is representable, a range error may occur and the correct value shall be returned.

like. that's a whole mood board of infinities and zeros. obsessed. ๐Ÿ’…


๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

these functions shall fail if:

  • Domain Error โ€” the value of x is negative and y is a finite non-integer.
    • if the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno shall be set to [EDOM].
    • if the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception shall be raised.
  • Pole Error โ€” the value of x is zero and y is negative.
    • 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 divide-by-zero floating-point exception shall be raised.
  • 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:

  • Pole Error โ€” the value of x is zero and y is negative.
    • 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 divide-by-zero floating-point exception shall be raised.
  • Range Error โ€” the result underflows.
    • 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.
yes the pole error shows up in both lists. that's not a typo, that's canon, and I'm not editing the source material bestie ๐Ÿซถ

oh and heads up: the following sections are informative. so like, no pressure, but here they come anyway.


๐ŸŒˆ EXAMPLES ๐ŸŒˆ

None. ๐Ÿ˜ญ not a single example. the girls gave us nothing. it's giving mysterious.


๐Ÿ’œ APPLICATION USAGE ๐Ÿ’œ

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. them's the rules. โญ


๐ŸŽ€ RATIONALE ๐ŸŽ€

None. iconic of them honestly.


๐Ÿงš FUTURE DIRECTIONS ๐Ÿงš

None. the future is a mystery, we stan a blank slate โœจ


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

  • exp()
  • feclearexcept()
  • fetestexcept()
  • isnan()

and from the Base Definitions volume of POSIX.1โ€2017:

  • Section 4.20, Treatment of Error Conditions for Mathematical Functions
  • <math.h>

so, legal girlie moment, don't skip this part:

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


and that's the whole page bestie!! ๐Ÿซถ this one came to you courtesy of IEEE/The Open Group, 2017 โ€” so when you see POW(3POSIX) in your man pages, you know exactly whose name is on it ๐Ÿ’…โœจ slay, go raise some numbers to some powers responsibly ๐ŸŒธ๐Ÿ’–

๐Ÿ“ฆ where this page comes from