<?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: PHP Math Library</title>
	<atom:link href="http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/</link>
	<description>1111111 * 1111111 = 1234567654321</description>
	<pubDate>Fri, 25 Jul 2008 05:41:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Alix</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-257</link>
		<dc:creator>Alix</dc:creator>
		<pubDate>Sun, 12 Aug 2007 05:24:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-257</guid>
		<description>Ok, I got so unhappy with the number_format behavior that I've made my own Number_Format() method for the Math class, I hope you like it.</description>
		<content:encoded><![CDATA[<p>Ok, I got so unhappy with the number_format behavior that I&#8217;ve made my own Number_Format() method for the Math class, I hope you like it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alix</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-256</link>
		<dc:creator>Alix</dc:creator>
		<pubDate>Sun, 12 Aug 2007 04:00:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-256</guid>
		<description>Thanks P L Patodia, I've double checked my code and the expected results are correct, the problem here resides in the number_format() PHP function that I've used for the presentational purpose of this blog (it wouldn't word wrap it otherwise) - it seems like when you tell number_format() to format a really large number the outcome result is wrong. I'll code my own Number_Format() method to handle big numbers and I'll post it here as soon as I finish it.

I've already reported the bug to the PHP team and had to manually add thousands separators to the real 1000th Fibonacci number, thank you very much for your feedback!</description>
		<content:encoded><![CDATA[<p>Thanks P L Patodia, I&#8217;ve double checked my code and the expected results are correct, the problem here resides in the number_format() PHP function that I&#8217;ve used for the presentational purpose of this blog (it wouldn&#8217;t word wrap it otherwise) - it seems like when you tell number_format() to format a really large number the outcome result is wrong. I&#8217;ll code my own Number_Format() method to handle big numbers and I&#8217;ll post it here as soon as I finish it.</p>
<p>I&#8217;ve already reported the bug to the PHP team and had to manually add thousands separators to the real 1000th Fibonacci number, thank you very much for your feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: P L Patodia</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-255</link>
		<dc:creator>P L Patodia</dc:creator>
		<pubDate>Sun, 12 Aug 2007 03:13:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-255</guid>
		<description>The value of 1000th Fibonacci number provided by you is not correct. The correct value is

4346655768693745643568852767504062580256466051737178040248172
9089536555417949051890403879840079255169295922593080322634775
2096896232398733224711616429964409065331879382989696499285160
03704476137795166849228875

This is computed using gp-pari.</description>
		<content:encoded><![CDATA[<p>The value of 1000th Fibonacci number provided by you is not correct. The correct value is</p>
<p>4346655768693745643568852767504062580256466051737178040248172<br />
9089536555417949051890403879840079255169295922593080322634775<br />
2096896232398733224711616429964409065331879382989696499285160<br />
03704476137795166849228875</p>
<p>This is computed using gp-pari.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alix</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-254</link>
		<dc:creator>Alix</dc:creator>
		<pubDate>Wed, 08 Aug 2007 01:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-254</guid>
		<description>Regarding the Math::$bcmath_enabled and Math::$gmp_enabled I'm aware of it, it would still produce the same error if I had used == or any other comparison operator. The reason for these variables being private is that this Math library is part of a much greater library framework I'm developing which runs on a base Singleton pattern class and therefore it doesn't produce those fatal errors. I've forgot to change this when I released it to the public - I'll do it now though.</description>
		<content:encoded><![CDATA[<p>Regarding the Math::$bcmath_enabled and Math::$gmp_enabled I&#8217;m aware of it, it would still produce the same error if I had used == or any other comparison operator. The reason for these variables being private is that this Math library is part of a much greater library framework I&#8217;m developing which runs on a base Singleton pattern class and therefore it doesn&#8217;t produce those fatal errors. I&#8217;ve forgot to change this when I released it to the public - I&#8217;ll do it now though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ed</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-253</link>
		<dc:creator>ed</dc:creator>
		<pubDate>Wed, 08 Aug 2007 01:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-253</guid>
		<description>Wow, that was quick! I had forgotten the purpose of the static keyword. Any reason that factors[] should be a class variable instead of an instance variable?

Another nit. Math()-&#62;$bcmath_enabled and $gmp_enabled should either be &lt;b&gt;public&lt;/b&gt; or accessible via public get and set methods (I think). Here's what happens if they are left &lt;b&gt;private&lt;/b&gt;.

  PHP Fatal error:  Cannot access private property Math::$gmp_enabled in C:\Development\www\math
\Number_Theory.php on line 228

Apparently, PHP doesn't let you check the type (the "===" operator) of private data.</description>
		<content:encoded><![CDATA[<p>Wow, that was quick! I had forgotten the purpose of the static keyword. Any reason that factors[] should be a class variable instead of an instance variable?</p>
<p>Another nit. Math()-&gt;$bcmath_enabled and $gmp_enabled should either be <b>public</b> or accessible via public get and set methods (I think). Here&#8217;s what happens if they are left <b>private</b>.</p>
<p>  PHP Fatal error:  Cannot access private property Math::$gmp_enabled in C:\Development\www\math<br />
\Number_Theory.php on line 228</p>
<p>Apparently, PHP doesn&#8217;t let you check the type (the &#8220;===&#8221; operator) of private data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alix</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-252</link>
		<dc:creator>Alix</dc:creator>
		<pubDate>Wed, 08 Aug 2007 00:51:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-252</guid>
		<description>The Factor() bug it's solved! :) Now it returns the correct result:

&lt;strong&gt;print_r($Number_Theory-&gt;Factor(20));&lt;/strong&gt;

Array
(
    [2] =&gt; 2
    [5] =&gt; 1
)

20 = 2^2 * 5^1 (correct)

&lt;strong&gt;print_r($Number_Theory-&gt;Factor(10));&lt;/strong&gt;

Array
(
    [2] =&gt; 1
    [5] =&gt; 1
)

10 = 2^1 * 5^1 (correct)

I had to add an extra variable to reset the factors, I couldn't find any other way to solve the bug... The source code has been updated, you can find the changes there. ;)</description>
		<content:encoded><![CDATA[<p>The Factor() bug it&#8217;s solved! <img src='http://www.alixaxel.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Now it returns the correct result:</p>
<p><strong>print_r($Number_Theory->Factor(20));</strong></p>
<p>Array<br />
(<br />
    [2] => 2<br />
    [5] => 1<br />
)</p>
<p>20 = 2^2 * 5^1 (correct)</p>
<p><strong>print_r($Number_Theory->Factor(10));</strong></p>
<p>Array<br />
(<br />
    [2] => 1<br />
    [5] => 1<br />
)</p>
<p>10 = 2^1 * 5^1 (correct)</p>
<p>I had to add an extra variable to reset the factors, I couldn&#8217;t find any other way to solve the bug&#8230; The source code has been updated, you can find the changes there. <img src='http://www.alixaxel.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alix</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-251</link>
		<dc:creator>Alix</dc:creator>
		<pubDate>Wed, 08 Aug 2007 00:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-251</guid>
		<description>Hi Ed, thanks for warning me about this unexpected behavior.

The bug you presented seems to be caused by a misuse of the static variable $factors (line 81), which is needed to store the factorization made if the script needs to re-factorize a certain number (line 116).

The problem is that the static variable $factors maintains its state until the script is finished and that causes it to also add the factors of previous factorizations. :(

The good news is that this is the only method where I've used static variables, so as soon as I solve it I'll post here the solution and I'll update the source code.

Again, many thanks for your info! ;)</description>
		<content:encoded><![CDATA[<p>Hi Ed, thanks for warning me about this unexpected behavior.</p>
<p>The bug you presented seems to be caused by a misuse of the static variable $factors (line 81), which is needed to store the factorization made if the script needs to re-factorize a certain number (line 116).</p>
<p>The problem is that the static variable $factors maintains its state until the script is finished and that causes it to also add the factors of previous factorizations. <img src='http://www.alixaxel.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>The good news is that this is the only method where I&#8217;ve used static variables, so as soon as I solve it I&#8217;ll post here the solution and I&#8217;ll update the source code.</p>
<p>Again, many thanks for your info! <img src='http://www.alixaxel.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ed</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-250</link>
		<dc:creator>ed</dc:creator>
		<pubDate>Tue, 07 Aug 2007 23:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-250</guid>
		<description>oops, darn wordpress. my code snippet was truncated.

  require('Number_Theory.php'); 

  $foo = new Number_Theory(); 
  print_r($foo-&#62;Factor(20));
 
  $bar = new Number_Theory(); 
  print_r($bar-&#62;Factor(10));</description>
		<content:encoded><![CDATA[<p>oops, darn wordpress. my code snippet was truncated.</p>
<p>  require(&#8217;Number_Theory.php&#8217;); </p>
<p>  $foo = new Number_Theory();<br />
  print_r($foo-&gt;Factor(20));</p>
<p>  $bar = new Number_Theory();<br />
  print_r($bar-&gt;Factor(10));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ed</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-249</link>
		<dc:creator>ed</dc:creator>
		<pubDate>Tue, 07 Aug 2007 23:35:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-249</guid>
		<description>Forgive my relative ignorance of OO, but why doesn't this test.php work?

Factor(20));
 
 $bar = new Number_Theory(); 
 print_r($bar-&#62;Factor(10)); 
?&#62; 

I get this unexpected result...

Array
(
    [2] =&#62; 2
    [5] =&#62; 1
)
Array
(
    [2] =&#62; 3
    [5] =&#62; 2
)

Why does the factors array persist?</description>
		<content:encoded><![CDATA[<p>Forgive my relative ignorance of OO, but why doesn&#8217;t this test.php work?</p>
<p>Factor(20));</p>
<p> $bar = new Number_Theory();<br />
 print_r($bar-&gt;Factor(10));<br />
?&gt; </p>
<p>I get this unexpected result&#8230;</p>
<p>Array<br />
(<br />
    [2] =&gt; 2<br />
    [5] =&gt; 1<br />
)<br />
Array<br />
(<br />
    [2] =&gt; 3<br />
    [5] =&gt; 2<br />
)</p>
<p>Why does the factors array persist?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alix</title>
		<link>http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-30</link>
		<dc:creator>Alix</dc:creator>
		<pubDate>Wed, 13 Jun 2007 16:52:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/#comment-30</guid>
		<description>Now also on http://www.numbertheory.org/ntw/N1.html thanks to Keith Matthews! :)</description>
		<content:encoded><![CDATA[<p>Now also on <a href="http://www.numbertheory.org/ntw/N1.html" rel="nofollow">http://www.numbertheory.org/ntw/N1.html</a> thanks to Keith Matthews! <img src='http://www.alixaxel.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
