SIN(3POSIX)

🌸 SIN(3POSIX) β€” the POSIX Programmer's Manual, but make it a group chat 🌸

okay bestie, welcome to SIN(3POSIX), straight out of the POSIX Programmer's Manual. this is the sine function and she is iconic. buckle up πŸŽ€


⚠️ PROLOG (read this first, fr)

so like… this manual page is part of the POSIX Programmer's Manual. but heads up πŸ‘‘ β€” the Linux implementation of this interface may differ, so if you're on Linux pls consult the corresponding Linux manual page for the deets on Linux behavior. or, plot twist, the interface might not even be implemented on Linux at all. πŸ’€


✨ NAME ✨

sin, sinf, sinl β€” the sine function πŸ¦‹


πŸ’… SYNOPSIS πŸ’…

#include <math.h>

double sin(double x);
float sinf(float x);
long double sinl(long double x);

🌈 DESCRIPTION 🌈

the functionality described 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, no cap. this volume of POSIX.1‐2017 defers to the ISO C standard, periodt.

these functions shall compute the sine of their argument x, and x is measured in radians btw (not degrees, bestie, do not come at me with degrees).

ok so if your app wants to actually check for error situations, here's the vibe check you gotta do: 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 β€” an error has occurred. πŸ™ˆ


⭐ RETURN VALUE ⭐

upon successful completion, these functions shall return the sine of x. slay.

  • if x is NaN, a NaN shall be returned. (garbage in, garbage out, but make it ✨formal✨)
  • if x is Β±0, x shall be returned. (zero is zero, she's consistent)
  • if x is subnormal, a range error may occur and x should be returned.
  • if x is not returned, sin(), sinf(), and sinl() shall return an implementation-defined value no greater in magnitude than DBL_MIN, FLT_MIN, and LDBL_MIN, respectively.
  • if x is Β±Inf, a domain error shall occur, and a NaN shall be returned. 🚨

πŸ’– ERRORS πŸ’–

these functions shall fail if:

Domain Error 🚩

the x argument is Β±Inf.

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.

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.

also jsyk: the following sections are informative. they're the bonus content, not the rules. 🫢

πŸŽ€ EXAMPLES πŸŽ€

πŸ“ Taking the Sine of a 45-Degree Angle πŸ“

#include <math.h>
...
double radians = 45.0 * M_PI / 180;
double result;
...
result = sin(radians);

look at her go. converting degrees to radians and everything. main character energy. πŸ‘‘


🧚 APPLICATION USAGE 🧚

these functions may lose accuracy when their argument is near a multiple of Ο€ or is far from 0.0. so like… be mindful, bestie, floating point is a hater sometimes. 😭

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. no skipping out of both, that's the law.


πŸ’€ RATIONALE πŸ’€

None.

(yeah. nothing. she said what she said. πŸ™ˆ)


🌟 FUTURE DIRECTIONS 🌟

None.

(the future is… unchanged. lowkey refreshing.)


πŸ”₯ SEE ALSO πŸ”₯

  • asin()
  • feclearexcept()
  • fetestexcept()
  • isnan()

the Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of Error Conditions for Mathematical Functions, <math.h>


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 .


okay that's the whole page, you're all caught up πŸ’– this one came to you from IEEE/The Open Group, 2017, filed under SIN(3POSIX) β€” go forth and compute some sines, bestie, you got this βœ¨πŸ¦‹πŸ’