BASIC syntax 

It may be that my references to 'BASIC syntax' might not mean much to some people.

It used to be that every small computer came equipped with BASIC but, as this has not been the case for some years now, I felt it might be useful to give a brief outline of the BASIC syntax you need to use to enter equations for the 'function' command or to create expressions for a program or command.

BASIC is an acronym for Beginners All-purpose Symbolic Instruction Code and it is the language that most of us over 50 cut our programming teeth on. Over 60 and you were likely to have started programming in binary via a set of switches!

The operators and functions which you can use are listed below. They are all case sensitive.


Recognised operators in order of precedence.
Package code Operation
^ Raise to the power
* Multiplication
/ Fractional, floating point division
\ Integral division
mod Mod, Modulus
+ Addition or a positive value
- Subtraction or a negative value
= Equality
> Greater than *
< Less than *
<> Not equal to *
<= Less than or equal to *
>= Greater than or equal to *
and Logical AND *
or Logical OR *
xor Logical Exclusive OR, XOR *
not Logical NOT * † ‡
eqv Logical equivalence, Not XOR * † ‡
imp Logical implication * † ‡

* The results of logical operations return -1 for True and 0 for False.

These operators can be applied to values as well as conditions.
Hover over the reference symbols for examples.

These operators can generate 1's from zeroes. As all of the bits in the number/s are processed, (32 bits in the case of integers), any leading zeroes in the values used will generate 1's and so the result is likely to be a negative number.

Hover over the symbols for examples.


Standard Functions

Package codeFunction
absAbs, the absolute value
cosCos, cosine
expExp, enumber, the antilogarithm
fixFix, = Sgn(number)*Int(Abs(number))
intInt, the integer portion of the number
logLog, the natural logarithm
rndRnd, a random number where 0 £ number < 1
sgnSgn, sign of the number
sinSin, sine
sqrSqr, the positive square root
tanTan, tangent

Derived Functions

Package codeFunction
log10Logarithm to the base 10
log2Logarithm to the base 2

Inverse Trig. Functions

Package codeFunction
sec1/Sin, secant
cosec1/Cos, cosecant
cot1/Tan, cotangent, cotan
arcsin'Angle whose sine is'
arccos'Angle whose cosine is'
atn'Angle whose tangent is', Arctan
arcsec'Angle whose secant is'
arccosec'Angle whose cosecant is'
arccot'Angle whose cotangent is'

Hyperbolic functions

Package codeFunction
sinhHyperbolic Sine

With BASIC, the main rule is that everything has to be stated explicitly. e.g. we all know that 2x means "Two multiplied by x" but this has to be written in full as '2*x' in BASIC.

A second point is that, as all parts of an equation have to be entered in line, far more parentheses are needed than is the case with written algebra. An equation which would usually be written as "1 over 1 + x" has to be entered as 1/(1+x).

Whilst the following is a rule of basic arithmetic not BASIC, a common mistake is to misinterpret expressions such as 2 + 5 x 3 and expect the result '21' when, in fact, it's 17. [21 = (2 + 5) x 3].