C acos () - C Standardbibliotek

Funktionen acos () returnerar bågen cosinus (invers cosinus) för ett tal i radianer.

Den acos()funktionen tar ett enda argument (en ≧ x ≧ -1), och återgår arcus cosinus i radianer.

Den acos()funktionen finns i header-fil.

acos () Prototyp

 dubbel acos (dubbel x);

För att hitta bågkosinus av typen int, floateller long double, kan du uttryckligen konvertera typen till att doubleanvända cast-operator.

int x = 0; dubbelt resultat; resultat = acos (dubbel (x));

Också, två funktioner acosf () och acosl () infördes i C99 att arbeta specifikt med typ floatoch long doublerespektive.

float acosf (float x); lång dubbel acosl (lång dubbel x);

acos () Parameter

Den acos()funktionen tar ett enda argument i intervallet (-1, 1). Det beror på att värdet av cosinus ligger i området 1 och -1.

Parameter Beskrivning
dubbelt värde Nödvändig. Ett dubbelt värde mellan - 1 och +1 inklusive.

acos () Returvärde

De acos()funktioner returnerar värdet i intervallet (0,0, π) i radianer. Om parametern som skickas till acos()funktionen är mindre än -1 eller större än 1, returnerar funktionen NaN (inte ett tal).

Parameter (x) Returvärde
x = (-1, +1) (0, π) i radianer
-1> x eller x> 1 NaN (inte ett nummer)

Exempel 1: acos () -funktion med olika parametrar

 #include #include int main() ( // constant PI is defined const double PI = 3.1415926; double x, result; x = -0.5; result = acos(x); printf("Inverse of cos(%.2f) = %.2lf in radians", x, result); // converting radians to degree result = acos(x)*180/PI; printf("Inverse of cos(%.2f) = %.2lf in degrees", x, result); // paramter not in range x = 1.2; result = acos(x); printf("Inverse of cos(%.2f) = %.2lf", x, result); return 0; )

Produktion

 Invers av cos (-0,50) = 2,09 i radianer Invers av cos (-0,50) = 120,00 i grader Invers av cos (1,20) = nan 

Exempel 2: funktion acosf () och acosl ()

 #include #include int main() ( float fx, facosx; long double lx, ldacosx; // arc cosine of type float fx = -0.505405; facosx = acosf(fx); // arc cosine of type long double lx = -0.50540593; ldacosx = acosf(lx); printf("acosf(x) = %f in radians", facosx); printf("acosl(x) = %Lf in radians", ldacosx); return 0; )

Produktion

 acosf (x) = 2.100648 i radianer acosl (x) = 2.100649 i radianer 

Intressanta artiklar...