Server IP : 195.201.23.43 / Your IP : 18.217.163.75 Web Server : Apache System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64 User : kdecoratie ( 1041) PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/groff/html/ |
Upload File : |
<!-- Creator : groff version 1.22.4 --> <!-- CreationDate: Sat Mar 21 12:27:30 2020 --> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta name="generator" content="groff -Thtml, see www.gnu.org"> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <meta name="Content-Style" content="text/css"> <style type="text/css"> p { margin-top: 0; margin-bottom: 0; vertical-align: top } pre { margin-top: 0; margin-bottom: 0; vertical-align: top } table { margin-top: 0; margin-bottom: 0; vertical-align: top } h1 { text-align: center } </style> <title>pic-13.html</title> </head> <hr> [ <a href="pic-12.html">prev</a> | <a href="pic-14.html">next</a> | <a href="pic.html">top</a> ] <hr> <h2>13. Expressions, Variables, and Assignment <a name="13. Expressions, Variables, and Assignment"></a> </h2> <p style="margin-top: 1em"><font color="#000000">A number is a valid expression, of course (all numbers are stored internally as floating-point). Decimal-point notation is acceptable; in GNU <b>gpic</b>, scientific notation in C’s ‘e’ format (like 5e-2) is accepted.</font></p> <p style="margin-top: 1em"><font color="#000000">Anywhere a number is expected, the language also accepts a variable. Variables may be the built-in style variable described in the last section, or new variables created by assignment.</font></p> <p style="margin-top: 1em"><font color="#000000">DWB <b>pic</b> supports only the ordinary assignment via <b>=</b>, which defines the variable (on the left side of the equal sign) in the current block if it is not already defined there, and then changes the value (on the right side) in the current block. The variable is not visible outside of the block. This is similar to the C programming language where a variable within a block shadows a variable with the same name outside of the block.</font></p> <p style="margin-top: 1em"><font color="#000000">GNU <b>gpic</b> supports an alternate form of assignment using <b>:=</b>. The variable must already be defined, and the value is assigned to that variable without creating a variable local to the current block. For example, this</font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000">x=5 <br> y=5 <br> [ <br> x:=3 <br> y=3 <br> ] <br> print x " " y</font></p> <p style="margin-top: 1em"><font color="#000000">prints <b>3 5</b>.</font></p> <p style="margin-top: 1em"><font color="#000000">You can use the height, width, radius, and x and y coordinates of any object or corner in expressions. If <b>A</b> is an object label or name, all the following are valid:</font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000">A.x # x coordinate of the center of A <br> A.ne.y # y coordinate of the northeast corner of A <br> A.wid # the width of A <br> A.ht # and its height <br> 2nd last circle.rad # the radius of the 2nd last circle</font></p> <p style="margin-top: 1em"><font color="#000000">Note the second expression, showing how to extract a corner coordinate.</font></p> <p style="margin-top: 1em"><font color="#000000">Basic arithmetic resembling those of C operators are available; <b>+</b>, <b>*</b>, <b>-</b>, <b>/</b>, and <b>%</b>. So is <b>^</b> for exponentiation. Grouping is permitted in the usual way using parentheses. GNU <b>gpic</b> allows logical operators to appear in expressions; <b>!</b> (logical negation, not factorial), <b>&&</b>, <b>||</b>, <b>==</b>, <b>!=</b>, <b>>=</b>, <b><=</b>, <b><</b>, <b>></b>.</font></p> <p style="margin-top: 1em"><font color="#000000">Various built-in functions are supported: <b>sin(</b><i>x</i><b>)</b>, <b>cos(</b><i>x</i><b>)</b>, <b>log(</b><i>x</i><b>)</b>, <b>exp(</b><i>x</i><b>)</b>, <b>sqrt(</b><i>x</i><b>)</b>, <b>max(</b><i>x</i><b>,</b><i>y</i><b>)</b>, <b>atan2(</b><i>x</i><b>,</b><i>y</i><b>)</b>, <b>min(</b><i>x</i><b>,</b><i>y</i><b>)</b>, <b>int(</b><i>x</i><b>)</b>, <b>rand()</b>, and <b>srand()</b>. Both <b>exp</b> and <b>log</b> are base 10; <b>int</b> does integer truncation; <b>rand()</b> returns a random number in [0-1), and <b>srand()</b> sets the seed for a new sequence of pseudo-random numbers to be returned by <b>rand()</b> (<b>srand()</b> is a GNU extension).</font></p> <p style="margin-top: 1em"><font color="#000000">GNU <b>gpic</b> also documents a one-argument form or rand, <b>rand(</b><i>x</i><b>)</b>, which returns a random number between 1 and <i>x</i>, but this is deprecated and may be removed in a future version.</font></p> <p style="margin-top: 1em"><font color="#000000">The function <b>sprintf()</b> behaves like a C <i>sprintf</i>(3) function that only takes %, %e, %f, and %g format strings.</font></p> <hr> [ <a href="pic-12.html">prev</a> | <a href="pic-14.html">next</a> | <a href="pic.html">top</a> ] <hr>Private