acos
, acosf
, acosl
計算反餘弦值。
語法
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
參數
x
介於 -1 和 1 之間的值,用來計算反余弦值(反余弦值)。
傳回值
acos
函式會傳回 0 到 π 弧度之間的 x
反餘弦值。
根據預設,如果 x
小於 -1 或大於 1, acos
則會傳回無限期。
輸入 | SEH 例外狀況 | _matherr 例外 |
---|---|---|
± INF | INVALID |
_DOMAIN |
± QNaN,IND | none | _DOMAIN |
|x| > 1 |
INVALID |
_DOMAIN |
備註
因為 C++ 允許多載,所以您可以呼叫採用並傳回 acos
和 float
類型的 long double
的多載。 在 C 程式中,除非您使用 <tgmath.h>
宏來呼叫此函式, acos
否則一律會採用 並傳 double
回 。
如果您使用 中的 acos
<tgmath.h>
宏,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學 。
根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
常式 | 必要的標頭 | 選擇性標頭 |
---|---|---|
acos , acosf , acosl |
<math.h> |
<errno.h> |
acos 宏觀 |
<tgmath.h> |
範例
此程式會提示範圍介於 -1 到 1 的值。 輸入此範圍外的值會產生 _DOMAIN
錯誤訊息。 如果輸入有效的值,則程式會列印該值的反正弦值及反餘弦值。
// 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
另請參閱
數學和浮點支援
asin
, asinf
, asinl
atan
, atanf
, atanl
, atan2
, atan2f
, atan2l
cos
, cosf
, cosl
_matherr
sin
, sinf
, sinl
tan
, tanf
, tanl
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應