Unary minus not supported in Liberty BASIC

From Liberty BASIC Family
Jump to navigation Jump to search

This is not a bug. This is documented in the help-file, along with the correct way to change the sign of a numeric variable.

Description

In some other languages, you can use unary minus on variables and expressions.
In Liberty BASIC, it is possible to use unary minus only as part of numeric literal.

It is documented in the help file, under "Numeric variables":

Negative numbers.
Liberty BASIC does not support changing the sign of a variable directly by preceding it with a negative sign "-". Instead the variable must be multiplied by -1

Example code to demonstrate the bug.

x = -1
y = -x
y = -sin(x)
y = -(x+1)

Only first line works, others do not compile with "BASIC Compile Halted: Syntax error" message.

Example code to work around the bug.

In addition to help file recommendation ("variable must be multiplied by -1"), folks routinely use "0-stuff" as a workaround:

x = -1
y = 0-x
y = 0-sin(x)
y = 0-(x+1)