cos(3)

๐Ÿ’– cos(3) โ€” like, the cosine function, bestie ๐Ÿ’–

okay so this is page cos(3) from the Library Functions Manual, and we're about to get SO cozy with trigonometry. pull up a chair. ๐ŸŽ€


โœจ NAME โœจ

cos, cosf, cosl โ€” cosine function ๐ŸŒŠ

๐Ÿ“š LIBRARY ๐Ÿ“š

Math library (libm, link it with -lm) โ€” yeah you gotta actually link it, don't @ me when it doesn't compile ๐Ÿ’…

๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <math.h>

double cos(double x);
float cosf(float x);
long double cosl(long double x);

๐Ÿฆ‹ Feature Test Macro Requirements for glibc ๐Ÿฆ‹

(peep feature_test_macros(7) if you wanna know what these are, iykyk)

cosf(), cosl():

_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
    || /* Since glibc 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

like, you need ALL of that or she simply will not exist for you. the audacity. ๐Ÿ˜ญ


๐Ÿ’ซ DESCRIPTION ๐Ÿ’ซ

These functions return the cosine of x, where x is given in radians. that's it. that's the whole vibe. radians only, bestie โ€” if you hand her degrees she's gonna be real confused and it's gonna be wrong and it's gonna be your fault ๐Ÿ™ˆ

๐Ÿซถ RETURN VALUE ๐Ÿซถ

On success, these functions return the cosine of x. slay. โœจ

  • If x is a NaN, a NaN is returned. (NaN in, NaN out, iconic behaviour honestly)
  • If x is positive infinity or negative infinity, a domain error occurs, and a NaN is returned. infinity is not on the guest list for this function fr fr ๐Ÿ’€

๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

Go read math_error(7) for the whole scoop on how to figure out whether an error happened when you called these. detective work. ๐Ÿ”

The following errors can occur:

๐Ÿšจ Domain error: x is an infinity ๐Ÿšจ

errno is set to EDOM (but see BUGS โ€” there's a lil plot twist down there). An invalid floating-point exception (FE_INVALID) is raised.

lowkey important: yes you read that right, EDOM. write it down.

๐Ÿ‘‘ ATTRIBUTES ๐Ÿ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • cos(), cosf(), cosl() โ€” Thread safety โ€” MT-Safe ๐Ÿ’…โœ…

(translation: she's safe to use from multiple threads, go wild, you're fine)

โญ STANDARDS โญ

C11, POSIX.1-2008. certified. stamped. approved. ๐ŸŽ€

๐ŸŒˆ HISTORY ๐ŸŒˆ

C89, POSIX.1-2001. she's been around. she's a legend. she's been doing this since before your parents had phones.

The variant returning double also conforms to SVr4, 4.3BSD.

๐Ÿ’€ BUGS ๐Ÿ’€

Before glibc 2.10, the glibc implementation did not set errno to EDOM when a domain error occurred. so if you're on some ancient glibc, don't trust errno, she's lying to you. that's the tea. ๐Ÿต

๐Ÿงš SEE ALSO ๐Ÿงš

acos(3), asin(3), atan(3), atan2(3), ccos(3), sin(3), sincos(3), tan(3)


and that's the whole page bestie!! ๐Ÿ’– this one's from Linux man-pages 6.20, dated 2026-02-08 โ€” go forth and compute your cosines, radians ONLY, and remember: you're the main character of your own trig โœจ๐Ÿฆ‹๐Ÿ’…

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms