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

COS

 Keyword Abbreviation Token (hex) Version(s) Classification COS none BE 1.0+ Function

COS angle )

 Parameters Type Legal Value(s) Default Value Note(s) angle Numeric any measured in radians

 Returns Type Value(s) Note(s) deltaX Floating-point -1 to 1 also called the run

 Purpose
Calculate the trignometric cosine (deltaX) of an angle (in radians).

 Remarks
The COS function returns deltaX which is a scaled version of the run in the formula: slope = rise / run.  It most useful to calculate the X component during polar to rectangular conversion.  May also used to calculate the real part of a complex number.  Because deltaX is a scaled version (based on a unit circle), to get the actual X (or the actual run), you need to multiply the returned value by the actual magnitude of the polar coordinate (or length of the slope).

Because of the nature of angles, the value of this function repeats itself with a "period" of 2*π radians or 360 degrees (approximately 6.28318531).  Because COS needs an angle in radians, first multiple by π/180 if you are using degrees.

You will get TYPE MISMATCH ERROR with a string value.

Examples:
 ```PRINT COS(π/180*30) .866025404 READY. PRINT COS(π/180*45) .707106782 READY. PRINT COS(π/180*90) 0 READY. ```

 Contrast With