Browse Source

Numbers

pull/54/head
Jure Šorn 4 years ago
parent
commit
cbde122c56
2 changed files with 42 additions and 42 deletions
  1. 42
      README.md
  2. 42
      index.html

42
README.md

@ -470,9 +470,9 @@ Format
### Ints
```python
{90:c} # 'Z'
{90:b} # '1011010'
{90:X} # '5A'
{90:c} # 'Z'
{90:b} # '1011010'
{90:X} # '5A'
```
@ -480,11 +480,11 @@ Numbers
-------
### Types
```python
<int> = int(<float/str/bool>) # Or: math.floor(<float>)
<float> = float(<int/str/bool>) # Or: <real><int>
<complex> = complex(real=0, imag=0) # Or: <real> ± <real>j
<Fraction> = fractions.Fraction(numerator=0, denominator=1)
<Decimal> = decimal.Decimal(<str/int/float>)
<int> = int(<float/str/bool>) # Or: math.floor(<float>)
<float> = float(<int/str/bool>) # Or: <real><int>
<complex> = complex(real=0, imag=0) # Or: <real> ± <real>j
<Fraction> = fractions.Fraction(0, 1) # Or: Fraction(numerator=0, denominator=1)
<Decimal> = decimal.Decimal(<str/int>) # Or: Decimal((sign, digits, exponent))
```
* **`'int(<str>)'` and `'float(<str>)'` raise ValueError on malformed strings.**
* **Decimal numbers can be represented exactly, unlike floats where `'1.1 + 2.2 != 3.3'`.**
@ -492,9 +492,9 @@ Numbers
### Basic Functions
```python
<num> = pow(<num>, <num>) # Or: <num> ** <num>
<num> = abs(<num>) # <float> = abs(<complex>)
<num> = round(<num> [, ±ndigits]) # `round(126, -1) == 130`
<num> = pow(<num>, <num>) # Or: <num> ** <num>
<num> = abs(<num>) # <float> = abs(<complex>)
<num> = round(<num> [, ±ndigits]) # `round(126, -1) == 130`
```
### Math
@ -520,20 +520,20 @@ shuffle(<list>)
### Bin, Hex
```python
<int> = 0b<bin> # Or: 0x<hex>
<int> = int('<bin>', 2) # Or: int('<hex>', 16)
<int> = int('0b<bin>', 0) # Or: int('0x<hex>', 0)
'0b<bin>' = bin(<int>) # Or: hex(<int>)
<int> = 0b<bin> # Or: 0x<hex>
<int> = int('<bin>', 2) # Or: int('<hex>', 16)
<int> = int('0b<bin>', 0) # Or: int('0x<hex>', 0)
'0b<bin>' = bin(<int>) # Or: hex(<int>)
```
### Bitwise Operators
```python
<int> = <int> & <int> # And
<int> = <int> | <int> # Or
<int> = <int> ^ <int> # Xor (0 if both bits equal)
<int> = <int> << n_bits # Shift left
<int> = <int> >> n_bits # Shift right
<int> = ~<int> # Compliment (flips bits)
<int> = <int> & <int> # And
<int> = <int> | <int> # Or
<int> = <int> ^ <int> # Xor (0 if both bits equal)
<int> = <int> << n_bits # Shift left
<int> = <int> >> n_bits # Shift right
<int> = ~<int> # Compliment (flips bits)
```

42
index.html

