<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Yet another bug</title>
	<atom:link href="http://www.certpal.com/blogs/2010/04/yet-another-bug/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/</link>
	<description>Technology and certifications</description>
	<lastBuildDate>Thu, 02 Feb 2012 09:47:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: CertPal</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1205</link>
		<dc:creator>CertPal</dc:creator>
		<pubDate>Tue, 08 Jun 2010 15:53:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1205</guid>
		<description>&lt;a href=&quot;#comment-1204&quot; rel=&quot;nofollow&quot;&gt;@Ludovicc Brenta &lt;/a&gt; 

I do not know Ada, but you raise a good point. Thanks for sharing that. 

On a side note, this bug can actually be exploited in certain cases.</description>
		<content:encoded><![CDATA[<p><a href="#comment-1204" rel="nofollow">@Ludovicc Brenta </a> </p>
<p>I do not know Ada, but you raise a good point. Thanks for sharing that. </p>
<p>On a side note, this bug can actually be exploited in certain cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ludovicc Brenta</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1204</link>
		<dc:creator>Ludovicc Brenta</dc:creator>
		<pubDate>Tue, 08 Jun 2010 14:34:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1204</guid>
		<description>This bug cannot exist in Ada because, in Ada, integers do not overflow; instead they raise an exception (Constraint_Error, &quot;overflow check failed&quot;) that allows you to find the problem immediately. Combine this with the standard library types for manipulating dates, which ensure you cannot *possibly* have e.g. month numbers outside the range 1 ..12, etc:

package Standard is
  [...]
  type Duration is delta implementation-defined range implementation-defined;
end Standard;

(Duration is a fixed-point type representing seconds with absolute accuracy, as opposed to a floating-point type that has relative accuracy).

package Ada.Calendar is
  type Time is private;
  subtype Year_Number  is Integer range 1901 .. 2399;
  subtype Month_Number is Integer range 1 .. 12;
  subtype Day_Number   is Integer range 1 .. 31;
  subtype Day_Duration is Duration range 0.0 .. 86_400.0;
  function Clock return Time;
  function Year   (Date : Time) return Year_Number;
  function Month  (Date : Time) return Month_Number;
  function Day    (Date : Time) return Day_Number;
  function Seconds(Date : Time) return Day_Duration;
  procedure Split (Date  : in Time;
                   Year    : out Year_Number;
                   Month   : out Month_Number;
                   Day     : out Day_Number;
                   Seconds : out Day_Duration);
  function Time_Of(Year  : Year_Number;
                   Month   : Month_Number;
                   Day     : Day_Number;
                   Seconds : Day_Duration := 0.0)
   return Time;
  function &quot;+&quot; (Left : Time;   Right : Duration) return Time;
  function &quot;+&quot; (Left : Duration; Right : Time) return Time;
  function &quot;-&quot; (Left : Time;   Right : Duration) return Time;
  function &quot;-&quot; (Left : Time;   Right : Time) return Duration;
  function &quot;&lt;&quot; (Left, Right : Time) return Boolean;
  function &quot;&quot; (Left, Right : Time) return Boolean;
  function &quot;&gt;=&quot;(Left, Right : Time) return Boolean;
  Time_Error : exception;
private
   ... -- not specified by the language
end Ada.Calendar;

Ada programmers consequently spend comparatively very little time debugging their software.</description>
		<content:encoded><![CDATA[<p>This bug cannot exist in Ada because, in Ada, integers do not overflow; instead they raise an exception (Constraint_Error, &#8220;overflow check failed&#8221;) that allows you to find the problem immediately. Combine this with the standard library types for manipulating dates, which ensure you cannot *possibly* have e.g. month numbers outside the range 1 ..12, etc:</p>
<p>package Standard is<br />
  [...]<br />
  type Duration is delta implementation-defined range implementation-defined;<br />
end Standard;</p>
<p>(Duration is a fixed-point type representing seconds with absolute accuracy, as opposed to a floating-point type that has relative accuracy).</p>
<p>package Ada.Calendar is<br />
  type Time is private;<br />
  subtype Year_Number  is Integer range 1901 .. 2399;<br />
  subtype Month_Number is Integer range 1 .. 12;<br />
  subtype Day_Number   is Integer range 1 .. 31;<br />
  subtype Day_Duration is Duration range 0.0 .. 86_400.0;<br />
  function Clock return Time;<br />
  function Year   (Date : Time) return Year_Number;<br />
  function Month  (Date : Time) return Month_Number;<br />
  function Day    (Date : Time) return Day_Number;<br />
  function Seconds(Date : Time) return Day_Duration;<br />
  procedure Split (Date  : in Time;<br />
                   Year    : out Year_Number;<br />
                   Month   : out Month_Number;<br />
                   Day     : out Day_Number;<br />
                   Seconds : out Day_Duration);<br />
  function Time_Of(Year  : Year_Number;<br />
                   Month   : Month_Number;<br />
                   Day     : Day_Number;<br />
                   Seconds : Day_Duration := 0.0)<br />
   return Time;<br />
  function &#8220;+&#8221; (Left : Time;   Right : Duration) return Time;<br />
  function &#8220;+&#8221; (Left : Duration; Right : Time) return Time;<br />
  function &#8220;-&#8221; (Left : Time;   Right : Duration) return Time;<br />
  function &#8220;-&#8221; (Left : Time;   Right : Time) return Duration;<br />
  function &#8220;&lt;&quot; (Left, Right : Time) return Boolean;<br />
  function &quot;&#8221; (Left, Right : Time) return Boolean;<br />
  function &#8220;&gt;=&#8221;(Left, Right : Time) return Boolean;<br />
  Time_Error : exception;<br />
private<br />
   &#8230; &#8212; not specified by the language<br />
end Ada.Calendar;</p>
<p>Ada programmers consequently spend comparatively very little time debugging their software.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christophe Roussy</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1172</link>
		<dc:creator>Christophe Roussy</dc:creator>
		<pubDate>Mon, 03 May 2010 16:17:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1172</guid>
		<description>Hi,
using the calendar is tricky too, I wrote a post featuring a few calendar related puzzlers:
http://javarizon.wordpress.com/2010/04/25/java-calendar-puzzlers/</description>
		<content:encoded><![CDATA[<p>Hi,<br />
using the calendar is tricky too, I wrote a post featuring a few calendar related puzzlers:<br />
<a href="http://javarizon.wordpress.com/2010/04/25/java-calendar-puzzlers/" rel="nofollow">http://javarizon.wordpress.com/2010/04/25/java-calendar-puzzlers/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CertPal</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1170</link>
		<dc:creator>CertPal</dc:creator>
		<pubDate>Mon, 03 May 2010 04:34:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1170</guid>
		<description>&lt;a href=&quot;#comment-1166&quot; rel=&quot;nofollow&quot;&gt;@Anonymous Coward &lt;/a&gt; 
Never looked at JODA time. Ah one more java lib out there

&lt;a href=&quot;#comment-1163&quot; rel=&quot;nofollow&quot;&gt;@Nov &lt;/a&gt; 
&lt;a href=&quot;#comment-1164&quot; rel=&quot;nofollow&quot;&gt;@steven &lt;/a&gt; 
&lt;a href=&quot;#comment-1167&quot; rel=&quot;nofollow&quot;&gt;@DD605 &lt;/a&gt; 
&lt;a href=&quot;#comment-1168&quot; rel=&quot;nofollow&quot;&gt;@Michal R. &lt;/a&gt; 

Yep that is a solution one could use. If one of the participants in the operations is a long, the result would have to be a long.

&lt;a href=&quot;#comment-1169&quot; rel=&quot;nofollow&quot;&gt;@knalli &lt;/a&gt; 
&lt;a href=&quot;#comment-1162&quot; rel=&quot;nofollow&quot;&gt;@Fabricio Tuosto &lt;/a&gt; 

Yep I agree that a calendar could be used here to provide a better solution.

When I said bug, I meant it was a bug from the method and developer&#039;s perspective. This component is supposed to return the expiry time but it does the opposite sometimes :)</description>
		<content:encoded><![CDATA[<p><a href="#comment-1166" rel="nofollow">@Anonymous Coward </a><br />
Never looked at JODA time. Ah one more java lib out there</p>
<p><a href="#comment-1163" rel="nofollow">@Nov </a><br />
<a href="#comment-1164" rel="nofollow">@steven </a><br />
<a href="#comment-1167" rel="nofollow">@DD605 </a><br />
<a href="#comment-1168" rel="nofollow">@Michal R. </a> </p>
<p>Yep that is a solution one could use. If one of the participants in the operations is a long, the result would have to be a long.</p>
<p><a href="#comment-1169" rel="nofollow">@knalli </a><br />
<a href="#comment-1162" rel="nofollow">@Fabricio Tuosto </a> </p>
<p>Yep I agree that a calendar could be used here to provide a better solution.</p>
<p>When I said bug, I meant it was a bug from the method and developer&#8217;s perspective. This component is supposed to return the expiry time but it does the opposite sometimes <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: knalli</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1169</link>
		<dc:creator>knalli</dc:creator>
		<pubDate>Sun, 02 May 2010 17:53:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1169</guid>
		<description>Actually, this is not a bug, but a little bit the fault of owned developer. Even C has this issue.

The developer assumes that
  long future = 3600 * 24 * days * 1000;

will compute as long, but that is not true. Because every component of &quot;3600 * 24 * days * 1000&quot; is int - the result is int, too. The type of &quot;future&quot; does not matter (because it is irrelevant for the computing part).

If you want a calculating &quot;on long level&quot; at least one component must be long. If this is not so, you must at least one of them. Option 1 use no &quot;int days&quot; but &quot;long days&quot; or option 2 cast one of the factors, like &quot;3600L&quot;.

The issue, other story: 
float d = 1/2

The result is not 0.5 because int/int has no decimals. 


Anyway, the usage of calendar and &quot;real&quot; 40 days would be better. The next 40 days can be 3456000001 seconds, too. :)</description>
		<content:encoded><![CDATA[<p>Actually, this is not a bug, but a little bit the fault of owned developer. Even C has this issue.</p>
<p>The developer assumes that<br />
  long future = 3600 * 24 * days * 1000;</p>
<p>will compute as long, but that is not true. Because every component of &#8220;3600 * 24 * days * 1000&#8243; is int &#8211; the result is int, too. The type of &#8220;future&#8221; does not matter (because it is irrelevant for the computing part).</p>
<p>If you want a calculating &#8220;on long level&#8221; at least one component must be long. If this is not so, you must at least one of them. Option 1 use no &#8220;int days&#8221; but &#8220;long days&#8221; or option 2 cast one of the factors, like &#8220;3600L&#8221;.</p>
<p>The issue, other story:<br />
float d = 1/2</p>
<p>The result is not 0.5 because int/int has no decimals. </p>
<p>Anyway, the usage of calendar and &#8220;real&#8221; 40 days would be better. The next 40 days can be 3456000001 seconds, too. <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal R.</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1168</link>
		<dc:creator>Michal R.</dc:creator>
		<pubDate>Sun, 02 May 2010 10:34:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1168</guid>
		<description>Why not just write it this way:
long future = 3600L * 24L * days * 1000L;</description>
		<content:encoded><![CDATA[<p>Why not just write it this way:<br />
long future = 3600L * 24L * days * 1000L;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DD605</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1167</link>
		<dc:creator>DD605</dc:creator>
		<pubDate>Sat, 01 May 2010 17:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1167</guid>
		<description>no bug.
but if your parameter days is a int the calculation is executed  as a (correct) multiplication of 4 int&#039;s and the result is put in a variable of type long.
if you want to do the calculation as long&#039;s at least one of the numbers should be of the type long.
so long future = 3600l * 24 * days * 1000; will do the job as you wish</description>
		<content:encoded><![CDATA[<p>no bug.<br />
but if your parameter days is a int the calculation is executed  as a (correct) multiplication of 4 int&#8217;s and the result is put in a variable of type long.<br />
if you want to do the calculation as long&#8217;s at least one of the numbers should be of the type long.<br />
so long future = 3600l * 24 * days * 1000; will do the job as you wish</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous Coward</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1166</link>
		<dc:creator>Anonymous Coward</dc:creator>
		<pubDate>Sat, 01 May 2010 09:04:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1166</guid>
		<description>Can you tell what is wrong with it?

Yes, you are not using Joda Time http://joda-time.sourceforge.net/ for your date and time calculations :D</description>
		<content:encoded><![CDATA[<p>Can you tell what is wrong with it?</p>
<p>Yes, you are not using Joda Time <a href="http://joda-time.sourceforge.net/" rel="nofollow">http://joda-time.sourceforge.net/</a> for your date and time calculations <img src='http://www.certpal.com/blogs/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steven</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1164</link>
		<dc:creator>steven</dc:creator>
		<pubDate>Sat, 01 May 2010 00:20:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1164</guid>
		<description>so it&#039;s this part?: 3600 * 24 * days * 1000
where each factor is an integer</description>
		<content:encoded><![CDATA[<p>so it&#8217;s this part?: 3600 * 24 * days * 1000<br />
where each factor is an integer</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nov</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1163</link>
		<dc:creator>Nov</dc:creator>
		<pubDate>Fri, 30 Apr 2010 23:36:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1163</guid>
		<description>Here is the bug:
long future = 3600 * 24 * days * 1000;
Simple fix would be:
long future = 3600 * 24 * days * 1000L;</description>
		<content:encoded><![CDATA[<p>Here is the bug:<br />
long future = 3600 * 24 * days * 1000;<br />
Simple fix would be:<br />
long future = 3600 * 24 * days * 1000L;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabricio Tuosto</title>
		<link>http://www.certpal.com/blogs/2010/04/yet-another-bug/comment-page-1/#comment-1162</link>
		<dc:creator>Fabricio Tuosto</dc:creator>
		<pubDate>Fri, 30 Apr 2010 22:48:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.certpal.com/blogs/?p=686#comment-1162</guid>
		<description>A way to solve dates math is with calendar more or less like this
Date date = new Date(); // received as parameter
int days = 5; // 
Calendar expiry = Calendar.getIntance();
expiry.setTime(date);
expiry.add(Calendar.DATE,days);
return new Timestamp(expiry.getTimeInMillis());</description>
		<content:encoded><![CDATA[<p>A way to solve dates math is with calendar more or less like this<br />
Date date = new Date(); // received as parameter<br />
int days = 5; //<br />
Calendar expiry = Calendar.getIntance();<br />
expiry.setTime(date);<br />
expiry.add(Calendar.DATE,days);<br />
return new Timestamp(expiry.getTimeInMillis());</p>
]]></content:encoded>
	</item>
</channel>
</rss>

