Mathematics

See also Numeric Variables, Mathematical Operations, Trigonometry, Numbers and Strings

Numbers and Numeric Expressions

Most mathematical operations in Liberty BASIC can be performed on literal numbers, numeric variables, or numeric expressions that consist of literal numbers, numeric variables, or both. Functions that require a numeric input can also use any of these forms, as long as the expression evaluates to a number. Here is the ABS function used as an example:

  print ABS(-2)'a literal number
  x = 13
  print ABS(x)'a numeric variable
  print ABS(7-233)'a literal numeric expression
  print ABS( x/13 )'a numeric expression containing a variable

Scientific Notation

Liberty BASIC supports scientific notation in code:

  print 1.2345e-4

Arithmetic

Arithmetic operators are as follows:

  +    addition
 -     subtraction
 *     multiplication
 /     division
 ^     raise to a power

Examples:

print 2 + 3 'addition
print 6 - 2 'subtraction
print 4 * 7 'multiplication
print 9 / 3 'division
print 2 ^ 3 'power - (two to the third power)
print (4+2)*6^2 'a complex expression

Order

Complex expressions are evaluated in this order:

 ( )    expressions within parentheses are evaluated first
 ^     exponents are evaluated next
 * /    multiplication and division are evaluated next
+ -    addition and subtraction are evaluated last

See also:

SIN
COS
TAN
ASN
ACS
ATN
ABS
EXP
LOG
HEXDEC
DECHEX$
INT
MAX
MIN
MOD
RND
SQR
VAL
STR$
USING