Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

TAN

Keyword Abbreviation Token (hex) Version(s) Classification
TAN none C0 1.0+ Function

  Syntax  
TANangle )
 
Parameters Type Legal Value(s) Default Value Note(s)
angle Numeric
any but an odd integer multiple of π/2
measured in radians
 
Returns Type Value(s) Note(s)
slope Floating-point
any
rise/run
 
  Purpose  
Calculate the triginometric tangent (slope) of an angle (in radians).

 
  Remarks  
The TAN function returns the slope of an angle, which is occassionally useful in things like trigonometry.  A slope of 0 is horizontal, a slope of 1 has an equal rise-to-run ratio, and a perfectly vertical slope is infinite.  Because CBM BASIC doesn't allow infinite values, any odd multiple of 90 degrees (π/2 radians)), should return OVERFLOW ERROR, but actually the only thing I have ever seen is DIVISION BY ZERO, which is misleading.
 
The value of TAN (the slope) can be easily derived from the SIN and COS functions; if their values are S and C respectively for angle, then you can "manually" calculate TAN(angle) as C / S.  The "manual" method is much faster if you already have C and S.  Usually if you have one of them, you probably have the other (or it would be handy to have the other).
 
Because of the nature of angles, the value of this function repeats itself with a "period" of π radians or 180 degrees (approximately 3.14159265); TAN is a never-ending repetion of the inverted ATN function.  Because TAN needs an angle in radians, first multiple by π/180 if you are using degrees.
 
Note the trignometric tangent (TAN) has almost no relation to the concept of a geometric tangent (where a line just touches a curve).
 
You will get TYPE MISMATCH ERROR with a string value.
  
Examples:
PRINT TAN(π/180*30)
 .577350269
 
READY.
PRINT TAN(π/180*45)
 .999999999

READY.
PRINT TAN(π/180*90)

?DIVISION BY ZERO ERROR
READY.
  
  Contrast With  
 
  See Also  
COS, SIN 

© H2Obsession, 2014
Comments