當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Math atan()用法及代碼示例

該函數計算以弧度給出的數字的反正切。

atan(x) = tan-1x

用法

假設一個數字是 'x'。語法是:

float atan(float x);
double atan(double x);
long double atan(long double x);
double atan(integral x);

注意:如果傳遞的值是整數類型,則將其強製轉換為 double。

參數

x:要計算其反正切的值。

返回值

它返回範圍[-∼ /2,∼ /2] 內的值。

例子1

當 x 的值為零時,讓我們看一個簡單的例子。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float degree=0;
    float x=degree*3.14/180;
    std::cout << "Value of tangent is:" <<tan(x)<< std::endl;
    cout<<"Inverse of tangent is:"<<atan(x);
    return 0;
}

輸出:

Value of tangent is:0
Inverse of tangent is:0   

在本例中,atan() 函數計算當 x 的值等於 0 時數字的反正切。

例子2

讓我們看一個簡單的例子,當 x 的值為負時。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float degree= -67;
    float x=degree*3.14/180;
    std::cout << "Value of tangent is:" <<tan(x)<< std::endl;
    cout<<"Inverse of tangent is:"<<atan(x);
    return 0;
}

輸出:

Value of tangent is:-2.35197
Inverse of tangent is:-0.863063   

在此示例中,atan() 函數計算 x 值為負時數字的反正切。

例子3

當 x 的值為正時,讓我們看一個簡單的例子。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float degree=30;
    float x=degree*3.14/180;
    std::cout << "Value of tangent is:" <<tan(x)<< std::endl;
    cout<<"Inverse of tangent is:"<<atan(x);
    return 0;
}

輸出:

Value of tangent is:0.576996
Inverse of tangent is:0.48214   

在本例中,當 x 的值為正時,atan() 函數計算一個數的反正切。






相關用法


注:本文由純淨天空篩選整理自 C++ Math atan()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。