Namespaces
Variants
Views
Actions

acos

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       acosf( float arg );
(since C99)
double      acos( double arg );
long double acosl( long double arg );
(since C99)

Computes arc cosine of arg

Contents

[edit] Parameters

arg - floating point value

[edit] Return value

Arc cosine of arg in radians in the range of [0; π] radians.

Domain error occurs if arg is outside the range [-1.0; 1.0]. NaN is returned in that case and FE_INVALID is raised.

acos(1) returns +0.

[edit] Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
#define PI acos(-1)
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    printf("acos(+0.0) = %f\n",   acos(+0.0));
    printf("acos(-0.0) = %f\n",   acos(-0.0));
    printf("acos(1.0)  = %.1f\n", acos(1.0));
    printf("acos(NAN)  = %.1f\n", acos(NAN));
    printf("\n");
 
    /* domain error                       */
    /* "invalid" floating-point exception */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("acos(1.1)  = %f\n", acos(1.1));
    printf("%s\n",strerror(errno));
    show_fe_exceptions();
 
    return 0;
}

Possible output:

acos(+0.0) = 1.570796
acos(-0.0) = 1.570796
acos(1.0)  = 0.0
acos(NAN)  = nan
 
acos(1.1)  = nan
Numerical argument out of domain
current exceptions raised:  FE_INVALID

[edit] See also

computes arc sine (arcsin(x))
(function) [edit]
computes arc tangent (arctan(x))
(function) [edit]
arc tangent, using signs to determine quadrants
(function) [edit]
computes cosine (cos(x))
(function) [edit]