Namespaces
Variants

tan, tanf, tanl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
定義済みヘッダー <math.h>
float tanf ( float arg ) ;
(1) (C99以降)
double tan ( double arg ) ;
(2)
long double tanl ( long double arg ) ;
(3) (C99以降)
_Decimal32  tand32 ( _Decimal32 arg ) ;
(4) (C23以降)
_Decimal64  tand64 ( _Decimal64 arg ) ;
(5) (C23以降)
_Decimal128 tand128 ( _Decimal128 arg ) ;
(6) (C23以降)
定義済みヘッダー <tgmath.h>
#define tan( arg )
(7) (C99以降)
1-6) ラジアン単位で測定された arg のタンジェントを計算します。
7) 型総称マクロ: 引数の型が long double の場合、 (3) ( tanl )が呼び出される。それ以外の場合、引数が整数型または double 型を持つ場合は、 (2) ( tan )が呼び出される。それ以外の場合は、 (1) ( tanf )が呼び出される。引数が複素数の場合、マクロは対応する複素数関数( ctanf , ctan , ctanl )を呼び出す。

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

(C23以降)

目次

パラメータ

arg - ラジアン単位の角度を表す浮動小数点値

戻り値

エラーが発生しない場合、 arg の正接( tan(arg) )が返されます。

arg の大きさが大きい場合、結果はほとんど意味を持たないか、全く意味を持たない可能性があります。

(C99まで)

定義域エラーが発生した場合、実装定義の値が返されます(NaNがサポートされている場合はNaN)。

アンダーフローによる範囲エラーが発生した場合、正しい結果(丸め後)が返されます。

エラーハンドリング

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

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

  • 引数が±0の場合、変更されずに返されます;
  • 引数が±∞の場合、NaNが返され、 FE_INVALID が発生します;
  • 引数がNaNの場合、NaNが返されます。

注記

引数が無限大の場合、C言語では定義域エラーと規定されていないが、 POSIXでは定義域エラー として定義されている。

この関数は π(1/2 + n) に数学的な極を持つが、一般的な浮動小数点表現では π/2 を正確に表現できないため、極エラーが発生する引数の値は存在しない。

#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
#ifndef __GNUC__
#pragma STDC FENV_ACCESS ON
#endif
int main(void)
{
    const double pi = acos(-1);
    // 典型的な使用例
    printf("tan(pi*1/4) = %+f\n", tan(pi * 1 / 4)); //   45度
    printf("tan(pi*3/4) = %+f\n", tan(pi * 3 / 4)); //  135度
    printf("tan(pi*5/4) = %+f\n", tan(pi * 5 / 4)); // -135度
    printf("tan(pi*7/4) = %+f\n", tan(pi * 7 / 4)); //  -45度
    // 特殊な値
    printf("tan(+0) = %f\n", tan(0.0));
    printf("tan(-0) = %f\n", tan(-0.0));
    // エラー処理
    feclearexcept(FE_ALL_EXCEPT);
    printf("tan(INFINITY) = %f\n", tan(INFINITY));
    if (fetestexcept(FE_INVALID))
        puts("    FE_INVALID raised");
}

出力例:

tan(pi*1/4) = +1.000000
tan(pi*3/4) = -1.000000
tan(pi*5/4) = +1.000000
tan(pi*7/4) = -1.000000
tan(+0) = 0.000000
tan(-0) = -0.000000
tan(INFINITY) = -nan
    FE_INVALID raised

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.4.7 tan関数群 (p: TBD)
  • 7.25 総称型数学 <tgmath.h> (p: TBD)
  • F.10.1.7 tan関数群 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.4.7 tan関数群 (p: 175)
  • 7.25 総称数学 <tgmath.h> (p: 272-273)
  • F.10.1.7 tan関数群 (p: 378)
  • C11標準 (ISO/IEC 9899:2011):
  • 7.12.4.7 tan関数群 (p: 240)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.1.7 tan関数群 (p: 519)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.4.7 tan関数群 (p: 220)
  • 7.22 型総称数学 <tgmath.h> (p: 335-337)
  • F.9.1.7 tan関数群 (p: 457)
  • C89/C90標準 (ISO/IEC 9899:1990):
  • 4.5.2.7 tan関数

関連項目

(C99) (C99)
正弦を計算する ( sin(x) )
(関数)
(C99) (C99)
余弦を計算する ( cos(x) )
(関数)
(C99) (C99)
逆正接を計算する ( arctan(x) )
(関数)
(C99) (C99) (C99)
複素正接を計算する
(関数)