Microsoft KB Archive/11158

{| = PRB: tan(pi/2) Returns Value, Causes No Error =
 * width="100%"|

Article ID: Q11158

The information in this article applies to:
 * The C Run-time (CRT), included with: - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, 6.0ax - Microsoft C for OS/2, versions 5.1, 6.0, 6.0a - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 5.0

SYMPTOMS
If an application uses the tan run-time function to compute the value of pi/2, the function returns a value. Mathematically, this value is not defined.

CAUSE
This error is caused by the precision with which numbers can be represented in the computer. It is not possible to specify a value X close enough to the true value of pi/2 to cause tan(X) to overflow.

MORE INFORMATION
The tangent of a value is defined as the sine of the value divided by the cosine of the value. Therefore, the tangent of pi/2 is the sine of pi/2 (1) divided by the cosine of pi/2 (0). Because the cosine of pi/2 is 0, its tangent is undefined.

sin(pi/2)    1 tan(pi/2) = --- = --- = undefined, divide by zero cos(pi/2)    0 The function tan(pi/2) returns a value because the computer approximates pi to a limited number of digits. Even at double precision, the approximate value of pi is not large enough to cause cos(pi/2) to equal zero. Therefore, tan(pi/2) returns an unexpected value, as follows: Approximate pi = 3.1415926535

sin(pi/2)   sin(3.1415926535/2)           1 tan(pi/2) = --- = --- = - cos(pi/2)   cos(3.1415926535/2)   0.000000000044896 Keywords         : kbCRT kbVC Version          : 5.1 6.0 6.0a 6.0ax 7.0 1.0 1.5 2 Platform         : MS-DOS NT OS/2 WINDOWS Issue type       : kbprb
 * }