Skip to main content

COS

Syntax

COS ( expression )

Description

ARMbasic uses integers, but there may be a need for certain functions that normally use floating point calculations.  One of these is the cosine function, which normally operates on degrees or radians.  But for simplicity and the binary world, these values and the result value have been normalized to fit in a byte value. So rather than taking an argument of 0..359 or 0..2 p , the argument is 0-255 which is equal to the number of degrees times 0.7103  (256/360).   The result would normally be between -1 and 1, but in this case it is expressed as -127 to +127 or the cos() multiplied by 127.

 

Example

PRINT "Please enter an angle in degrees:
";

DEBUGIN a

r = a
* 256 / 360 'Convert the degrees to "binary radians"

PRINT ""

PRINT "The cosine of a" ; a; " degree angle is"; COS ( r )

END

The output would look like:

Please enter an angle in degrees: 30

The cosine of a 30 degree angle IS 110

Differences from other BASICs

  • Floating point routine in Visual BASIC
  • The () around expression are enforced in ARMbasic, but not PBASIC

See also