1. 程式人生 > 實用技巧 >acosl (Numerics) – C 中文開發手冊

acosl (Numerics) – C 中文開發手冊

[
  •   C 語言中文開發手冊

    acosl (Numerics) - C 中文開發手冊

    在標頭檔案<math.h>中定義
    float acosf( float arg ); (1) (since C99)
    double acos( double arg ); (2)
    long double acosl( long double arg ); (3) (since C99)
    Defined in header <tgmath.h>
    #define acos( arg ) (4) (since C99)

    1-3)計算反餘弦的主值arg。4)型別 - 通用巨集:如果引數具有型別long double,acosl則被呼叫。否則,如果引數具有整數型別或型別double,acos則呼叫該引數。否則,acosf被呼叫。如果引數是複雜的,則巨集呼叫相應的複變函式(cacosf,cacos,cacosl)。

    引數

    arg - 浮點值

    返回值

    如果沒有錯誤發生,arg則範圍為0 的(arccos(arg))的反餘弦值為0; π,返回。如果發生域錯誤,則返回實現定義的值(NaN,如果支援)。如果由於下溢而發生範圍錯誤,則返回正確的結果(舍入後)。

    錯誤處理

    按照math_errhandling中的指定報告錯誤。如果arg超出範圍,則會發生域錯誤[-1.0; 1.0]。如果實現支援IEEE浮點運算(IEC 60559),如果引數為+1,+0則返回該值。如果| arg | > 1,發生域錯誤並返回NaN。如果引數是NaN,則返回NaN

    #include <stdio.h>
    #include <math.h>
    #include <errno.h>
    #include <fenv.h>
    #include <string.h>
     
    #pragma STDC FENV_ACCESS ON
    int main(void)
    {
        printf("acos(-1) = %f\n", acos(-1));
        printf("acos(0.0) = %f 2*acos(0.0) = %f\n", acos(0), 2*acos(0));
        printf("acos(0.5) = %f 3*acos(0.5) = %f\n", acos(0.5), 3*acos(0.5));
        printf("acos(1) = %f\n", acos(1));
        // error handling 
        errno = 0; feclearexcept(FE_ALL_EXCEPT);
        printf("acos(1.1) = %f\n", acos(1.1));
        if(errno == EDOM) perror("    errno == EDOM");
        if(fetestexcept(FE_INVALID)) puts("    FE_INVALID raised");
    }

    可能的輸出:

    acos(-1) = 3.141593
    acos(0.0) = 1.570796 2*acos(0.0) = 3.141593
    acos(0.5) = 1.047198 3*acos(0.5) = 3.141593
    acos(1) = 0.000000
    acos(1.1) = nan
        errno == EDOM: Numerical argument out of domain
        FE_INVALID raised

    參考

    C11標準(ISO / IEC 9899:2011): 7.12.4.1阿科斯函式(p:238) 7.25型別通用數學<tgmath.h>(p:373-375) F.10.1.1 acos功能(p:518) C99標準(ISO / IEC 9899:1999): 7.12.4.1 acos功能(p:218) 7.22型別通用數學<tgmath.h>(p:335-337) F.9.1.1 acos功能(p:455) C89 / C90標準(ISO / IEC 9899:1990): 4.5.2.1 acos函式

  •   C 語言中文開發手冊
    ]
  •   本文標題:acosl (Numerics) – C 中文開發手冊 - Break易站轉載請保留頁面地址:https://www.breakyizhan.com/c-3/26759.html