1COS(3P) POSIX Programmer's Manual COS(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 cos, cosf, cosl — cosine function
14
16 #include <math.h>
17
18 double cos(double x);
19 float cosf(float x);
20 long double cosl(long double x);
21
23 The functionality described on this reference page is aligned with the
24 ISO C standard. Any conflict between the requirements described here
25 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
26 defers to the ISO C standard.
27
28 These functions shall compute the cosine of their argument x, measured
29 in radians.
30
31 An application wishing to check for error situations should set errno
32 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
33 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
34 FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
35 occurred.
36
38 Upon successful completion, these functions shall return the cosine of
39 x.
40
41 If x is NaN, a NaN shall be returned.
42
43 If x is ±0, the value 1.0 shall be returned.
44
45 If x is ±Inf, a domain error shall occur, and a NaN shall be returned.
46
48 These functions shall fail if:
49
50 Domain Error
51 The x argument is ±Inf.
52
53 If the integer expression (math_errhandling & MATH_ERRNO)
54 is non-zero, then errno shall be set to [EDOM]. If the
55 integer expression (math_errhandling & MATH_ERREXCEPT) is
56 non-zero, then the invalid floating-point exception shall
57 be raised.
58
59 The following sections are informative.
60
62 Taking the Cosine of a 45-Degree Angle
63 #include <math.h>
64 ...
65 double radians = 45 * M_PI / 180;
66 double result;
67 ...
68 result = cos(radians);
69
71 These functions may lose accuracy when their argument is near an odd
72 multiple of π/2 or is far from 0.
73
74 On error, the expressions (math_errhandling & MATH_ERRNO) and
75 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
76 at least one of them must be non-zero.
77
79 None.
80
82 None.
83
85 acos(), feclearexcept(), fetestexcept(), isnan(), sin(), tan()
86
87 The Base Definitions volume of POSIX.1‐2008, Section 4.19, Treatment of
88 Error Conditions for Mathematical Functions, <math.h>
89
91 Portions of this text are reprinted and reproduced in electronic form
92 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
93 -- Portable Operating System Interface (POSIX), The Open Group Base
94 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
95 cal and Electronics Engineers, Inc and The Open Group. (This is
96 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
97 event of any discrepancy between this version and the original IEEE and
98 The Open Group Standard, the original IEEE and The Open Group Standard
99 is the referee document. The original Standard can be obtained online
100 at http://www.unix.org/online.html .
101
102 Any typographical or formatting errors that appear in this page are
103 most likely to have been introduced during the conversion of the source
104 files to man page format. To report such errors, see https://www.ker‐
105 nel.org/doc/man-pages/reporting_bugs.html .
106
107
108
109IEEE/The Open Group 2013 COS(3P)