<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: The Zune Bug</title>
	<atom:link href="http://www.bit-player.org/2009/the-zune-bug/feed" rel="self" type="application/rss+xml" />
	<link>http://bit-player.org/2009/the-zune-bug</link>
	<description>An amateur's outlook on computation and mathematics.</description>
	<pubDate>Tue, 07 Feb 2012 07:27:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Palm Pre</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-2153</link>
		<dc:creator>Palm Pre</dc:creator>
		<pubDate>Fri, 19 Jun 2009 17:58:53 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-2153</guid>
		<description>I have had a Zune for the past year now and I am loving every bit of it. Although it is currently in the rapair shop I still use the software. Hopefully when the Zune HD comes out this fall I will be able to get it. Would really like to see how it compares to the iPod Touch.</description>
		<content:encoded><![CDATA[<p>I have had a Zune for the past year now and I am loving every bit of it. Although it is currently in the rapair shop I still use the software. Hopefully when the Zune HD comes out this fall I will be able to get it. Would really like to see how it compares to the iPod Touch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: solicitors northamptonshire</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-2147</link>
		<dc:creator>solicitors northamptonshire</dc:creator>
		<pubDate>Mon, 15 Jun 2009 23:22:07 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-2147</guid>
		<description>One word.. Microsoft.   Is it any wonder that such a simple error could occur on one of their products?!?</description>
		<content:encoded><![CDATA[<p>One word.. Microsoft.   Is it any wonder that such a simple error could occur on one of their products?!?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jagbot</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1910</link>
		<dc:creator>jagbot</dc:creator>
		<pubDate>Sat, 07 Feb 2009 01:00:58 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1910</guid>
		<description>oh my is_leap is wrong!
replace with:

int is_leap (int year) {
  if (year % 4 == 0) {
  if ((year % 100 == 0) {
    if (year % 400 != 0) return 1; else return 0;
  } 
  return 1;
  }
  return 0;
}</description>
		<content:encoded><![CDATA[<p>oh my is_leap is wrong!<br />
replace with:</p>
<p>int is_leap (int year) {<br />
  if (year % 4 == 0) {<br />
  if ((year % 100 == 0) {<br />
    if (year % 400 != 0) return 1; else return 0;<br />
  }<br />
  return 1;<br />
  }<br />
  return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jagbot</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1909</link>
		<dc:creator>jagbot</dc:creator>
		<pubDate>Sat, 07 Feb 2009 00:51:34 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1909</guid>
		<description>// add include stdio.h to above

using 364 solves the problem cleanly.
why all the fuss?</description>
		<content:encoded><![CDATA[<p>// add include stdio.h to above</p>
<p>using 364 solves the problem cleanly.<br />
why all the fuss?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jagbot</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1908</link>
		<dc:creator>jagbot</dc:creator>
		<pubDate>Sat, 07 Feb 2009 00:46:29 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1908</guid>
		<description>#include 

int is_leap (int y) {
if ( (y % 4 == 0) &#38;&#38; (y % 100 == 0) &#38;&#38; (y % 400 != 0)) return 1; else return 0;
}

int main () {
  int days; 
  int year = 1980;
  scanf ("%d", &#38;days);
  while (days &#62; 364) {
   if (is_leap (year) == 1) days -= 366; else days -= 365;
   ++year;
  }
  printf ("year is %d", year);
}</description>
		<content:encoded><![CDATA[<p>#include </p>
<p>int is_leap (int y) {<br />
if ( (y % 4 == 0) &amp;&amp; (y % 100 == 0) &amp;&amp; (y % 400 != 0)) return 1; else return 0;<br />
}</p>
<p>int main () {<br />
  int days;<br />
  int year = 1980;<br />
  scanf (&#8221;%d&#8221;, &amp;days);<br />
  while (days &gt; 364) {<br />
   if (is_leap (year) == 1) days -= 366; else days -= 365;<br />
   ++year;<br />
  }<br />
  printf (&#8221;year is %d&#8221;, year);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roland</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1907</link>
		<dc:creator>roland</dc:creator>
		<pubDate>Thu, 29 Jan 2009 15:14:38 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1907</guid>
		<description>Max Hailperin:

Great comment. Maybe the person who deleted the error message thought the code works, so this clause will never be executed and is therefore unnecessary.</description>
		<content:encoded><![CDATA[<p>Max Hailperin:</p>
<p>Great comment. Maybe the person who deleted the error message thought the code works, so this clause will never be executed and is therefore unnecessary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1905</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 20 Jan 2009 11:37:17 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1905</guid>
		<description>just change the condition for the while loop and the code can be that easy:
    year = ORIGINYEAR;
    while ((days &#62; 365 &#38;&#38; !IsLeapYear(year)) &#124;&#124; (days &#62; 366 &#38;&#38; IsLeapYear(year))
    {
        if (IsLeapYear(year))
        {   
                days -= 366;
        }
        else
        {
            days -= 365;
        }
       year += 1;
    }</description>
		<content:encoded><![CDATA[<p>just change the condition for the while loop and the code can be that easy:<br />
    year = ORIGINYEAR;<br />
    while ((days &gt; 365 &amp;&amp; !IsLeapYear(year)) || (days &gt; 366 &amp;&amp; IsLeapYear(year))<br />
    {<br />
        if (IsLeapYear(year))<br />
        {<br />
                days -= 366;<br />
        }<br />
        else<br />
        {<br />
            days -= 365;<br />
        }<br />
       year += 1;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Mather</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1903</link>
		<dc:creator>Michael Mather</dc:creator>
		<pubDate>Thu, 15 Jan 2009 23:29:08 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1903</guid>
		<description>The following needs to be tested, but has the advantage of not having any loops. It should be good until the year 2100.

// calculate the year from 1980 = 0
year = (days * 4 - 4) / 1461;

// calculate the day within that year, from 1 jan = 1
days -= (year * 1461 + 3) / 4;

// adjust the year to start from 1980
year += 1980;</description>
		<content:encoded><![CDATA[<p>The following needs to be tested, but has the advantage of not having any loops. It should be good until the year 2100.</p>
<p>// calculate the year from 1980 = 0<br />
year = (days * 4 - 4) / 1461;</p>
<p>// calculate the day within that year, from 1 jan = 1<br />
days -= (year * 1461 + 3) / 4;</p>
<p>// adjust the year to start from 1980<br />
year += 1980;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max Hailperin</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1901</link>
		<dc:creator>Max Hailperin</dc:creator>
		<pubDate>Wed, 14 Jan 2009 02:00:19 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1901</guid>
		<description>@dagor17: The text you quoted from Barak Pearlmutter's comment wasn't from the C code he included within his comment, but rather from the explanatory text talking about that code.   It is a mathematical equation, not an assignment statement.  You didn't quote it in full: you missed the DaysInYear(y) that appears at the end of the equation.  The equation contains a term that would be written with a big sigma if it were in conventional mathematical notation rather than this typed form.  The equation is saying that after any number of complete iterations through the loop (including 0, i.e., before it starts), the original value of days is equal to the current value of days plus the sum of DaysInYear(y) for y ranging from ORIGINYEAR up to but not including the current value of year.  (Note that before the first iteration of the loop, there are no such values of y, so the sum would be 0.)</description>
		<content:encoded><![CDATA[<p>@dagor17: The text you quoted from Barak Pearlmutter&#8217;s comment wasn&#8217;t from the C code he included within his comment, but rather from the explanatory text talking about that code.   It is a mathematical equation, not an assignment statement.  You didn&#8217;t quote it in full: you missed the DaysInYear(y) that appears at the end of the equation.  The equation contains a term that would be written with a big sigma if it were in conventional mathematical notation rather than this typed form.  The equation is saying that after any number of complete iterations through the loop (including 0, i.e., before it starts), the original value of days is equal to the current value of days plus the sum of DaysInYear(y) for y ranging from ORIGINYEAR up to but not including the current value of year.  (Note that before the first iteration of the loop, there are no such values of y, so the sum would be 0.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dargor17</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1900</link>
		<dc:creator>dargor17</dc:creator>
		<pubDate>Tue, 13 Jan 2009 15:24:54 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1900</guid>
		<description>About your last question, I don't think there's ever a reason to substitute a general code with a code working under some assumptions unless there is a huge difference in performance or maintainability...
I don't really know the hardware specifics of the zune, but I guess leaving one more "if" should not affect the time it takes to execute the function that much...

@Barak A. Pearlmutter (or any one who can help me):
what does this construct mean? I don't think I've ever seen it... Is it C? Or is just some formatting problem of the blog software?
original_days = days + sum_{y : ORIGINYEAR &#60;= y &#60; year}</description>
		<content:encoded><![CDATA[<p>About your last question, I don&#8217;t think there&#8217;s ever a reason to substitute a general code with a code working under some assumptions unless there is a huge difference in performance or maintainability&#8230;<br />
I don&#8217;t really know the hardware specifics of the zune, but I guess leaving one more &#8220;if&#8221; should not affect the time it takes to execute the function that much&#8230;</p>
<p>@Barak A. Pearlmutter (or any one who can help me):<br />
what does this construct mean? I don&#8217;t think I&#8217;ve ever seen it&#8230; Is it C? Or is just some formatting problem of the blog software?<br />
original_days = days + sum_{y : ORIGINYEAR &lt;= y &lt; year}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: krick</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1899</link>
		<dc:creator>krick</dc:creator>
		<pubDate>Mon, 12 Jan 2009 21:16:31 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1899</guid>
		<description>Here's a more concise leap year function...

int isLeapYear(int year)
{
	return !(year % 100 ? year % 4 : year % 400);
}

...
Krick
http://www.tankadin.com</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a more concise leap year function&#8230;</p>
<p>int isLeapYear(int year)<br />
{<br />
	return !(year % 100 ? year % 4 : year % 400);<br />
}</p>
<p>&#8230;<br />
Krick<br />
<a href="http://www.tankadin.com" rel="nofollow">http://www.tankadin.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anthony</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1895</link>
		<dc:creator>Anthony</dc:creator>
		<pubDate>Thu, 08 Jan 2009 17:16:19 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1895</guid>
		<description>To those that claim "dealing with dates is not easy", a really simple unit test would have caught that bug  - like feeding the function integers from 1 to 1000 and testing that it did not crash for any of them. Bonus points for testing that it returned something sensible each time. 

Sadly, this code probably wasn't unit tested at all.</description>
		<content:encoded><![CDATA[<p>To those that claim &#8220;dealing with dates is not easy&#8221;, a really simple unit test would have caught that bug  - like feeding the function integers from 1 to 1000 and testing that it did not crash for any of them. Bonus points for testing that it returned something sensible each time. </p>
<p>Sadly, this code probably wasn&#8217;t unit tested at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Minter</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1894</link>
		<dc:creator>Dave Minter</dc:creator>
		<pubDate>Thu, 08 Jan 2009 16:00:35 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1894</guid>
		<description>If clarity is the aim, why not just split the logic into its constituent procedures?

1. Determine if we have passed the end of the year

2. Determine if a given year is a leap year

3. Adjust the day and year counts.

I admit that I may be missing some subtlety as I don't really follow why a loop was used at all - but I'd expect something like the following three functions:

// (1)
if( isLeapYear(year) ) { 
   return days &#62; 366;
} else {
   return days &#62; 365;
}

// We've already got (2) from the original implementation.

// (3)
if(isAfterEndOfYear(days,year)) {
   days = 1;
   year += 1; 
}

Even if I'm off base somewhere the problem of clarity seems to be more to do with trying to combine too many logical tests into a single</description>
		<content:encoded><![CDATA[<p>If clarity is the aim, why not just split the logic into its constituent procedures?</p>
<p>1. Determine if we have passed the end of the year</p>
<p>2. Determine if a given year is a leap year</p>
<p>3. Adjust the day and year counts.</p>
<p>I admit that I may be missing some subtlety as I don&#8217;t really follow why a loop was used at all - but I&#8217;d expect something like the following three functions:</p>
<p>// (1)<br />
if( isLeapYear(year) ) {<br />
   return days &gt; 366;<br />
} else {<br />
   return days &gt; 365;<br />
}</p>
<p>// We&#8217;ve already got (2) from the original implementation.</p>
<p>// (3)<br />
if(isAfterEndOfYear(days,year)) {<br />
   days = 1;<br />
   year += 1;<br />
}</p>
<p>Even if I&#8217;m off base somewhere the problem of clarity seems to be more to do with trying to combine too many logical tests into a single</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Ward</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1892</link>
		<dc:creator>Jim Ward</dc:creator>
		<pubDate>Tue, 06 Jan 2009 21:28:17 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1892</guid>
		<description>Software is a garden, ever generation must dig in and turn over the soil. Sometimes you kill the flowers, but you learn.  I don't fault Microsoft for rewriting glibc, I work with many coders who aren't curious at all about how things work, they call all these black boxes, like glibc. They're plumbers, not programmers.</description>
		<content:encoded><![CDATA[<p>Software is a garden, ever generation must dig in and turn over the soil. Sometimes you kill the flowers, but you learn.  I don&#8217;t fault Microsoft for rewriting glibc, I work with many coders who aren&#8217;t curious at all about how things work, they call all these black boxes, like glibc. They&#8217;re plumbers, not programmers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max Hailperin</title>
		<link>http://bit-player.org/2009/the-zune-bug#comment-1891</link>
		<dc:creator>Max Hailperin</dc:creator>
		<pubDate>Tue, 06 Jan 2009 18:15:05 +0000</pubDate>
		<guid isPermaLink="false">http://bit-player.org/?p=248#comment-1891</guid>
		<description>Reply 3 of 3:

Another plausible replacement for the buggy loop would use a test-in-the-middle loop.  Like Brian, I tested this in a different programming language, so apologize if the C is a bit off:

while(TRUE){

int daysInYear = IsLeapYear(year) ? 366 : 365;

if(days &#60;= daysInYear) break;

days -= daysInYear;

year += 1;

}</description>
		<content:encoded><![CDATA[<p>Reply 3 of 3:</p>
<p>Another plausible replacement for the buggy loop would use a test-in-the-middle loop.  Like Brian, I tested this in a different programming language, so apologize if the C is a bit off:</p>
<p>while(TRUE){</p>
<p>int daysInYear = IsLeapYear(year) ? 366 : 365;</p>
<p>if(days &lt;= daysInYear) break;</p>
<p>days -= daysInYear;</p>
<p>year += 1;</p>
<p>}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

