Fast fractions data type for rational numbers. Cythonized version of 'fractions.Fraction'.
Python’s Fraction data type is an excellent way to do exact money calculations and largely beats Decimal in terms of simplicity, accuracy and safety. Clearly not in terms of speed, though, given the cdecimal accelerator in Py3.3+.
quicktions is an adaptation of the original fractions module (as included in CPython 3.5) that is compiled and optimised with Cython into a fast, native extension module.
Compared to the standard library fractions module in Py2.7 and Py3.4, quicktions is currently about 10x faster, and still about 6x faster than the current version in Python 3.5. It’s also about 15x faster than the (Python implemented) decimal module in Py2.7.
For documentation, see the Python standard library’s fractions module:
- Substantially faster normalisation (and therefore instantiation) in Py3.5+.
- // (floordiv) now follows the expected rounding behaviour when used with floats (by converting to float first), and is much faster for integer operations.
- Fix return type of divmod(), where the first item should be an integer.
- Further speed up mod and divmod operations.
- Faster mod and divmod calculation.
- Faster normalisation and fraction string parsing.
- Add support for Python 3.7.
- Built using Cython 0.29.
- Speed up Fraction creation from a string value by 3-5x.
- Built using Cython 0.28.1.
- Result of power operator (**) was not normalised for negative values.
- Built using Cython 0.27.2.
- Rebuilt using Cython 0.26.1 to improve support of Python 3.7.
- repair the faster instantiation from Decimal values in Python 3.6
- avoid potential glitch for certain large numbers in normalisation under Python 2.x
- change hash function in Python 2.x to match that of fractions.Fraction
- faster instantiation from float values
- faster instantiation from Decimal values in Python 3.6
- Fraction.imag property could return non-zero
- parsing strings with long fraction parts could use an incorrect scale
- faster instantiation from float and string values
- fix test in Python 2.x
- faster normalisation (and thus instantiation)
- faster math operations
- enable legacy division support in Python 2.x
- minor behavioural fixes in corner cases under Python 2.x (now passes all test in Py2.7 as well)
- cache hash value of Fractions
- initial public release
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.