名前空間
変種
操作

cospi、cospif、cospil、cospid32、cospid64、cospid128

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
共通の数学関数
関数
基本的な数学関数
(C99)
(C99)
(C99)
(C99)(C99)(C99)(C23)
最大/最小演算
(C99)
(C99)
指数関数
(C23)
(C99)
(C99)
(C23)
(C23)

(C99)
(C99)(C23)
(C23)
(C23)
べき乗関数
(C99)
(C23)
(C23)

(C99)
(C23)
(C23)
三角関数と双曲線関数
(C23)
cospi
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
(C99)
(C99)
(C99)
最も近い整数浮動小数点数
(C99)(C99)(C99)
(C99)

(C99)(C99)(C99)
(C23)(C23)(C23)(C23)
浮動小数点操作
(C99)(C99)
(C99)(C23)
(C99)
縮小演算
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
量子および量子指数
Decimal再エンコーディング関数
総順序およびペイロード関数
分類
(C99)
(C99)
(C99)
(C23)
誤差関数とガンマ関数
(C99)
(C99)
(C99)
(C99)
マクロ定数
特殊な浮動小数点値
(C99)(C23)
引数と戻り値
エラーハンドリング
高速演算インジケータ
 
ヘッダー <math.h> で定義
float       cospif( float arg );
(1) (C23以降)
double      cospi( double arg );
(2) (C23以降)
long double cospil( long double arg );
(3) (C23以降)
_Decimal32  cospid32( _Decimal32 arg );
(4) (C23以降)
_Decimal64  cospid64( _Decimal64 arg );
(5) (C23以降)
_Decimal128 cospid128( _Decimal128 arg );
(6) (C23以降)
ヘッダー <tgmath.h> で定義
#define cospi( arg )
(7) (C23以降)
1-6) π·arg のコサインをラジアン単位で計算します。これにより、arg は半回転の測定値として扱われます。
7) 型汎用マクロ: arg の型に基づいて適切な関数を呼び出します。arg が整数型の場合、(2) (cospi) が呼び出されます。

関数 (4-6) は、実装が __STDC_IEC_60559_DFP__ を事前定義している場合(つまり、実装が10進浮動小数点数をサポートしている場合)にのみ宣言されます。

(C23以降)

目次

[編集] パラメータ

arg - 浮動小数点値。この値とπの積がラジアン単位の角度を表します。

[編集] 戻り値

エラーが発生しなかった場合、π·arg (cos(π×arg)) のコサインが [-1, +1] の範囲で返されます。

[編集] エラー処理

エラーは math_errhandling で指定されたとおりに報告されます。

実装が IEEE 浮動小数点演算 (IEC 60559) をサポートしている場合

  • 引数が ±0 の場合、結果は 1.0 です。
  • 引数が ±∞ の場合、NaN が返され、FE_INVALID が発生します。
  • 引数が NaN の場合、NaN が返されます。

[編集]

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
 
#ifndef __GNUC__
#pragma STDC FENV_ACCESS ON
#endif
 
#if __STDC_VERSION__ < 202311L
// A naive implementation of a subset of cospi family
double cospi(double arg)
{
    return cos(arg * (double)3.1415926535897932384626433);
}
#endif
 
int main(void)
{
    const double pi = acos(-1);
 
    // typical usage
    printf("cospi(1) = %f, cos(pi) = %f\n", cospi(1), cos(pi));
    printf("cospi(0.5) = %f, cos(pi/2) = %f\n", cospi(0.5), cos(pi / 2));
    printf("cospi(-0.75) = %f, cos(-3*pi/4) = %f\n", cospi(-0.75), cos(-3 * pi / 4));
 
    // special values
    printf("cospi(+0) = %f\n", cospi(0.0));
    printf("cospi(-0) = %f\n", cospi(-0.0));
 
    // error handling
    feclearexcept(FE_ALL_EXCEPT);
    printf("cospi(INFINITY) = %f\n", cospi(INFINITY));
    if (fetestexcept(FE_INVALID))
        puts("    FE_INVALID raised");
}

実行結果の例

cospi(1) = -1.000000, cos(pi) = -1.000000
cospi(0.5) = 0.000000, cos(pi/2) = 0.000000
cospi(-0.75) = -0.707107, cos(-3*pi/4) = -0.707107
cospi(+0) = 1.000000
cospi(-0) = 1.000000
cospi(INFINITY) = -nan
    FE_INVALID raised

[編集] 参考文献

  • C23標準 (ISO/IEC 9899:2024)
  • 7.12.4.12 The cospi functions (p: 247)
  • 7.27 Type generic math <tgmath.h> (p: 387)

[編集] 関連項目

(C99)(C99)
コサインを計算する (cos(x))
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)