Microsoft KB Archive/69164

From BetaArchive Wiki
Knowledge Base


BASIC Uses Radians, Not Degrees, for Trigonometric Functions

Article ID: 69164

Article Last Modified on 8/16/2005



APPLIES TO

  • Microsoft QuickBasic Compiler for Macintosh 1.0
  • Microsoft QuickBasic Compiler for Macintosh 1.0
  • Microsoft QuickBasic Compiler for Macintosh 1.0
  • Microsoft BASIC Compiler 6.0b, when used with:
    • Apple Macintosh OS X
  • Microsoft BASIC Interpreter 1.0
  • Microsoft BASIC Interpreter 1.01 for Macintosh
  • Microsoft BASIC Interpreter 2.0
  • Microsoft BASIC Interpreter 2.1 for Macintosh
  • Microsoft BASIC Interpreter 3.0 for Macintosh
  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0
  • Microsoft BASIC Professional Development System 7.1
  • Microsoft GW-BASIC 3.2
  • Microsoft GW-BASIC 3.22
  • Microsoft GW-BASIC 3.23



This article was previously published under Q69164

SUMMARY

You must pass angle measurements in radians (not degrees) to BASIC's trigonometric functions (SIN, COS, and TAN).

All versions of Microsoft BASIC require radians for the built-in trigonometric functions (SIN, COS, TAN). Therefore, the value returned from BASIC's SINe, COSine, and TANgent will be different than your calculator's value, unless your calculator is using radians.

To convert degrees to radians, multiply the degrees by pi/180, where pi equals 3.14159265359.

This information applies to the following BASIC versions:

  1. Microsoft QuickBASIC versions 1.00, 1.00a, and 1.00b for Apple Macintosh.
  2. Microsoft BASIC Compiler version 1.00 for Apple Macintosh.
  3. Microsoft BASIC Interpreter versions 1.00, 1.01, 2.00, 2.10, and 3.00 for Apple Macintosh.
  4. Microsoft QuickBASIC versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS.
  5. Microsoft BASIC Compiler versions 5.35 and 5.36 for MS-DOS.
  6. Microsoft BASIC Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2.
  7. Microsoft BASIC Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.
  8. Microsoft GW-BASIC Interpreter versions 3.20, 3.22, and 3.23 for MS-DOS.

Code Example

'Radians = degrees * PI / 180
PI = 3.141593
X = 45
' The following prints .8509035, which is the SIN of 45 radians,
' which may not be what you wanted:
PRINT SIN(X)

' Now, convert X to radians before passing to the SIN function:
PRINT SIN(X * PI / 180)  'This gives .7071068 as the SIN of 45 degrees
                


Additional query words: QuickBas BasicCom MQuickB

Keywords: KB69164