Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
acos, acosf
div
eof
Collapse the table of content
Expand the table of content

acos, acosf 

Calculate the arccosine.


double acos( 
   double x 
);
float acos(
   float x 
);   // C++ only
long double acos(
   long double x
);   // C++ only
float acosf(
   float x 
);

Parameters

x

Value between –1 and 1 whose arccosine is to be calculated.

The acos function returns the arccosine of x in the range 0 to π radians.

If x is less than –1 or greater than 1, acos returns an indefinite by default.

Input SEH Exception Matherr Exception

± ∞

INVALID

_DOMAIN

± QNAN,IND

none

_DOMAIN

|x|>1

INVALID

_DOMAIN

C++ allows overloading, so you can call overloads of acos. In a C program, acos always takes and returns a double.

Routine Required header Optional headers Compatibility

acos, acosf

<math.h>

<errno.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

This program prompts for a value in the range -1 to 1. Input values outside this range will produce _DOMAIN error messages. If a valid value is entered, the program prints the arcsine and the arccosine of that value.

// crt_asincos.c
// arguments: 0

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main( int ac, char* av[] )
{
    double  x,
            y;
    errno_t err; 

    // argument checking
    if (ac != 2)
    {
        fprintf_s( stderr, "Usage: %s <number between -1 and 1>\n",
                   av[0]);
        return 1;
    }

    // Convert argument into a double value
    if ((err = sscanf_s( av[1], "%lf", &x )) != 1)
    {
        fprintf_s( stderr, "Error converting argument into ",
                   "double value.\n");
        return 1;
    }

    // Arcsine of X
    y = asin( x );
    printf_s( "Arcsine of %f = %f\n", x, y );

    // Arccosine of X
    y = acos( x );
    printf_s( "Arccosine of %f = %f\n", x, y );
}

Output

Arcsine of 0.000000 = 0.000000
Arccosine of 0.000000 = 1.570796

Community Additions

ADD
Show:
© 2015 Microsoft