Difference between revisions of "TAN"

From BeebWiki
Jump to: navigation, search
m
 
m (1 revision)
(No difference)

Revision as of 23:58, 28 August 2013

TAN is a BASIC function which returns the Tangent of the angle (passed as a parameter).

TAN
Availability Present in all original versions of BBC BASIC.
Syntax BASIC I-V <num-var> = TAN(<numeric>)
Token (hex) BASIC I-V B7 (function)
Description BASIC I-V Returns the Tangent of the angle (passed as a parameter)
Associated keywords SIN, COS, ATN, ASN, ACS

Description

TAN accepts a single parameter (the angle), and returns the Tangent of that angle.


Internal Operation

Overview

TAN(x)

To obtain the Tangent value the SIN(x) result is divided by the COS(x) result:

TAN(x) = SIN(x) / COS(x)


Detailed

BASIC 4 implements TAN as follows:

The TAN routine calls &A93A to obtain the Floating-point argument and use continued-fraction expressions to calculate either the Sine or Cosine value (depending on the value of the argument) of the argument.
This FWA result is stored in temporary Floating-point location &047B-&047F.

Call &A917 (SIN) to calculate the Sine value from the FWA result.
Store the Sine result in the temporary Floating-point location &0476-&047A.

Set the FWA back to the &A93A result (from the Temporary Floating-point variable at &047B-&047F).
Call &A915 (COS) to calculate the Cosine value from the &A93A result.
Note: Storing the &A93A value avoids the need to calculate it again!


Set the argument pointer to point to &0476 (the Sine result).
Call &A5EE to divide argp by the FWA [FWA = argp / FWA], where argp points to the Sine result and the FWA contains the Cosine result.
Dividing the Sine result by the Cosine result gives the Tangent value.


Exit with A = #&FF (as the result is Floating-point and is located in the FWA).


Example 1: TAN(90)

Divide the SIN(90) result by the COS(90) result
FWA = 0.8939945 / -0.4480777 --> -1.9951774 (= the TAN result)


Example 2: TAN(2.41)

Divide the SIN(2.41) result by the COS(2.41) result
FWA = 0.6680554 / -0.7441115 --> -0.8977893 (= the TAN result)


Example 3: TAN(1.5)

Divide the SIN(1.5) result by the COS(1.5) result
FWA = 0.9974949 / 0.0707372 --> 14.1014191 (= the TAN result)


Example 4: TAN(5.63)

Divide the SIN(5.63) result by the COS(5.63) result
FWA = -0.6078147 / 0.7940788 --> -0.7654337 (= the TAN result)


Example 5: TAN(0)

Divide the SIN(0) result by the COS(0) result
FWA = 0 / 1 --> 0 (= the TAN result)


Example 6: TAN(-0.75)

Divide the SIN(-0.75) result by the COS(-0.75) result
FWA = -0.6816387 / 0.7316889 --> -0.9315963 (= the TAN result)


Example 7: TAN(0.25)

Divide the SIN(0.25) result by the COS(0.25) result
FWA = 0.2474039 / 0.9689124 --> 0.2553418 (= the TAN result)



Kranser 23:11, 2 October 2007 (BST)