Skip to content

Latest commit

 

History

History
118 lines (90 loc) · 3.75 KB

acos-acosf-acosl.md

File metadata and controls

118 lines (90 loc) · 3.75 KB
title description ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords
acos, acosf, acosl
API reference for acos, acosf, and acosl; which calculate the arccosine of a floating-point value.
1/15/2021
acosf
acos
acosl
_o_acos
_o_acosf
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-private-l1-1-0.dll
DLLExport
apiref
acos
acosl
acosf
math/acosf
math/acosl
acos function
acosl function
acosf function
trigonometric functions
arccosine function

acos, acosf, acosl

Calculates the arccosine.

Syntax

double acos( double x );
float acosf( float x );
long double acosl( long double x );
#define acos(X) // Requires C11 or higher

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

Parameters

x
Value between -1 and 1, for which to calculate the arccosine (the inverse cosine).

Return Value

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

By default, if x is less than -1 or greater than 1, acos returns an indefinite.

Input SEH exception Matherr exception
± ∞ INVALID _DOMAIN
± QNAN, IND none _DOMAIN
|x|>1 INVALID _DOMAIN

Remarks

Because C++ allows overloading, you can call overloads of acos that take and return float and long double types. In a C program, unless you're using the <tgmath.h> macro to call this function, acos always takes and returns a double.

If you use the <tgmath.h> acos() macro, the type of the argument determines which version of the function is selected. See Type-generic math for details.

By default, this function's global state is scoped to the application. To change this, see Global state in the CRT.

Requirements

Routine Required header Optional headers
acos, acosf, acosl <math.h> <errno.h>
acos() macro <tgmath.h>

Example

This program prompts for a value in the range -1 to 1. Input values outside this range 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 );
}
Arcsine of 0.000000 = 0.000000
Arccosine of 0.000000 = 1.570796

See also

Floating-Point Support
asin, asinf, asinl
atan, atanf, atanl, atan2, atan2f, atan2l
cos, cosf, cosl
_matherr
sin, sinf, sinl
tan, tanf, tanl