User Tools

Site Tools


k5:k5.3:k5.3.2:start

5.3.2 Evaluation of expressions

If you call the gambas interpreter gbx3 in a terminal with the option -e, you can evaluate an expression passed as a parameter and display the result:

Usage: gbx3 -e <expression>
Option: -e evaluate an expression

hans@linux:~$ gbx3 -e -2*5+8^3-36/77
501,532467532467

hans@linux:~$ gbx3 -e "sin(rad(30))"
0,5

5.3.2.1 Notes

Note that some expressions in the following examples are enclosed in quotation marks. This is especially necessary if the expression contains parentheses. This has nothing to do with the Gambas interpreter, it is the shell that interprets these special characters in different ways: In the event of a syntax error or an error in the evaluation of an expression, an error message and a comment are output. The comment indicates the type of error.

5.3.2.2 Selected examples

The following list of examples of how to use the interpreter with the -e option is sufficiently representative:

hans@linux:~$ gbx3 -e 3-4*5.66+1
-18,64
 
hans@linux:~$ gbx3 -e 22/7 '  Approximation of Pi
3,142857142857
 
hans@linux:~$ gbx3 -e "pi-(355/113)" ' Approximation of Pi with 7 valid digits!
-2,66764189405E-7
 
hans@linux:~$ gbx3 -e now
09.01.2012 18:21:19
 
hans@linux:~$ gbx3 -e 2*(3-pi)
-0,28318530718
 
hans@linux:~$ gbx3 -e log(2)
bash: syntax error near unexpected token `('
 
hans@linux:~$ gbx3 -e 2*(3+log(2))
7,38629436112
 
hans@linux:~$ gbx3 -e sin(rad(30))
bash: syntax error near unexpected token `('
 
hans@linux:~$ gbx3 -e "sin(rad(30))"
0,5
 
hans@linux:~$ gbx3 -e "sqr(-8)"
Mathematic error
 
hans@linux:~$ gbx3 -e "cbr(sqr(4)-10)"
-2
 
hans@linux:~$ gbx3 -e "date(now)"
09.03.12
 
hans@linux:~$ gbx3 -e "year(now)"
2012
 
hans@linux:~$ gbx3 -e "bin(2301)"
100011111101
 
hans@linux:~$ gbx3 -e "hex(244)"
F4
 
hans@linux:~$ gbx3 -e "hex(678)"
2A6
 
hans@linux:~$ gbx3 -e "Int(Rnd(1, 7))"
6
 
hans@linux:~$ gbx3 -e "Int(Rnd(1, 7))"
2
 
hans@linux:~$ gbx3 -e 3.77*pi-37
-25,156195695966
 
hans@linux:~$ gbx3 -e "fix(3.77*pi-37)"
-25
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k5/k5.3/k5.3.2/start.txt · Last modified: 29.01.2022 (external edit)

Page Tools