<h2>Introduction</h2>

<p>This document describes a request for comments for a Mathematics namespace within Zend Framework. The reason I am writing this RFC is that I believe mathematics will play a bigger role in the near future in web projects. With WebGL coming up and HTML5's canvas element being there already there I am sure that more complex projects and applications will come in the future. These applications will do more calculations than a 'normal' website. Zend Framework could have a Zend\Math namespace which will act as a core for all mathematical concepts.</p>

<h2>Math currently used in Zend Framework</h2>

<p>At the moment of writing, Zend Framework uses a BigInteger class within the Zend\Crypt namespace. This should be refactored to the Zend\Math namespace in order to improve reusability. Also within the Zend\Locale namespace mathematical functions are often used such as a custom round function, normalize, etc. There even is a special class devoted to doing this (Zend\Locale\Math).</p>

<p>The namespace Zend\XmlRpc contains a wrapper class around Zend\Crypt\Math\BigInteger. I'd like to think that a dependency between Zend\XmlRpc and Zend\Math makes more sense than a dependency between Zend\XmlRpc and Zend\Crypt (unless there actually is done some en/decrypting).</p>

<h2>What would Zend\Math contain?</h2>

<p>As already pointed out the Zend\Math namespace should contain the common used math-related classes in other namespaces. This improves reusability. Of course the options are endless but I'd like to share some first ideas:</p>

<ul>

<li>Basic math functions such as normalize, clamping, etc.</li>

<li>Spline algorithims such as Bezier, Hermite or Catmull-Rom</li>

<li>Random number generating algorithms where "rand();" is not sufficient enough.</li>

<li>Vector operations</li>

<li>Matrix operations</li>

<li>Quaternion operations</li>

<li>Latitude/longitude related calculations (how often did we need to calculate the distance to...?)</li>

</ul>

<h3>Updates</h3>

<ul>

<li>Zend\Math\BigInteger component is ready (with tests). It provides basic arithmetic operations, base conversion and int/binary conversions. Code is <a href="https://github.com/denixport/zf2/tree/feature/math-biginteger/library/Zend/Math/BigInteger/">here</a></li>

</ul>

<ul>

<li>Zend\Math\Rand component is ready. Please see <a href="http://framework.zend.com/wiki/x/HADTAg">updated RFC</a> and code in <a href="https://github.com/denixport/zf2/tree/feature/rand/library/Zend/Math/Rand">this feature branch</a></li>

</ul>

<p>This document describes a request for comments for a Mathematics namespace within Zend Framework. The reason I am writing this RFC is that I believe mathematics will play a bigger role in the near future in web projects. With WebGL coming up and HTML5's canvas element being there already there I am sure that more complex projects and applications will come in the future. These applications will do more calculations than a 'normal' website. Zend Framework could have a Zend\Math namespace which will act as a core for all mathematical concepts.</p>

<h2>Math currently used in Zend Framework</h2>

<p>At the moment of writing, Zend Framework uses a BigInteger class within the Zend\Crypt namespace. This should be refactored to the Zend\Math namespace in order to improve reusability. Also within the Zend\Locale namespace mathematical functions are often used such as a custom round function, normalize, etc. There even is a special class devoted to doing this (Zend\Locale\Math).</p>

<p>The namespace Zend\XmlRpc contains a wrapper class around Zend\Crypt\Math\BigInteger. I'd like to think that a dependency between Zend\XmlRpc and Zend\Math makes more sense than a dependency between Zend\XmlRpc and Zend\Crypt (unless there actually is done some en/decrypting).</p>

<h2>What would Zend\Math contain?</h2>

<p>As already pointed out the Zend\Math namespace should contain the common used math-related classes in other namespaces. This improves reusability. Of course the options are endless but I'd like to share some first ideas:</p>

<ul>

<li>Basic math functions such as normalize, clamping, etc.</li>

<li>Spline algorithims such as Bezier, Hermite or Catmull-Rom</li>

<li>Random number generating algorithms where "rand();" is not sufficient enough.</li>

<li>Vector operations</li>

<li>Matrix operations</li>

<li>Quaternion operations</li>

<li>Latitude/longitude related calculations (how often did we need to calculate the distance to...?)</li>

</ul>

<h3>Updates</h3>

<ul>

<li>Zend\Math\BigInteger component is ready (with tests). It provides basic arithmetic operations, base conversion and int/binary conversions. Code is <a href="https://github.com/denixport/zf2/tree/feature/math-biginteger/library/Zend/Math/BigInteger/">here</a></li>

</ul>

<ul>

<li>Zend\Math\Rand component is ready. Please see <a href="http://framework.zend.com/wiki/x/HADTAg">updated RFC</a> and code in <a href="https://github.com/denixport/zf2/tree/feature/rand/library/Zend/Math/Rand">this feature branch</a></li>

</ul>