diff --git a/README.md b/README.md index ef0f117..996d1ec 100644 --- a/README.md +++ b/README.md @@ -473,20 +473,28 @@ Format Numbers ------- +### Built-in Types ```python = int() # Or: math.floor() = float() = complex(real=0, imag=0) # Or: + j - = fractions.Fraction(numerator=0, denominator=1) ``` * **`'int()'` and `'float()'` raise ValueError on malformed strings.** +### Special Types +```python + = fractions.Fraction(numerator=0, denominator=1) + = decimal.Decimal() +``` +* **Decimal numbers can be represented exactly, unlike floats where `'1.1 + 2.2 == 3.3000000000000003'`.** +* **Their precision can be adjusted with `'decimal.getcontext().prec = '`.** + ### Basic Functions ```python - = pow(, ) # Or: ** - = abs() - = round() - = round(, ±ndigits) # `round(126, -1) == 130` + = pow(, ) # Or: ** + = abs() + = round() + = round(, ±ndigits) # `round(126, -1) == 130` ``` ### Math diff --git a/index.html b/index.html index 5c382ac..d4b3be0 100644 --- a/index.html +++ b/index.html @@ -552,19 +552,27 @@ to_exclusive = <range>.stop {90:b} # '1011010' -

#Numbers

<int>      = int(<float/str/bool>)    # Or: math.floor(<float>)
+

#Numbers

Built-in Types

<int>      = int(<float/str/bool>)    # Or: math.floor(<float>)
 <float>    = float(<int/str/bool>)
 <complex>  = complex(real=0, imag=0)  # Or: <real> + <real>j
-<Fraction> = fractions.Fraction(numerator=0, denominator=1)
-
+
+
  • 'int(<str>)' and 'float(<str>)' raise ValueError on malformed strings.
-

Basic Functions

<num>  = pow(<num>, <num>)            # Or: <num> ** <num>
-<real> = abs(<num>)
-<int>  = round(<real>)
-<real> = round(<real>, ±ndigits)      # `round(126, -1) == 130`
+

Special Types

<Fraction> = fractions.Fraction(numerator=0, denominator=1)
+<Decimal>  = decimal.Decimal(<int/float/str>)
+
+ +
    +
  • Decimal numbers can be represented exactly, unlike floats where '1.1 + 2.2 == 3.3000000000000003'.
  • +
  • Their precision can be adjusted with 'decimal.getcontext().prec = <int>'.
  • +
+

Basic Functions

<num> = pow(<num>, <num>)             # Or: <num> ** <num>
+<num> = abs(<num>)
+<int> = round(<num>)
+<num> = round(<num>, ±ndigits)        # `round(126, -1) == 130`
 

Math

from math import e, pi, inf, nan