Debian Codegraph @

docs/manual/Formulas_3__Operators.html

raw symbols SCIP
1 <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2 <title>Formulas 3. Operators</title>
3 <style>
4 td { padding-left: 5pt; padding-right: 5pt; }
5 th { padding-left: 5pt; padding-right: 5pt; }
6 code { white-space: pre-wrap; }
7 dd { white-space: pre-wrap; }
8 </style>
9 </head><body bgcolor="#FFFFFF">
10
11 <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b>
12 Formulas 3. Operators
13 </b></font></table></table>
14 <p>In formulas you can use the numerical and logical operators that are described on this page. The order of evaluation of the operators is the order that is most usual in programming languages. To force a different order, you use parentheses.</p>
15 <p>The operators with the highest precedence are <b>negation</b> (-) and <b>exponentation</b> (^):</p>
16 <code> --6 \-&gt; 6<br></code>
17 <code> 2^6 \-&gt; 64<br></code>
18 <p>Sequences of negation and exponentiation are evaluated from right to left:</p>
19 <code> 2^-6 \-&gt; 0.015625<br></code>
20 <code> -(1+1)^6 \-&gt; -64<br></code>
21 <code> 4^3^2 \-&gt; 4^9 \-&gt; 262144<br></code>
22 <p>Note that changing the spacing does not change the meaning:</p>
23 <code> 4^3 ^ 2 \-&gt; 262144<br></code>
24 <p>To change the order of evaluation, you have to use parentheses:</p>
25 <code> (4 ^ 3) ^ 2 \-&gt; 4096<br></code>
26 <p>The following construction is not allowed because of an ambiguity between a negative number and negation of a positive number:</p>
27 <code> -2^6 \-&gt; ?<br></code>
28 <p>Instead, you use any of the following:</p>
29 <code> (-2)^6 \-&gt; 64<br></code>
30 <code> -(2^6) \-&gt; -64<br></code>
31 <code> -(2)^6 \-&gt; -64<br></code>
32 <p>The operators with the next highest precedence are <b>multiplication</b> (*) and <b>division</b> (/). They are evaluated from left to right:</p>
33 <code> 1/4*5 \-&gt; 1.25 (from left to right)<br></code>
34 <code> 1 / 4*5 \-&gt; 1.25 (spacing does not help)<br></code>
35 <code> 1 / (4*5) \-&gt; 0.05 (use parentheses to change the order)<br></code>
36 <code> 3 * 2 ^ 4 \-&gt; 48 (exponentiation before multiplication)<br></code>
37 <code> 3*2 ^ 4 \-&gt; 48 (this spacing does not matter and is misleading)<br></code>
38 <code> (3 * 2) ^ 4 \-&gt; 1296 (use parentheses to change the order)<br></code>
39 <p><b>Integer division</b> operators (<b>div</b> and <b>mod</b>) have the same precedence as * and /, and are likewise evaluated from left to right:</p>
40 <code> 54 div 5 \-&gt; 10 (division rounded down)<br></code>
41 <code> 54 mod 5 \-&gt; 4 (the remainder)<br></code>
42 <code> 54.3 div 5.1 \-&gt; 10 (works for real numbers as well)<br></code>
43 <code> 54.3 mod 5.1 \-&gt; 3.3 (the remainder)<br></code>
44 <code> -54 div 5 \-&gt; -11 (division rounded down; negation before division)<br></code>
45 <code> -54 mod 5 \-&gt; 1 (the remainder)<br></code>
46 <code> -(54 div 5) \-&gt; -10 (use parentheses to change the order)<br></code>
47 <code> -(54 mod 5) \-&gt; -4<br></code>
48 <code> 3 * 18 div 5 \-&gt; 10 (from left to right)<br></code>
49 <code> 3 * (18 div 5) \-&gt; 9<br></code>
50 <code> 3 * 18 mod 5 \-&gt; 4<br></code>
51 <code> 3 * (18 mod 5) \-&gt; 9<br></code>
52 <code> 54 div 5 * 3 \-&gt; 30 (from left to right)<br></code>
53 <code> 54 div (5 * 3) \-&gt; 3<br></code>
54 <code> 54 mod 5 * 3 \-&gt; 12<br></code>
55 <code> 54 mod (5 * 3) \-&gt; 9<br></code>
56 <p>The operators with the next highest precedence are <b>addition</b> (+) and <b>subtraction</b> (-), evaluated from left to right:</p>
57 <code> 3 - 8 + 7 \-&gt; 2 (from left to right)<br></code>
58 <code> 3 - (8 + 7) \-&gt; -12 (use parentheses to change the order)<br></code>
59 <code> 3 + 8 * 7 \-&gt; 59 (multiplication before addition)<br></code>
60 <code> (3 + 8) * 7 \-&gt; 77 (use parentheses to change the order)<br></code>
61 <code> 3 + - (2 \^ 4) \-&gt; -13 (exponentiation, negation, addition)<br></code>
62 <code> 3 + 5 / 2 + 3 \-&gt; 8.5<br></code>
63 <code> (3 + 5) / (2 + 3) \-&gt; 1.6<br></code>
64 <p>The operators with the next highest precedence are the <b>comparison</b> operators (<code><font size=+1>=, <>, <, >, <=, >=</font></code>). These operators always yield 0 (<i>false</i>) or 1 (<i>true</i>):</p>
65 <code> 5 + 6 = 10 \-&gt; 0 (equal)<br></code>
66 <code> 5 + 6 = 11 \-&gt; 1<br></code>
67 <code> 5 + 6 &lt;&gt; 10 \-&gt; 1 (unequal)<br></code>
68 <code> 5 + 6 &lt;&gt; 11 \-&gt; 0<br></code>
69 <code> 5 + 6 &lt; 10 \-&gt; 0 (less than)<br></code>
70 <code> 5 + 6 &lt; 11 \-&gt; 0<br></code>
71 <code> 5 + 6 &gt; 10 \-&gt; 1 (greater than)<br></code>
72 <code> 5 + 6 &gt; 11 \-&gt; 0<br></code>
73 <code> 5 + 6 &lt;= 10 \-&gt; 0 (less than or equal)<br></code>
74 <code> 5 + 6 &lt;= 11 \-&gt; 1<br></code>
75 <code> 5 + 6 &gt;= 10 \-&gt; 1 (greater or equal)<br></code>
76 <code> 5 + 6 &gt;= 11 \-&gt; 1<br></code>
77 <p>The comparison operators are mainly used in <b>if</b>, <b>while</b>, and <b>until</b> conditions.</p>
78 <p>The operators of lowest precedence are the <b>logical</b> operators (<b>not</b>, <b>and</b>, and <b>or</b>), of which <b>not</b> has the highest precedence and <b>or</b> the lowest:</p>
79 <code> not 5 + 6 = 10 \-&gt; 1<br></code>
80 <code> x &gt; 5 and x &lt; 10 (is x between 5 and 10?)<br></code>
81 <code> not x &lt;= 5 and not x &gt;= 10 (means the same as the previous line, except if x is undefined)<br></code>
82 <code> not (x &lt;= 5 or x &gt;= 10) (again means the same, except if x is undefined)<br></code>
83 <h2>String comparison</h2>
84 <dl>
85 <dt><b><code><font size=+1>a$ = b$</font></code></b>
86 <dd>gives the value <i>true</i> (= 1) if the strings are equal, and <i>false</i> (= 0) otherwise.</dd>
87 <dt><b><code><font size=+1>a$ <> b$</font></code></b>
88 <dd>gives the value <i>true</i> if the strings are unequal, and <i>false</i> otherwise.</dd>
89 <dt><b><code><font size=+1>a$ < b$</font></code></b>
90 <dd>gives <i>true</i> if the string <i><code><font size=+1>a$</font></code></i> precedes the string <i><code><font size=+1>b$</font></code></i> in Unicode sorting order. Thus, "ha" &lt; "hal" and "ha" &lt; "ja" are true, but "ha" &lt; "JA" is false, because all capitals precede all lower-case characters in the Unicode sorting order.</dd>
91 <dt><b><code><font size=+1>a$ > b$</font></code></b>
92 <dd><i>true</i> if <i><code><font size=+1>a$</font></code></i> comes after <i><code><font size=+1>b$</font></code></i> in Unicode sorting order. </dd>
93 <dt><b><code><font size=+1>a$ <= b$</font></code></b>
94 <dd>gives the value <i>true</i> if the string <i><code><font size=+1>a$</font></code></i> precedes the string <i><code><font size=+1>b$</font></code></i> in Unicode sorting order, or if the strings are equal.</dd>
95 <dt><b><code><font size=+1>a$ >= b$</font></code></b>
96 <dd><i>true</i> if <i><code><font size=+1>a$</font></code></i> comes after <i><code><font size=+1>b$</font></code></i> or the two are equal.</dd>
97 </dl>
98 <h2>String concatenation and truncation</h2>
99 <dl>
100 <dt><b><code><font size=+1>a$ + b$</font></code></b>
101 <dd>concatenates the two strings. After</dd>
102 </dl>
103 <code> text$ = "hallo" + "dag"<br></code>
104 <dl>
105 <dd>the variable <i><code><font size=+1>text$</font></code></i> contains the string &#8220;hallodag&#8221;.</dd>
106 <dt><b><code><font size=+1>a$ - b$</font></code></b>
107 <dd>subtracts the second string from the end of the first. After</dd>
108 </dl>
109 <code> soundFileName$ = "hallo.aifc"<br></code>
110 <code> textgridFileName$ = soundFileName$ - ".aifc" + ".TextGrid"<br></code>
111 <dl>
112 <dd>the variable <i><code><font size=+1>textgridFileName$</font></code></i> contains the string "hallo.TextGrid". If the first string <i><code><font size=+1>a$</font></code></i> does not end in the string <i><code><font size=+1>b$</font></code></i>, the result of the subtraction is the string <i><code><font size=+1>a$</font></code></i>.</dd>
113 </dl>
114 <h3>Links to this page</h3>
115 <ul>
116 <li><a href="Formulas.html">Formulas</a>
117 </ul>
118 <hr>
119 <address>
120 <p>© ppgb 20230124</p>
121 </address>
122 </body>
123 </html>