<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: First steps with report writing and LaTeX</title>
	<link>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/</link>
	<description>DFWBL !!!</description>
	<pubDate>Fri, 18 May 2012 13:59:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Davide Pasca</title>
		<link>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/#comment-3090</link>
		<pubDate>Thu, 18 Jan 2007 18:39:37 +0000</pubDate>
		<guid>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/#comment-3090</guid>
					<description>Talk about the difficulty of documenting 8P
Wordpress is officially a piece of crap. I just created a test user and posted a comment with that account. Apparently there is no way to delete your own comments even if you are a registered user !!
I'm seriously considering going back to blogger.com.. especially now that it allows to host the blog on your own domain.</description>
		<content:encoded><![CDATA[<p>Talk about the difficulty of documenting 8P<br />
Wordpress is officially a piece of crap. I just created a test user and posted a comment with that account. Apparently there is no way to delete your own comments even if you are a registered user !!<br />
I&#8217;m seriously considering going back to blogger.com.. especially now that it allows to host the blog on your own domain.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: rince</title>
		<link>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/#comment-3084</link>
		<pubDate>Thu, 18 Jan 2007 17:58:44 +0000</pubDate>
		<guid>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/#comment-3084</guid>
					<description>eeehhh wtf, half of my comment didnt make it.... bah, even parts in the middle of the article have gone missing...</description>
		<content:encoded><![CDATA[<p>eeehhh wtf, half of my comment didnt make it&#8230;. bah, even parts in the middle of the article have gone missing&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: rince</title>
		<link>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/#comment-3083</link>
		<pubDate>Thu, 18 Jan 2007 17:57:19 +0000</pubDate>
		<guid>http://v3.kazzuya.com/first-steps-with-report-writing-and-latex/#comment-3083</guid>
					<description>Problem with documenting is that it progressively occupies more and more of your time as you try to keep it up to date.

Anyway, so recently I ran into a problem where I needed to solve a set of 686 linear equations. (To calculate coeffcients of a 686 degree polynomial). So I quickly ran into the problem of not having enough bits in the built in c/c++ numerical types to store intermediate results. A number raised to the power of 686 needs a lot of bits to represent itself!!!!

So I implemented integer math code that works on arbitrary size arrays of unsigned int, thus giving me as many bits as I need. This was actually not too trivial, especially the multiplication and division!

Anyway I thought this could be a good opportunity to give c++ operator overriding another try, as I always stayed away from that on the grounds of it being very obfuscated to debug later on. And very quickly I indeed confirmed my initial views! Here is the case:

I have the following code:

// constructor
integer::integer(const unsigned int bits, const unsigned int *pValue)
{
	assert((bits &amp;#38; 0x1F) == 0);
	mpValue = new unsigned int[bits / 0x20];
	assert(mpValue);
	unsigned int i;
	for(i = 0; i &amp;#62; 32);
	} 	
}


// operator -
integer integer::operator-() const
{
	integer neg(mBits, mpValue);	
	neg.twos_compliment( );
	return neg;
}

So lets say  I do something like:

unsigned int arr[2] = { 1, 0 };
integer b(64, arr);
b =-b;

Looks good, right? But it crashes in a destructor of &quot;integer&quot; trying to delete mpValue. 

Why?

Well what seems to happen is that when the - operator is called c++ creates a 'hidden' instance of &quot;integer&quot; when executing

return neg;

Since there is no '=' anywhere in that statement the default assignment operator gets called so the mpValue in this 'hidden' instance is now pointing to the same place as mpValue of 'neg'. 

Then when the - operator goes out of scope destructor of 'neg' gets called and deletes mpValue, but the 'hidden' instance is still alive because it is needed for the b =-b statement, however once b=-b is executed, destructor for the 'hidden' instance gets called and it crashes trying to delete its mpValue, because it already has been deleted....

So the fix was to implement another constructor:

// constructor
integer::integer(integer &amp;#38;src)
{
	mBits = src.bits( );
	mpValue = new unsigned int[mBits / 0x20];
	unsigned int i;
	for(i = 0; i </description>
		<content:encoded><![CDATA[<p>Problem with documenting is that it progressively occupies more and more of your time as you try to keep it up to date.</p>
<p>Anyway, so recently I ran into a problem where I needed to solve a set of 686 linear equations. (To calculate coeffcients of a 686 degree polynomial). So I quickly ran into the problem of not having enough bits in the built in c/c++ numerical types to store intermediate results. A number raised to the power of 686 needs a lot of bits to represent itself!!!!</p>
<p>So I implemented integer math code that works on arbitrary size arrays of unsigned int, thus giving me as many bits as I need. This was actually not too trivial, especially the multiplication and division!</p>
<p>Anyway I thought this could be a good opportunity to give c++ operator overriding another try, as I always stayed away from that on the grounds of it being very obfuscated to debug later on. And very quickly I indeed confirmed my initial views! Here is the case:</p>
<p>I have the following code:</p>
<p>// constructor<br />
integer::integer(const unsigned int bits, const unsigned int *pValue)<br />
{<br />
	assert((bits &amp; 0&#215;1F) == 0);<br />
	mpValue = new unsigned int[bits / 0&#215;20];<br />
	assert(mpValue);<br />
	unsigned int i;<br />
	for(i = 0; i &gt; 32);<br />
	}<br />
}</p>
<p>// operator -<br />
integer integer::operator-() const<br />
{<br />
	integer neg(mBits, mpValue);<br />
	neg.twos_compliment( );<br />
	return neg;<br />
}</p>
<p>So lets say  I do something like:</p>
<p>unsigned int arr[2] = { 1, 0 };<br />
integer b(64, arr);<br />
b =-b;</p>
<p>Looks good, right? But it crashes in a destructor of &#8220;integer&#8221; trying to delete mpValue. </p>
<p>Why?</p>
<p>Well what seems to happen is that when the - operator is called c++ creates a &#8216;hidden&#8217; instance of &#8220;integer&#8221; when executing</p>
<p>return neg;</p>
<p>Since there is no &#8216;=&#8217; anywhere in that statement the default assignment operator gets called so the mpValue in this &#8216;hidden&#8217; instance is now pointing to the same place as mpValue of &#8216;neg&#8217;. </p>
<p>Then when the - operator goes out of scope destructor of &#8216;neg&#8217; gets called and deletes mpValue, but the &#8216;hidden&#8217; instance is still alive because it is needed for the b =-b statement, however once b=-b is executed, destructor for the &#8216;hidden&#8217; instance gets called and it crashes trying to delete its mpValue, because it already has been deleted&#8230;.</p>
<p>So the fix was to implement another constructor:</p>
<p>// constructor<br />
integer::integer(integer &amp;src)<br />
{<br />
	mBits = src.bits( );<br />
	mpValue = new unsigned int[mBits / 0&#215;20];<br />
	unsigned int i;<br />
	for(i = 0; i
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

