Format
#include <math.h> double acos(double x);
Language Level: ANSI
Threadsafe: Yes.
Description
The acos() function calculates the arccosine of x, expressed in radians, in the range 0 to&Pi..
Return Value
The acos() function returns the arccosine of x. The value of x must be between -1 and 1 inclusive. If x is less than -1 or greater than 1, acos() sets errno to EDOM and returns 0.
Example that uses acos()
This example prompts for a value for x. It prints an error message if x is greater than 1 or less than -1; otherwise, it assigns the arccosine of x to y.
#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 1.0 #define MIN -1.0 int main(void) { double x, y; printf( "Enter x\n" ); scanf( "%lf", &x ); /* Output error if not in range */ if ( x > MAX ) printf( "Error: %lf too large for acos\n", x ); else if ( x < MIN ) printf( "Error: %lf too small for acos\n", x ); else { y = acos( x ); printf( "acos( %lf ) = %lf\n", x, y ); } } /******* Expected output if 0.4 is entered: ********* Enter x acos( 0.400000 ) = 1.159279 */
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.