<?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>Laughing Meme &#187; big numbers</title>
	<atom:link href="http://laughingmeme.org/tag/big-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://laughingmeme.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 29 Jan 2012 21:54:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>4294967295 and MySQL INT(20) Syntax Blows</title>
		<link>http://laughingmeme.org/2010/01/24/4294967295-and-mysql-int20-syntax-blows/</link>
		<comments>http://laughingmeme.org/2010/01/24/4294967295-and-mysql-int20-syntax-blows/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 06:01:39 +0000</pubDate>
		<dc:creator>Kellan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[big numbers]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://laughingmeme.org/?p=4412</guid>
		<description><![CDATA[When you&#8217;ve been working with a technology for a long time, it&#8217;s difficult not to develop Stockholm syndrome. Not sure when I started using MySQL, but I bought my first license in 1998. I think it wasn&#8217;t until mid-to-late &#8217;98 when we had to call Monty long distance to Sweden to get help with some [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/pjern/1339311643/"><img src="http://farm2.static.flickr.com/1156/1339311643_3acb54e40a.jpg" alt="Big Numbers 2 by pjern." title="" width="500" height="332" border="0"></a></p>

<p>When you&#8217;ve been working with a technology for a long time, it&#8217;s difficult not to develop Stockholm syndrome.  Not sure when I started using MySQL, but I bought my first license in 1998.   I think it wasn&#8217;t until mid-to-late &#8217;98 when we had to call <a href="http://monty-says.blogspot.com/">Monty</a> long distance to Sweden to get help with some tricky issues.  Which is to say its been a long time since I thought about how confusing MySQL&#8217;s CREATE TABLE syntax can be.</p>

<p>Which is not to say that the documentation isn&#8217;t clear:</p>

<blockquote>
  <p><em class="replaceable"><code>M</code></em> indicates the maximum display width for integer types. The maximum legal display width is 255.
  Display width is unrelated to the range of values a type can contain, as described in <a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html" title="10.2. Numeric Types">Section 10.2, “Numeric Types”</a>. For floating-point and fixed-point types, <em class="replaceable"><code>M</code></em> is the total number of digits that can be stored.</p>
</blockquote>

<p>But last week Flickr had a hiccup.  We hit <a href="http://www.flickr.com/photos/oming91745/4294967295/">4,294,967,295</a> photos. Or as a geek might say it, the largest number that can be represented by a 32-bit unsigned integer.  This didn&#8217;t exactly catch us by surprise.  We&#8217;d switched to using 64-bit ids for some things January, Friday the 13th, 2006.  That and we got bit a few years ago when we hit 2,147,483,647 photos (that&#8217;d be the max signed 32 bit integer).  Shortly after that we did a full audit of our tables.</p>

<p>But somehow we went on writing code after that, and we managed to slip a couple of new tables into the mix.  And some of those tables ended up with <code>INT(20)</code> columns.  Which simply mean we were adding some non-significant zeros to pad the display but truncating photo ids over 4294967295.</p>

<p>INT(5), INT(10), INT(20), and INT(255) all store the same amount of data.</p>

<p>Funny thing is, when I told this story to folks last week, this caught them by surprise.  Sophisticated engineers, some of whom had deployed quite large MySQL backed sites. Because they were right, that syntax is dumb. And confusing.  And I&#8217;d been taking it for granted so long I hadn&#8217;t thought about it in a decade.  Which is why I&#8217;d bother to write a blog post about a popular piece of software, behaving exactly as it&#8217;s extensively documented to work. </p>

<p>Also, it&#8217;s interesting to note how if you keep making the same mistakes they become easier and easier to fix.</p>

<p>If you&#8217;re ever debugging a problem and you see the number 42-mumble-mumble-mumble-7295 you&#8217;ve run out of 32-bit storage.
If you see 2-mumble-mumble-mumble-647 (2147483647) you&#8217;ve run out of signed 32-bit storage.
167-mumble-mumble-15 (16777215) you&#8217;ve run out of 24-bits
and 65-mumble-mumble-35 (65535) you&#8217;ve run out of 16-bits of integers.</p>

<p>Somehow those numbers just jump out at me after all this time, you ignore the numbers in the middle, and notice the significant bits at the front and the end.</p>

<p>Photo from <a href="http://www.flickr.com/photos/pjern/">pjern</a></p>
]]></content:encoded>
			<wfw:commentRss>http://laughingmeme.org/2010/01/24/4294967295-and-mysql-int20-syntax-blows/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>bceval: arbitrary precision math for PHP without extensions</title>
		<link>http://laughingmeme.org/2008/03/25/bceval-arbitrary-precision-math-for-php-without-extensions/</link>
		<comments>http://laughingmeme.org/2008/03/25/bceval-arbitrary-precision-math-for-php-without-extensions/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 20:50:38 +0000</pubDate>
		<dc:creator>Kellan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[big numbers]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://laughingmeme.org/2008/03/25/bceval-arbitrary-precision-math-for-php-without-extensions/</guid>
		<description><![CDATA[I needed arbitrary precision math in PHP, and wasn&#8217;t willing to rebuild PHP to add the bcmath extensions. All hail backticks. function bceval($expr) { return trim(`echo "$expr" &#124; bc`); } Used like so $end = bceval("$start + $batchsize - 1"); Wet cat territory.]]></description>
			<content:encoded><![CDATA[<p>I needed arbitrary precision math in PHP, and wasn&#8217;t willing to rebuild PHP to add the <a href="http://www.php.net/bc">bcmath</a> extensions.  All hail backticks.</p>

<pre><code>function bceval($expr) {
  return trim(`echo "$expr" | bc`);
}
</code></pre>

<p>Used like so</p>

<pre><code>$end = bceval("$start + $batchsize - 1");
</code></pre>

<p><a href="http://simonwillison.net/2003/Jun/24/philosophy/">Wet cat</a> territory.</p>
]]></content:encoded>
			<wfw:commentRss>http://laughingmeme.org/2008/03/25/bceval-arbitrary-precision-math-for-php-without-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

