Mathematical Expressions

A mathematical expression is an expression which eventually evaluates to a number.

A mathematical expression is built using standard mathematical notation. The operators that TNT Basic supports are...

* - Multiply
/ - Divide
- - Subtract or unary minus
+ - Add
^ - Raise to the power

Brackets can also be used inside mathematical expression to specify the order in which the calculation should be performed.

Techincal Note: TNT Basic supports standard operator precedences.

Using Mathematical Expressions

Mathematical expressions can be used in the following ways...

6

This mathematical expression simply evaluates to the number 6.

-6

This is an example of what is called 'unary minus'. It is used to represent negative numbers.

10+5 ' This evaluates to 15
10-5
' This evaluates to 5
10*5
' This evaluates to 50
10/5
' This evaluates to 2
5^3
' This evaluates to 125 (5x5x5)

Mathematical expressions can also be combined easily...

10*5-5/5 ' This evaluates to 49

Brackets can also be used to specify the order in which the calculation should be performed...

(10*5-5)/5 ' This evaluates to 9

The answer is different due to the part in brackets being done before everything else.

TNT Basic Functions

TNT Basic also has built in functions that perform specific tasks (e.g. As Number)

Most of the functions return a numeric result..

int number=As Number("12")

These functions can be used as part of mathematical expressions just like ordinary numbers...

int number=As Number("12")+18

Note: If you are using one of these functions, it is required that you receive the result and that you place brackets around the parameters you pass to the function.


Table of contents