Fractions#
Module introducing all the functions used to handle fractions.
- frac(*arg: int | float | mpq) int | float | mpq [source]#
Returns a fraction instantiated from the module defined by the FRACTION constant. If more than two numbers are provided, an error is raised.
- Parameters:
Numeric – One or two numbers.
- Returns:
The fraction.
- Return type:
Numeric
- str_as_frac(s: str) int | float | mpq [source]#
Converts a string to a fraction instantiated from the module defined by the FRACTION constant.
- Parameters:
s (str) – A string representing a number.
- Returns:
The fraction.
- Return type:
Numeric
- FLOAT_FRAC = 'float'#
Value of the FRACTION constant when float fractions are to be used.
- FRACTION = 'gmpy2'#
Constant describing which module to use for computing fractions. It can either be “gmpy2” or “float”. The default is “gmpy2”.
- GMPY_FRAC = 'gmpy2'#
Value of the FRACTION constant when gumpy2 fractions are to be used.
- Numeric#
Type for numeric values. Is the union of int, float and mpq fractions (from the gumpy2 package).
alias of
int
|float
|mpq