# ccosf, ccos, ccosl

> C++ Atlas: `cppatlas.com/w/c/numeric/complex/ccos` | Source: https://en.cppreference.com/w/c/numeric/complex/ccos | Domain: Numerics | Standards: C99

If no errors occur, the complex cosine of z is returned.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <complex.h>
float complex       ccosf( float complex z ); // (1) (since C99)
double complex      ccos( double complex z ); // (2) (since C99)
long double complex ccosl( long double complex z ); // (3) (since C99)
// Defined in header <tgmath.h>
#define cos( z ) // (4) (since C99)
```

1-3) Computes the complex cosine of `z`.

4) Type-generic macro: If `z` has type `long double complex`, `ccosl` is called. if `z` has type `double complex`, `ccos` is called, if `z` has type `float complex`, `ccosf` is called. If `z` is real or integer, then the macro invokes the corresponding real function (`cosf`, `cos`, `cosl`). If `z` is imaginary, then the macro invokes the corresponding real version of the function `cosh`, implementing the formula cos(iy) = cosh(y), and the return type is real.

### Parameters

- `z` - complex argument

### Return value

If no errors occur, the complex cosine of `z` is returned.

Errors and special cases are handled as if the operation is implemented by `ccosh(I*z)`.

### Notes

The cosine is an entire function on the complex plane, and has no branch cuts.

Mathematical definition of the cosine is

cos z = e^(iz)+e^(-iz)
2

### Example

```c
#include <stdio.h>
#include <math.h>
#include <complex.h>

int main(void)
{
    double complex z = ccos(1);  // behaves like real cosine along the real line
    printf("cos(1+0i) = %f%+fi ( cos(1)=%f)\n", creal(z), cimag(z), cos(1));

    double complex z2 = ccos(I); // behaves like real cosh along the imaginary line
    printf("cos(0+1i) = %f%+fi (cosh(1)=%f)\n", creal(z2), cimag(z2), cosh(1));
}
```

Output:

```text
cos(1+0i) = 0.540302-0.000000i ( cos(1)=0.540302)
cos(0+1i) = 1.543081-0.000000i (cosh(1)=1.543081)
```

### References

- C11 standard (ISO/IEC 9899:2011):

  - 7.3.5.4 The ccos functions (p: 191)

  - 7.25 Type-generic math \<tgmath.h> (p: 373-375)

  - G.7 Type-generic math \<tgmath.h> (p: 545)

- C99 standard (ISO/IEC 9899:1999):

  - 7.3.5.4 The ccos functions (p: 173)

  - 7.22 Type-generic math \<tgmath.h> (p: 335-337)

  - G.7 Type-generic math \<tgmath.h> (p: 480)

### See also

- [`csin`](https://en.cppreference.com/w/c/numeric/complex/csin) (C99), [`csinf`](https://en.cppreference.com/w/c/numeric/complex/csin) (C99), [`csinl`](https://en.cppreference.com/w/c/numeric/complex/csin) (C99): computes the complex sine (function)
- [`ctan`](https://en.cppreference.com/w/c/numeric/complex/ctan) (C99), [`ctanf`](https://en.cppreference.com/w/c/numeric/complex/ctan) (C99), [`ctanl`](https://en.cppreference.com/w/c/numeric/complex/ctan) (C99): computes the complex tangent (function)
- [`cacos`](https://en.cppreference.com/w/c/numeric/complex/cacos) (C99), [`cacosf`](https://en.cppreference.com/w/c/numeric/complex/cacos) (C99), [`cacosl`](https://en.cppreference.com/w/c/numeric/complex/cacos) (C99): computes the complex arc cosine (function)
- [`cos`](https://en.cppreference.com/w/c/numeric/math/cos), [`cosf`](https://en.cppreference.com/w/c/numeric/math/cos) (C99), [`cosl`](https://en.cppreference.com/w/c/numeric/math/cos) (C99): computes cosine (cos(x)) (function)
- [C++ documentation for `cos`](https://en.cppreference.com/w/cpp/numeric/complex/cos)

---
Attribution: content from https://en.cppreference.com/w/c/numeric/complex/ccos (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.