﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Go Program - The First internet site for Go programming &#187; Expressions</title>
	<atom:link href="http://www.go-program.com/category/basics/expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.go-program.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 11:31:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Go Language Expressions</title>
		<link>http://www.go-program.com/go-language-expressions/</link>
		<comments>http://www.go-program.com/go-language-expressions/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 15:13:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Expressions]]></category>

		<guid isPermaLink="false">http://www.go-program.com/?p=19</guid>
		<description><![CDATA[



Expressions
Mostly C-like operators.
Binary operators:




Prec


operators


comments




6


* / % &#60;&#60; &#62;&#62; &#38; &#38;^

&#38;^   is &#8220;bit clear&#8221;



5


+ &#8211; &#124; ^


^ is &#8220;xor&#8221;




4


== != &#60; &#60;= &#62; &#62;=







3


&#60;-


communication




2


&#38;&#38;







1


&#124;&#124;








Operators that are also unary: &#38; ! * + &#8211; ^ &#60;-
Unary ^ is complement.

Go vs. C expressions
Surprises for the C programmer:




fewer precedence levels (should be easy)
^ instead of ~ (it&#8217;s [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-9004887195759386";
/* Go programs text ads1 */
google_ad_slot = "3650915252";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Expressions</p>
<p>Mostly C-like operators.</p>
<p>Binary operators:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="119" valign="top">
<p align="center">Prec</p>
</td>
<td width="212" valign="top">
<p align="center">operators</p>
</td>
<td width="162" valign="top">
<p align="center">comments</p>
</td>
</tr>
<tr>
<td width="119" valign="top">
<p align="center">6</p>
</td>
<td width="212" valign="top">
<p align="center">* / % &lt;&lt; &gt;&gt; &amp; &amp;^</p>
</td>
<td width="162" valign="top">&amp;^   is &#8220;bit clear&#8221;</td>
</tr>
<tr>
<td width="119" valign="top">
<p align="center">5</p>
</td>
<td width="212" valign="top">
<p align="center">+ &#8211; | ^</p>
</td>
<td width="162" valign="top">
<p align="center">^ is &#8220;xor&#8221;</p>
</td>
</tr>
<tr>
<td width="119" valign="top">
<p align="center">4</p>
</td>
<td width="212" valign="top">
<p align="center">== != &lt; &lt;= &gt; &gt;=</p>
</td>
<td width="162" valign="top">
<p align="center">
</td>
</tr>
<tr>
<td width="119" valign="top">
<p align="center">3</p>
</td>
<td width="212" valign="top">
<p align="center">&lt;-</p>
</td>
<td width="162" valign="top">
<p align="center">communication</p>
</td>
</tr>
<tr>
<td width="119" valign="top">
<p align="center">2</p>
</td>
<td width="212" valign="top">
<p align="center">&amp;&amp;</p>
</td>
<td width="162" valign="top">
<p align="center">
</td>
</tr>
<tr>
<td width="119" valign="top">
<p align="center">1</p>
</td>
<td width="212" valign="top">
<p align="center">||</p>
</td>
<td width="162" valign="top">
<p align="center">
</td>
</tr>
</tbody>
</table>
<ul>
<li>Operators that are also unary: &amp; ! * + &#8211; ^ &lt;-</li>
<li>Unary ^ is complement.</li>
</ul>
<p style="text-align: center;">Go vs. C expressions</p>
<p>Surprises for the C programmer:<br />
<script type="text/javascript"><!--
google_ad_client = "pub-9004887195759386";
/* Goprograms1 */
google_ad_slot = "8587802801";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
fewer precedence levels (should be easy)</p>
<p>^ instead of ~ (it&#8217;s binary &#8220;exclusive or&#8221; made unary)</p>
<p>++ and &#8212; are not expression operators</p>
<p>(x++ is a statement, not an expression;</p>
<p>*p++ is (*p)++ not *(p++))</p>
<p>&amp;^ is new; handy in constant expressions</p>
<p>&lt;&lt; &gt;&gt; etc. require an unsigned shift count</p>
<p>Non-surprises:</p>
<p>assignment ops work as expected: += &lt;&lt;= &amp;^= etc.</p>
<p>expressions generally look the same (indexing,</p>
<p>function call, etc.)</p>
<p>Examples</p>
<p>+x</p>
<p>23 + 3*x[i]</p>
<p>x &lt;= f()</p>
<p>^a &gt;&gt; b</p>
<p>f() || g()</p>
<p>x == y + 1 &amp;&amp; &lt;-chan_ptr &gt; 0</p>
<p>x &amp;^ 7 // x with the low 3 bits cleared</p>
<p>fmt.Printf(&#8221;%5.2g\n&#8221;, 2*math.Sin(PI/8))</p>
<p>&#8220;hello&#8221; &#8220;, &#8221; &#8220;there&#8221; // lexical cat</p>
<p>&#8220;hello, &#8221; + str // dynamic cat</p>
<p>Numeric conversions</p>
<p>Converting a numeric value from one type to another is a conversion, with syntax like a function call:</p>
<p>uint8(int_var)        // truncate to size</p>
<p>int(float_var)        // truncate fraction</p>
<p>float64(int_var)    // convert to float</p>
<p>Also some conversions to string:</p>
<p>string(0&#215;1234)     // == &#8220;\u1234&#8243;</p>
<p>string(array_of_bytes)   // bytes -&gt; bytes</p>
<p>string(array_of_ints)      // ints -&gt; Unicode/UTF-8</p>
<p>Constants</p>
<p>Numeric constants are &#8220;ideal numbers&#8221;: no size or sign, hence no l or u or ul endings.</p>
<p>Example:</p>
<p>077 // octal</p>
<p>0xFEEDBEEEEEEEEEEEEEEEEEEEEF // hexadecimal</p>
<p>1 &lt;&lt; 100</p>
<p>There are integer and floating-point ideal numbers; syntax of literal determines type:</p>
<p>Example:</p>
<p>1.234e5</p>
<p>1e2 // floating-point</p>
<p>100 // integer</p>
<p>Constant Expressions</p>
<p>Floating point and integer constants can be combined at will, with the type of the resulting expression determined by the type of the constants.</p>
<p>The operations themselves also depend on the type.</p>
<p>2*3.14        // floating point: 6.28</p>
<p>3./2    // floating point: 1.5</p>
<p>3/2     // integer: 1</p>
<p>// high precision:</p>
<p>const Ln2</p>
<p>= 0.693147180559945309417232121458\</p>
<p>176568075500134360255254120680009</p>
<p>const Log2E</p>
<p>= 1/Ln2       // accurate reciprocal</p>
<p>Representation is &#8220;big enough&#8221; (1024 bits now).</p>
<p>Consequences of ideal numbers</p>
<p>The language permits the use of constants without explicit conversion if the value can be represented</p>
<p>var million int = 1e6      / float constant</p>
<p>math.Sin(1)</p>
<p>Constants must be representable in their type.</p>
<p>Example:</p>
<p>^0 is -1 which is not in range 0-255.</p>
<p>uint8(^0)     / bad: -1 can&#8217;t be represented</p>
<p>^uint8(0)     // OK</p>
<p>uint8(350)   // bad: 350 can&#8217;t be represented</p>
<p>uint8(35.0)  // OK: 35</p>
<p>uint8(3.5)     // bad: 3.5 can&#8217;t be represented</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.go-program.com/go-language-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
