/usr/share/doc/groff-base/html/pic-13.html is in groff 1.22.3-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | <!-- Creator : groff version 1.22.3 -->
<!-- CreationDate: Thu Jan 28 14:57:16 2016 -->
<!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 <tt>5e-2</tt>) 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>
<pre style="margin-left:10%; margin-top: 1em">x=5
y=5
[
x:=3
y=3
]
print x " " y</pre>
<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>
<pre style="margin-left:10%; margin-top: 1em">A.x # x coordinate of the center of A
A.ne.y # y coordinate of the northeast corner of A
A.wid # the width of A
A.ht # and its height
2nd last circle.rad # the radius of the 2nd last circle</pre>
<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>
|