Home

Trigonometric Functions: Tangents

 

 

The C/C++ tan Functions

double tan(double x);
long double tanl(long double x);

The tan() function calculates the tangent of a number.

In geometry, consider AC the length of A to C. Also consider BC the length of B to C. The tangent is the result of BC/AC; that is, the ratio of BC over AC.

Example: A form contains an Edit control named edtValue. After the user has typed a value and presses Enter, the OnKeyPress event retrieves the number typed in the edit box, calculates its tangent and displays the result in the same Edit control:

//---------------------------------------------------------------------------
void __fastcall TForm1::edtValueKeyPress(TObject *Sender, char &Key)
{
	if( Key == VK_RETURN )
	{
		double Value = edtValue->Text.ToDouble();
		double Tangent = tan(Value);
		
		edtValue->Text = Tangent;
	}
}
//---------------------------------------------------------------------------
 

The Arc Tangent Functions

double atan(double x);

The atan() function is used to calculate the arc tangent of a number.

In geometry, consider BC the length of B to C. Also consider AC the length of A to C. The arc tangent is the ratio of BC/AC.

The atan() function takes one argument, x, that represents the angle BA AC. After the evaluation, the function returns a double-precision number between –PI/2 and PI/2.

If the number to be evaluated is larger than a double, use the atanl() function:

long double atanl(long double x);

This function takes a long double argument and returns a long double.

 
Home Copyright © 2004-2010 FunctionX, Inc.