Popular Python recipes tagged "meta:requires=fractions"http://code.activestate.com/recipes/langs/python/tags/meta:requires=fractions/2013-12-27T06:43:59-08:00ActiveState Code RecipesPublic Key Encryption (RSA) (Python) 2013-12-27T06:43:59-08:00Mohammad Taha Jahangirhttp://code.activestate.com/recipes/users/4188847/http://code.activestate.com/recipes/578797-public-key-encryption-rsa/ <p style="color: grey"> Python recipe 578797 by <a href="/recipes/users/4188847/">Mohammad Taha Jahangir</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/inverse/">inverse</a>, <a href="/recipes/tags/multiplicative/">multiplicative</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/publickey/">publickey</a>, <a href="/recipes/tags/rsa/">rsa</a>). Revision 3. </p> <p>Simple code to create and use public/private keypairs. Accompanied by a rudimentary encoder.</p> Continued fractions (Python) 2013-08-22T07:15:47-07:00Glenn Hutchingshttp://code.activestate.com/recipes/users/4175415/http://code.activestate.com/recipes/578647-continued-fractions/ <p style="color: grey"> Python recipe 578647 by <a href="/recipes/users/4175415/">Glenn Hutchings</a> (<a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/fractions/">fractions</a>). Revision 2. </p> <p>A class representing a <a href="https://en.wikipedia.org/wiki/Continued_fraction">continued fraction</a>.</p> Public Key Encryption (RSA) (Python) 2012-05-12T23:34:22-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577737-public-key-encryption-rsa/ <p style="color: grey"> Python recipe 577737 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/inverse/">inverse</a>, <a href="/recipes/tags/multiplicative/">multiplicative</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/publickey/">publickey</a>, <a href="/recipes/tags/rsa/">rsa</a>). Revision 2. </p> <p>Simple code to create and use public/private keypairs. Accompanied by a rudimentary encoder.</p> Generate equally-spaced floats (Python) 2011-09-24T18:49:39-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577878-generate-equally-spaced-floats/ <p style="color: grey"> Python recipe 577878 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/range/">range</a>, <a href="/recipes/tags/spread/">spread</a>). </p> <p>Generating a list of equally-spaced floats can surprising due to floating point rounding. See, for example, the recipe for a <a href="http://code.activestate.com/recipes/577068">floating point range</a>. One way of avoiding some surprises is by changing the API: instead of specifying a start, stop and step values, instead use a start, stop and count:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; list(spread(0.0, 2.1, 7)) [0.0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8] </code></pre> <p>Like <a href="http://code.activestate.com/recipes/577068">frange</a> <code>spread</code> takes an optional mode argument to select whether the start and end values are included. By default, start is included and end is not, and exactly count values are returned.</p> Equally-spaced floats part 2 (Python) 2011-09-27T15:48:00-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/577881-equally-spaced-floats-part-2/ <p style="color: grey"> Python recipe 577881 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/float/">float</a>, <a href="/recipes/tags/range/">range</a>, <a href="/recipes/tags/spread/">spread</a>). </p> <p>See the recipe <a href="http://code.activestate.com/recipes/577878">here</a> for a description of the problem.</p> <p>This variant allows the user to choose between two APIs, either by supplying the count, start value and end value:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; list(spread(5, 1.0, end=2.0)) [1.0, 1.2, 1.4, 1.6, 1.8] </code></pre> <p>or the count, start value and step size:</p> <pre class="prettyprint"><code>&gt;&gt;&gt; list(spread(5, 1.0, step=-0.25)) [1.0, 0.75, 0.5, 0.25, 0.0] </code></pre> <p>As before, the count argument specifies how many subdivisions are made. The optional argument <code>mode</code> selects whether the start and end values are included. By default, start is included and end is not, and exactly count values are returned.</p> Binary floating point summation accurate to full precision (Python) 2009-03-28T23:32:08-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/393090-binary-floating-point-summation-accurate-to-full-p/ <p style="color: grey"> Python recipe 393090 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 5. </p> <p>Completely eliminates rounding errors and loss of significance due to catastrophic cancellation during summation. Achieves exactness by keeping full precision intermediate subtotals. Offers three alternative approaches, each using a different technique to store exact subtotals.</p>