@ -559,16 +559,16 @@ to_exclusive = &lt;range&gt;.stop
| 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |
+---------------+-----------------+-----------------+-----------------+-----------------+
</code></pre>
<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span>
{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span>
{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span>
<div><h3 id="ints">Ints</h3><pre><code class="python language-python hljs">{<span class="hljs-number">90</span>:c} <span class="hljs-comment"># 'Z'</span>
{<span class="hljs-number">90</span>:b} <span class="hljs-comment"># '1011010'</span>
{<span class="hljs-number">90</span>:X} <span class="hljs-comment"># '5A'</span>
</code></pre></div>
<div><h2 id="numbers"><a href="#numbers" name="numbers">#</a>Numbers</h2><div><h3 id="types">Types</h3><pre><code class="python language-python hljs">&lt;int&gt; = int(&lt;float/str/bool&gt;) <span class="hljs-comment"># Or: math.floor(&lt;float&gt;)</span>
&lt;float&gt; = float(&lt;int/str/bool&gt;) <span class="hljs-comment"># Or: &lt;real&gt;&lt;int&gt;</span>
&lt;complex&gt; = complex(real=<span class="hljs-number">0</span>, imag=<span class="hljs-number">0</span>) <span class="hljs-comment"># Or: &lt;real&gt; ± &lt;real&gt;j</span>
&lt;Fraction&gt; = fractions.Fraction(numerator=<span class="hljs-number">0</span>, denominator=<span class="hljs-number">1</span>)
&lt;Decimal&gt; = decimal.Decimal(&lt;str/int/float&gt;)
<div><h2 id="numbers"><a href="#numbers" name="numbers">#</a>Numbers</h2><div><h3 id="types">Types</h3><pre><code class="python language-python hljs">&lt;int&gt; = int(&lt;float/str/bool&gt;) <span class="hljs-comment"># Or: math.floor(&lt;float&gt;)</span>
&lt;float&gt; = float(&lt;int/str/bool&gt;) <span class="hljs-comment"># Or: &lt;real&gt;&lt;int&gt;</span>
&lt;complex&gt; = complex(real=<span class="hljs-number">0</span>, imag=<span class="hljs-number">0</span>) <span class="hljs-comment"># Or: &lt;real&gt; ± &lt;real&gt;j</span>
&lt;Fraction&gt; = fractions.Fraction(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>) <span class="hljs-comment"># Or: Fraction(numerator=0, denominator=1)</span>
&lt;Decimal&gt; = decimal.Decimal(&lt;str/int&gt;) <span class="hljs-comment"># Or: Decimal((sign, digits, exponent))</span>
</code></pre></div></div>
@ -577,9 +577,9 @@ to_exclusive = &lt;range&gt;.stop
<li><strong>Decimal numbers can be represented exactly, unlike floats where <code class="python hljs"><span class="hljs-string">'1.1 + 2.2 != 3.3'</span></code>.</strong></li>
<li><strong>Precision of decimal operations is set with: <code class="python hljs"><span class="hljs-string">'decimal.getcontext().prec = &lt;int&gt;'</span></code>.</strong></li>
</ul>
<div><h3 id="basicfunctions">Basic Functions</h3><pre><code class="python language-python hljs">&lt;num&gt; = pow(&lt;num&gt;, &lt;num&gt;) <span class="hljs-comment"># Or: &lt;num&gt; ** &lt;num&gt;</span>
&lt;num&gt; = abs(&lt;num&gt;) <span class="hljs-comment"># &lt;float&gt; = abs(&lt;complex&gt;)</span>
&lt;num&gt; = round(&lt;num&gt; [, ±ndigits]) <span class="hljs-comment"># `round(126, -1) == 130`</span>
<div><h3 id="basicfunctions">Basic Functions</h3><pre><code class="python language-python hljs">&lt;num&gt; = pow(&lt;num&gt;, &lt;num&gt;) <span class="hljs-comment"># Or: &lt;num&gt; ** &lt;num&gt;</span>
&lt;num&gt; = abs(&lt;num&gt;) <span class="hljs-comment"># &lt;float&gt; = abs(&lt;complex&gt;)</span>
&lt;num&gt; = round(&lt;num&gt; [, ±ndigits]) <span class="hljs-comment"># `round(126, -1) == 130`</span>
</code></pre></div>
<div><h3 id="math">Math</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> e, pi, inf, nan, isinf, isnan
@ -597,18 +597,18 @@ to_exclusive = &lt;range&gt;.stop
shuffle(&lt;list&gt;)
</code></pre></div>
<div><h3 id="binhex">Bin, Hex</h3><pre><code class="python language-python hljs">&lt;int&gt; = <span class="hljs-number">0</span>b&lt;bin&gt; <span class="hljs-comment"># Or: 0x&lt;hex&gt;</span>
&lt;int&gt; = int(<span class="hljs-string">'&lt;bin&gt;'</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Or: int('&lt;hex&gt;', 16)</span>
&lt;int&gt; = int(<span class="hljs-string">'0b&lt;bin&gt;'</span>, <span class="hljs-number">0</span>) <span class="hljs-comment"># Or: int('0x&lt;hex&gt;', 0)</span>
<span class="hljs-string">'0b&lt;bin&gt;'</span> = bin(&lt;int&gt;) <span class="hljs-comment"># Or: hex(&lt;int&gt;)</span>
<div><h3 id="binhex">Bin, Hex</h3><pre><code class="python language-python hljs">&lt;int&gt; = <span class="hljs-number">0</span>b&lt;bin&gt; <span class="hljs-comment"># Or: 0x&lt;hex&gt;</span>
&lt;int&gt; = int(<span class="hljs-string">'&lt;bin&gt;'</span>, <span class="hljs-number">2</span>) <span class="hljs-comment"># Or: int('&lt;hex&gt;', 16)</span>
&lt;int&gt; = int(<span class="hljs-string">'0b&lt;bin&gt;'</span>, <span class="hljs-number">0</span>) <span class="hljs-comment"># Or: int('0x&lt;hex&gt;', 0)</span>
<span class="hljs-string">'0b&lt;bin&gt;'</span> = bin(&lt;int&gt;) <span class="hljs-comment"># Or: hex(&lt;int&gt;)</span>
</code></pre></div>
<div><h3 id="bitwiseoperators">Bitwise Operators</h3><pre><code class="python language-python hljs">&lt;int&gt; = &lt;int&gt; &amp; &lt;int&gt; <span class="hljs-comment"># And</span>
&lt;int&gt; = &lt;int&gt; | &lt;int&gt; <span class="hljs-comment"># Or</span>
&lt;int&gt; = &lt;int&gt; ^ &lt;int&gt; <span class="hljs-comment"># Xor (0 if both bits equal)</span>
&lt;int&gt; = &lt;int&gt; &lt;&lt; n_bits <span class="hljs-comment"># Shift left</span>
&lt;int&gt; = &lt;int&gt; &gt;&gt; n_bits <span class="hljs-comment"># Shift right</span>
&lt;int&gt; = ~&lt;int&gt; <span class="hljs-comment"># Compliment (flips bits)</span>
<div><h3 id="bitwiseoperators">Bitwise Operators</h3><pre><code class="python language-python hljs">&lt;int&gt; = &lt;int&gt; &amp; &lt;int&gt; <span class="hljs-comment"># And</span>
&lt;int&gt; = &lt;int&gt; | &lt;int&gt; <span class="hljs-comment"># Or</span>
&lt;int&gt; = &lt;int&gt; ^ &lt;int&gt; <span class="hljs-comment"># Xor (0 if both bits equal)</span>
&lt;int&gt; = &lt;int&gt; &lt;&lt; n_bits <span class="hljs-comment"># Shift left</span>
&lt;int&gt; = &lt;int&gt; &gt;&gt; n_bits <span class="hljs-comment"># Shift right</span>
&lt;int&gt; = ~&lt;int&gt; <span class="hljs-comment"># Compliment (flips bits)</span>
</code></pre></div>
<div><h2 id="combinatorics"><a href="#combinatorics" name="combinatorics">#</a>Combinatorics</h2><ul>

Loading…
Cancel
Save