Skip to end of metadata
Go to start of metadata

<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>

Labels:
math math Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Feb 29, 2012

    <p>I don't think we have to add the latitude/longitude calculations in Zend\Math. We should insert only mathematical operators. For instance, I would love to see some statistic operators like: averages, standard deviation, etc.<br />
    Actually , there is already a prototype of Zend\Math proposed by Denis Portnov and implemented here: <a class="external-link" href="https://github.com/denixport/zf2-math/tree/master/library/Zend/Math">https://github.com/denixport/zf2-math/tree/master/library/Zend/Math</a>. I think we can start from here.</p>

    1. Feb 29, 2012

      <p>Hi Enrico,</p>

      <p>Thank you for your feedback. I think I agree with you that the latitude/longitude calculations are out of the scope of a Zend\Math component.</p>

      <p>Maybe we need to document what features would be wanted. For me that is basic linear algebra calculations such as Vector and Matrix calculations.</p>