WordPress.org

Make WordPress Core

Ticket #20112: page.txt

File page.txt, 9.3 KB (added by spoko_ws, 4 years ago)

The page, which I cannot save clearly into database

Line 
1<h2>Contents</h2>
2<ul>
3        <li><a href="#overview">Overview</a></li>
4        <li><a href="#types">Types</a></li>
5        <li><a href="#operators">Supported operators</a></li>
6        <li><a href="#functions">Built-in Functions</a></li>
7        <li><a href="#defining">Defining user variables and functions</a></li>
8</ul>
9<a name="overview"></a>
10<h2>Overview</h2>
11Calculations in ProCalc are done by entering an expression into the expression textbox. ProCalc supports a number of operators and functions, as well as adding user-defined variables and functions.
12
13<a name="types"></a>
14<h2>Types</h2>
15ProCalc supports the following numeric types:
16<table class="simple" width="100%">
17<tbody>
18<tr>
19<th width="20%">Type</th>
20<th width="60%">Description</th>
21<th width="20%">Sample</th>
22</tr>
23<tr>
24<td>Integer</td>
25<td>Integer value ranging from - 9,223,372,036,854,775,808 to
269,223,372,036,854,775,807</td>
27<td>44</td>
28</tr>
29<tr>
30<td>Binary, octal and hexadecimal values</td>
31<td>Use 0b, 0o and 0h prefix to denote an integer in specific system.</td>
32<td>0b1001010</td>
33</tr>
34<tr>
35<td>Floating point</td>
36<td>Floating point value ranging from ±5.0 x 10 <sup>-324</sup>
37to ±1.7 x 10 <sup>308</sup> with 15 digits of precision.</td>
38<td>10.5</td>
39</tr>
40<tr>
41<td>Fractions</td>
42<td>ProCalc attempts to evaluate expressions using the common fractions instead of floating point numbers as long as it is possible. If the calculations involves using floating point values or if the fraction cannot be represented as a common fraction, ProCalc converts the value into floating point value. For example, if you try to evaluate 1 / 3, the result will be a common fraction. However, if you try to evaluate 1.0 / 3 (forcing the first operand to be a floating point value), the result will be a floating point value. The fractions are automatically reduced to the simplest form. You may enter a common fraction by dividing two integers.</td>
43<td>4/9</td>
44</tr>
45<tr>
46<td>Complex numbers</td>
47<td>A number followed by the "i" letter is considered to be a imaginary
48value.</td>
49<td>4i1 + 2i</td>
50</tr>
51<tr>
52<td>DMS values</td>
53<td>A DMS value is a fraction represented as units (degrees), minutes (1/60 of a degree) and seconds (1/3600 of a degree). Internally a DMS value is stored as a common fraction (if possible).</td>
54<td>12:30:00</td>
55</tr>
56<tr>
57<td>Boolean value</td>
58<td>Two logical values: true and false.</td>
59<td>true</td>
60</tr>
61<tr>
62<td>Matrices</td>
63<td>Use the rectangular brackets [ and ] to define a matrix. Inside, use the comma symbol to separate items in row and the semicolon to denote end of row. For example, matrix:
64<table border="0" cellspacing="2" cellpadding="0">
65<tbody>
66<tr>
67<td>1</td>
68<td>2</td>
69</tr>
70<tr>
71<td>3</td>
72<td>4</td>
73</tr>
74</tbody>
75</table>
76Can be entered by using the following syntax:
77
78[1, 2; 3, 4]
79
80Matrix can contain any numeric value, including nested matrices.</td>
81<td>[1, 2, 3; 4-2i, 5+3i, 1/3]</td>
82</tr>
83<tr>
84<td>Lists</td>
85<td>A list contains one or more numeric values. Use curly brackets { and } to enter list and a comma to separate its items.</td>
86<td>{1, 2, 3}</td>
87</tr>
88<tr>
89<td>Strings</td>
90<td>Use the double-quotes to denote a string. If you want to include the double-quote inside the string, write it twice: &quot;Alice has a &quot;&quot;funny&quot;&quot; cat&quot;</td>
91<td>&quot;CATS. CATS ARE NICE&quot;</td>
92</tr>
93</tbody>
94</table>
95<a name="operators"></a>
96<h2>Supported operators</h2>
97The following operators are supported by ProCalc.
98<table class="simple" width="100%">
99<tbody>
100<tr>
101<th width="30%">Operator</th>
102<th width="10%">Symbol</th>
103<th width="60%">Samples</th>
104</tr>
105<tr>
106<td>Addition</td>
107<td>+</td>
108<td>2+2 = 4[1,2]+[2,5] = [3,7]1+2i + 3+4i = 4+8i</td>
109</tr>
110<tr>
111<td>Subtraction</td>
112<td>-</td>
113<td>10-8 = 2</td>
114</tr>
115<tr>
116<td>Multiplication</td>
117<td>*</td>
118<td>2*2 = 4[1,2;3,4]*[5,6;7,8] = [19, 22; 43, 50](1+2i)*(3+4i) = 5+10i</td>
119</tr>
120<tr>
121<td>Division</td>
122<td>/</td>
123<td>11/2 = 5.5</td>
124</tr>
125<tr>
126<td>Integer division</td>
127<td>\</td>
128<td>11\2 = 5</td>
129</tr>
130<tr>
131<td>Modulo</td>
132<td>%</td>
133<td>11%2 = 1</td>
134</tr>
135<tr>
136<td>Power</td>
137<td>^</td>
138<td>2^10 = 1024</td>
139</tr>
140<tr>
141<td>Binary shift left</td>
142<td>&lt;&lt;</td>
143<td>1200&lt;&lt;5 = 38400</td>
144</tr>
145<tr>
146<td>Binary shift right</td>
147<td>&gt;&gt;</td>
148<td>1200&gt;&gt;5 = 37</td>
149</tr>
150<tr>
151<td>Less than or equal</td>
152<td>&lt;=</td>
153<td>10&lt;5 = false</td>
154</tr>
155<tr>
156<td>More than or equal</td>
157<td>&gt;=</td>
158<td>10&gt;=5 = true</td>
159</tr>
160<tr>
161<td>Less than</td>
162<td>&lt;</td>
163<td>10&lt;5 = false</td>
164</tr>
165<tr>
166<td>More than</td>
167<td>&gt;</td>
168<td>10&gt;5 = true</td>
169</tr>
170<tr>
171<td>Equal</td>
172<td>==</td>
173<td>10==5 = falseNote, that equal operator will always return false when a floating-point value is involved in comparison</td>
174</tr>
175<tr>
176<td>Inequal</td>
177<td>!=</td>
178<td>10!=5 = trueNote, that inequal operator will always return true when a floating-point value is involved in comparison</td>
179</tr>
180<tr>
181<td>And (logical and binary)</td>
182<td>&amp;</td>
183<td>true &amp; true = true0hab &amp; 0hba = 0haa</td>
184</tr>
185<tr>
186<td>Or (logical and binary)</td>
187<td>|</td>
188<td>true | false = true10 | 25 = 27</td>
189</tr>
190<tr>
191<td>Xor (logical and binary)</td>
192<td>#</td>
193<td>true # true = false10 # 25 = 19</td>
194</tr>
195<tr>
196<td>Unary negative value operator</td>
197<td>-</td>
198<td>-5</td>
199</tr>
200<tr>
201<td>Unary logical negation</td>
202<td>!</td>
203<td>!true = false</td>
204</tr>
205</tbody>
206</table>
207<a name="functions"></a>
208<h2>Built-in functions</h2>
209The following built-in functions are available:
210<table class="simple" width="100%">
211<tbody>
212<tr>
213<th>Definition</th>
214<th>Description</th>
215<th>Example</th>
216</tr>
217<tr>
218<td>sin(x)</td>
219<td>Sine of x. X is in radians.</td>
220<td>sin(1) = 0.841470984807897</td>
221</tr>
222<tr>
223<td>cos(x)</td>
224<td>Cosine of x. X is in radians.</td>
225<td>cos(1) = 0.54030230586814</td>
226</tr>
227<tr>
228<td>tan(x)</td>
229<td>Tangent of x. X is in radians.</td>
230<td>tan(1) = 1.5574077246549</td>
231</tr>
232<tr>
233<td>ctg(x)</td>
234<td>Cotangent of x. X is in radians.</td>
235<td>ctg(1) = 0.642092615934331</td>
236</tr>
237<tr>
238<td>arcsin(x)</td>
239<td>The inverse sine of x.</td>
240<td>arcsin(1) = 1.5707963267949</td>
241</tr>
242<tr>
243<td>arccos(x)</td>
244<td>The inverse cosine of x.</td>
245<td>arccos(1) = 0</td>
246</tr>
247<tr>
248<td>arctan(x)</td>
249<td>The inverse tangent of x.</td>
250<td>arctan(1) = 0.785398163397448</td>
251</tr>
252<tr>
253<td>arcctg(x)</td>
254<td>The inverse cotangent of x.</td>
255<td>arcctg(1) = 0.785398163397448</td>
256</tr>
257<tr>
258<td>abs(x)</td>
259<td>Absolute value</td>
260<td>abs(-5) = 5</td>
261</tr>
262<tr>
263<td>round(x)</td>
264<td>Value rounded to the nearest integer.</td>
265<td>round(2.6) = 3round(-2.6) = -3</td>
266</tr>
267<tr>
268<td>trunc(x)</td>
269<td>Integer part of value</td>
270<td>trunc(2.5) = 2trunc(-2.5) = -2</td>
271</tr>
272<tr>
273<td>frac(x)</td>
274<td>Fraction part of value</td>
275<td>frac(2.5) = 0.5frac(-2.5) = -0.5</td>
276</tr>
277<tr>
278<td>sqrt(x)</td>
279<td>Square root of argument</td>
280<td>sqrt(4) = 2</td>
281</tr>
282<tr>
283<td>sqr(x)</td>
284<td>Argument, squared.</td>
285<td>sqr(2) = 4</td>
286</tr>
287<tr>
288<td>ln(x)</td>
289<td>Natural logarithm of argument</td>
290<td>ln(1) = 0</td>
291</tr>
292<tr>
293<td>length(x)</td>
294<td>Length of a string</td>
295<td>length("CATS. CATS ARE NICE") = 19</td>
296</tr>
297<tr>
298<td>copy(x, start, len)</td>
299<td>Substring of a string</td>
300<td>copy("CATS. CATS ARE NICE", 0, 4) = "CATS"</td>
301</tr>
302<tr>
303<td>pos(x, str)</td>
304<td>Returns position of first occurrence of a substring in string or -1 if the string was not found.</td>
305<td>pos("Alice has a cat", "a") = 7</td>
306</tr>
307<tr>
308<td>insert(str, x, pos)</td>
309<td>Inserts a string into another string</td>
310<td>insert("has ", "Alice a cat", 6) = "Alice has a cat"</td>
311</tr>
312<tr>
313<td>delete(x, start, len)</td>
314<td>Removes part of a string</td>
315<td>delete("Alice has a cat", 0, 10) = "a cat"</td>
316</tr>
317<tr>
318<td>uppercase(x)</td>
319<td>Converts a string into upper case</td>
320<td>uppercase("cats. cats are nice") = "CATS. CATS ARE NICE"</td>
321</tr>
322<tr>
323<td>lowercase(x)</td>
324<td>Converts a string into lower case</td>
325<td>lowercase("CATS. CATS ARE NICE") = "cats. cats are nice"</td>
326</tr>
327<tr>
328<td>strtoint(x)</td>
329<td>Converts string into integer value</td>
330<td>strtoint("5") = 5</td>
331</tr>
332<tr>
333<td>inttostr(x)</td>
334<td>Converts integer value into string</td>
335<td>inttostr(5) = "5"</td>
336</tr>
337</tbody>
338</table>
339<a id="defining" name="defining"></a>
340<h2>Defining user variables and functions</h2>
341To define user variable, use the special operator =. Variable name can consist of small and big letters and digits and must begin with a letter. ProCalc is case-insensitive, thus variable = VARIABLE.
342
343Example:
344<pre><code>a = 5 b = [1,2;3,4] c = "Alice has a cat"</code></pre>
345To define user function, use the same operator =. Function and function parameter naming rule is the same, as for the variables. Sample function definition follows:
346<pre><code>f(x, y)=sqrt(x^2+y^2)</code></pre>
347Function must have at least one parameter. Function parameter names hides variables with the same names. For example:
348<pre><code>x=5 y=2 f(x)=x+y</code></pre>
349In the example, y will be interpreted as a variable, but x - as a function parameter.
350
351<a href="http://spook.freshsite.pl/protools/?page_id=152">Return</a> to the main manual page