Description

Arithmetic expressions are combinations of variables, constants, or functions that specify a rule to calculate a single numeric value.

Syntax

result = expression [operator expression ...]

Operators

PriorityOperatorKeyboard Symbol
high 1unary plus+
1unary minus-
2exponentiation**
3multivalued multiplication***
3multivalued division///
3multiplication*
3division/
4multivalued addition+ + +
4multivalued subtraction---
4addition+
4subtraction-
5multivalued concatenation:::
low 5concatenation:

Simple Arithmetic Expressions

The simplest arithmetic expressions consist of a single numeric constant, a variable or an intrinsic function. Following are examples of simple arithmetic expressions:

3.14161000.0005
QTAINT(2.5)"144"

An arithmetic operator (+, /, *, (), etc.) can combine two arithmetic expressions and produce a third arithmetic expression. The third arithmetic expression may in turn be combined with other expressions. For examples

bal_ford + mo_end

scoreA + scoreB / 2

amt * .065

sin(D) / cos(D)

Arithmetic operations follow a strict order of priority. See Arithmetic Operators for details.

BASIC+ considers character string values that contain only numeric characters to be decimal numbers. For exampe, the expression 123 + "321" will evaluate to 444.

Character string values that contain non-numeric characters will produce an error message when the program is run. The string value will assume the value of 0 (zero) in this case and the program will terminate.

Correct Use of Arithmetic Operators

result = - 6 + 3 The result variable will be -3.

result = - (6 + 3) The result variable will be - 9.

A = 5 result = 3 * 4 ** 2 + A

The result variable will be 4 raised to the second power multiplied by 3 plus the current value of 5. The result variable will be 53.

See Also

Arithmetic operators, Multi-value Arithmetic operators

  • No labels