The atan functions - atan, atanf, atanl

逆正接 (arctan) を計算します.

atan

#include <math.h>
double atan(
    double x
);

atan 関数は x の逆正接 (arctan) を計算し,結果を double 型で返します.

atanf (C99)

#include <math.h>
float atanf(
    float x
);

atanf 関数は x の逆正接 (arctan) を計算し,結果を float 型で返します.

atanl (C99)

#include <math.h>
long double atanl(
    long double x
);

atanl 関数は x の逆正接 (arctan) を計算し,結果を long double 型で返します.

戻り値

  • 区間 [-pi/2, +pi/2]ラジアンの逆正接値

数学上の表記

arctan

C言語サンプルプログラム

以下に atan,atanf,atanl 関数それぞれを使用して逆正接を求めるサンプルプログラムを示します.

/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* functions */
double to_deg(double);
double pi();

/* main */
int main(void) {
    double d = tan(pi() / 3.0), d_rad, d_deg;
    float f = tan(pi() / 4.0), f_rad, f_deg;
    long double ld = tan(pi() / 6.0L), ld_rad, ld_deg;

    /* 逆正接 (arctan) を取得する */
    d_rad = atan(d);
    f_rad = atanf(f);
    ld_rad = atanl(ld);

    /* 弧度法 から 度数法 に変換する */
    d_deg = to_deg(d_rad);
    f_deg = to_deg(f_rad);
    ld_deg = to_deg(ld_rad);

    /* 結果の表示 */
    printf("atan(%.8f): %.2f度\n", d, d_deg);
    printf("atanf(%.8f): %.2f度\n", f,f_deg);
    printf("atanl(%.8Lf): %.2Lf度\n", ld, ld_deg);

    return EXIT_SUCCESS;
}

/**
 * 弧度法表記を度数法表記に変換する
 * @param r 角度[rad]
 * @return  角度[deg]
 */
double to_deg(double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}

/**
 * 円周率を求める
 * @return 円周率
 */
double pi(void) {
    return atan(1.0) * 4.0;
}

実行例

サンプルプログラムの実行結果は以下のようになります.

atan(1.73205080): 60.00度
atanf(1.00000000): 45.00度
atanl(0.57735027): 30.00度

Cプログラマの必読書

たくさんあるC言語関連の書籍の中でも特に役に立った本です.よかったら参考にしてみてください.

C実践プログラミング 第3版

C言語の実践的参考書.少々値段は張りますが初心者を脱しようとしている人は絶対に読むべきです.
文法だけでなく,コーディングスタイルやデバッグなど文字通り「実践的」なことが書かれているので非常にためになります. オライリーの本は,読みにくい本が多いのですが本書はとても読みやすくオススメです.


C言語ポインタ完全制覇 (標準プログラマーズライブラリ)

ポインタの解説書としては最高の書籍です.
この1冊でポインタを完全に理解することができます.全くの初学者が読むには敷居が高いですが,入門書を読み終えた後に読むと非常に有益です.