qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
BASIC Arithmetic Operators
  Expressions and Operators   Arithmetic Operators   Contents   Index
──────────────────────────────────────────────────────────────────────────────
Arithmetic Operators
 
Parentheses change the order in which arithmetic operations are performed.
Operations within parentheses are performed first. Inside parentheses, the
usual order of operation is maintained.
 
Generally, two consecutive operators must be separated by parentheses.
Exceptions to this rule are * -, * +, ^ -, and ^ +.
 
Integer Division
 
Integer division is denoted by the backslash () instead of the forward
slash (/), which indicates floating-point division. Before integer division
is performed, operands are rounded to integers or long integers, and so
must be greater than -2,147,483,648.5 and less than +2,147,483,647.5. The
quotient of an integer division is truncated to an integer.
 
Example
 
  PRINT 10  4, 10 / 4, -32768.499  10, -32768.499 / 10
 
  Output
 
  2             2.5          -3276         -3276.8499
 
 
Modulo Arithmetic
 
Modulo arithmetic is denoted by the modulus operator MOD. Modulo arithmetic
provides the remainder, rather than the quotient, of an integer division.
 
Example
 
  X% = 10.4  4
  REMAINDER% = INT(10.4) - 4*X%       '104 = 2, with remainder 2
  PRINT REMAINDER%, 10.4 MOD 4
 
  Output
 
  2             2
 
 
Overflow and Division by Zero
 
Dividing by zero, raising zero to a negative power, or arithmetic overflow
produce run-time errors. These errors can be trapped by an error-trapping
routine.  The following BASIC statements are useful for error trapping:
 
        ERROR  - allows user to define error codes
        ON ERROR  - error handling
        RESUME  - continue execution after error-trapping
        ERR, ERL  - error status