C acos () - C Standard Library

De functie acos () retourneert de boogcosinus (inverse cosinus) van een getal in radialen.

De acos()functie accepteert één argument (1 ≧ x ≧ -1) en geeft de boogcosinus in radialen terug.

De acos()functie is opgenomen in het header-bestand.

acos () Prototype

 dubbele acos (dubbele x);

Om erachter te arccosinus van het type int, floatof long double, kunt u expliciet converteren het type om doublemet behulp van cast operator.

int x = 0; dubbel resultaat; resultaat = acos (dubbel (x));

Ook werden twee functies acosf () en acosl () geïntroduceerd in C99 om specifiek te werken met respectievelijk type floaten long double.

float acosf (float x); lange dubbele acosl (lange dubbele x);

acos () Parameter

De acos()functie heeft een enkel argument in het bereik van (-1, +1). Dit komt omdat de waarde van cosinus in het bereik van 1 en -1 ligt.

Parameter Omschrijving
dubbele waarde Verplicht. Een dubbele waarde tussen - 1 en +1 inclusief.

acos () Retourwaarde

De acos()functie retourneert de waarde in het bereik van (0,0, π) in radialen. Als de parameter die aan de acos()functie wordt doorgegeven, kleiner is dan -1 of groter dan 1, retourneert de functie NaN (geen getal).

Parameter (x) Winstwaarde
x = (-1; +1) (0, π) in radialen
-1> x of x> 1 NaN (geen nummer)

Voorbeeld 1: acos () functie met verschillende parameters

 #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; )

Uitvoer

 Inverse van cos (-0,50) = 2,09 in radialen Inverse van cos (-0,50) = 120,00 in graden Inverse van cos (1,20) = nan 

Voorbeeld 2: acosf () en acosl () functie

 #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; )

Uitvoer

 acosf (x) = 2.100648 in radialen acosl (x) = 2.100649 in radialen 

Interessante artikelen...