Skip to main content

Fast fractions data type for rational numbers. Cythonized version of 'fractions.Fraction'.

Project description

Python’s Fraction data type is an excellent way to do exact calculations with unlimited rational numbers and largely beats Decimal in terms of simplicity, accuracy and safety. Clearly not in terms of speed, though, given the cdecimal accelerator in Python 3.3+.

quicktions is an adaptation of the original fractions module (as included in CPython 3.13a3) that is compiled and optimised with Cython into a fast, native extension module.

Compared to the standard library fractions module of CPython, computations in quicktions are about

  • 10x faster in Python 2.7 and 3.4

  • 6x faster in Python 3.5

  • 3-4x faster in Python 3.10

Compared to the fractions module in CPython 3.10, instantiation of a Fraction in quicktions is also

  • 5-15x faster from a floating point string value (e.g. Fraction("123.456789"))

  • 3-5x faster from a floating point value (e.g. Fraction(123.456789))

  • 2-4x faster from an integer numerator-denominator pair (e.g. Fraction(123, 456))

We provide a set of micro-benchmarks here:

https://github.com/scoder/quicktions/tree/master/benchmark

As of quicktions 1.12, the different number types and implementations compare as follows in CPython 3.10:

Average times for all 'create' benchmarks:
float               :    36.17 us (1.0x)
Decimal             :   111.71 us (3.1x)
Fraction            :   111.98 us (3.1x)
PyFraction          :   398.80 us (11.0x)

Average times for all 'compute' benchmarks:
float               :     4.53 us (1.0x)
Decimal             :    16.62 us (3.7x)
Fraction            :    72.91 us (16.1x)
PyFraction          :   251.93 us (55.6x)

While not as fast as the C implemented decimal module in Python 3, quicktions is about 15x faster than the Python implemented decimal module in Python 2.7.

For documentation, see the Python standard library’s fractions module:

https://docs.python.org/3/library/fractions.html

ChangeLog

1.18 (2024-04-03)

  • New binary wheels were added built with gcc 12 (manylinux_2_28).

  • x86_64 wheels now require SSE4.2.

  • Built using Cython 3.0.10.

1.17 (2024-03-24)

  • Math operations were sped up by inlined binary GCD calculation.

1.16 (2024-01-10)

1.15 (2023-08-27)

  • Add support for Python 3.12 by using Cython 3.0.2.

1.14 (2023-03-19)

1.13 (2022-01-11)

  • Parsing very long numbers from a fraction string was very slow, even slower than fractions.Fraction. The parser is now faster in all cases (and still much faster for shorter numbers).

  • Fraction did not implement __int__. https://bugs.python.org/issue44547

1.12 (2022-01-07)

1.11 (2019-12-19)

  • Fix OverflowError when parsing string values with long decimal parts.

1.10 (2019-08-23)

  • hash(fraction) is substantially faster in Py3.8+, following an optimisation in CPython 3.9 (https://bugs.python.org/issue37863).

  • New method fraction.as_integer_ratio().

1.9 (2018-12-26)

  • 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.

1.8 (2018-12-26)

  • Faster mod and divmod calculation.

1.7 (2018-10-16)

  • Faster normalisation and fraction string parsing.

  • Add support for Python 3.7.

  • Built using Cython 0.29.

1.6 (2018-03-23)

  • Speed up Fraction creation from a string value by 3-5x.

  • Built using Cython 0.28.1.

1.5 (2017-10-22)

  • Result of power operator (**) was not normalised for negative values.

  • Built using Cython 0.27.2.

1.4 (2017-09-16)

  • Rebuilt using Cython 0.26.1 to improve support of Python 3.7.

1.3 (2016-07-24)

  • repair the faster instantiation from Decimal values in Python 3.6

  • avoid potential glitch for certain large numbers in normalisation under Python 2.x

1.2 (2016-04-08)

  • change hash function in Python 2.x to match that of fractions.Fraction

1.1 (2016-03-29)

  • faster instantiation from float values

  • faster instantiation from Decimal values in Python 3.6

1.0 (2015-09-10)

  • Fraction.imag property could return non-zero

  • parsing strings with long fraction parts could use an incorrect scale

0.7 (2014-10-09)

  • faster instantiation from float and string values

  • fix test in Python 2.x

0.6 (2014-10-09)

  • faster normalisation (and thus instantiation)

0.5 (2014-10-06)

  • faster math operations

0.4 (2014-10-06)

  • enable legacy division support in Python 2.x

0.3 (2014-10-05)

  • minor behavioural fixes in corner cases under Python 2.x (now passes all test in Py2.7 as well)

0.2 (2014-10-03)

  • cache hash value of Fractions

0.1 (2014-09-24)

  • initial public release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quicktions-1.18.tar.gz (371.0 kB view hashes)

Uploaded Source

Built Distributions

quicktions-1.18-cp312-cp312-win_amd64.whl (100.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

quicktions-1.18-cp312-cp312-win32.whl (91.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

quicktions-1.18-cp312-cp312-musllinux_1_2_x86_64.whl (132.7 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

quicktions-1.18-cp312-cp312-musllinux_1_2_aarch64.whl (120.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ ARM64

quicktions-1.18-cp312-cp312-musllinux_1_1_x86_64.whl (137.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

quicktions-1.18-cp312-cp312-musllinux_1_1_aarch64.whl (126.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

quicktions-1.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (132.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (120.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (145.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp312-cp312-macosx_11_0_universal2.whl (232.6 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ universal2 (ARM64, x86-64)

quicktions-1.18-cp312-cp312-macosx_11_0_arm64.whl (116.4 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

quicktions-1.18-cp312-cp312-macosx_10_9_x86_64.whl (124.6 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

quicktions-1.18-cp311-cp311-win_amd64.whl (98.1 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

quicktions-1.18-cp311-cp311-win32.whl (88.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

quicktions-1.18-cp311-cp311-musllinux_1_2_x86_64.whl (135.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

quicktions-1.18-cp311-cp311-musllinux_1_2_aarch64.whl (123.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ ARM64

quicktions-1.18-cp311-cp311-musllinux_1_1_x86_64.whl (138.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

quicktions-1.18-cp311-cp311-musllinux_1_1_aarch64.whl (129.0 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

quicktions-1.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (135.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (123.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (146.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp311-cp311-macosx_11_0_arm64.whl (114.5 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

quicktions-1.18-cp311-cp311-macosx_10_9_x86_64.whl (120.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

quicktions-1.18-cp310-cp310-win_amd64.whl (98.2 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

quicktions-1.18-cp310-cp310-win32.whl (90.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

quicktions-1.18-cp310-cp310-musllinux_1_2_x86_64.whl (135.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

quicktions-1.18-cp310-cp310-musllinux_1_2_aarch64.whl (123.3 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ ARM64

quicktions-1.18-cp310-cp310-musllinux_1_1_x86_64.whl (139.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

quicktions-1.18-cp310-cp310-musllinux_1_1_aarch64.whl (130.0 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

quicktions-1.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (135.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (123.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (154.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp310-cp310-macosx_11_0_arm64.whl (114.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

quicktions-1.18-cp310-cp310-macosx_10_9_x86_64.whl (120.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

quicktions-1.18-cp39-cp39-win_amd64.whl (98.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

quicktions-1.18-cp39-cp39-win32.whl (90.9 kB view hashes)

Uploaded CPython 3.9 Windows x86

quicktions-1.18-cp39-cp39-musllinux_1_2_x86_64.whl (136.2 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

quicktions-1.18-cp39-cp39-musllinux_1_2_aarch64.whl (124.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ ARM64

quicktions-1.18-cp39-cp39-musllinux_1_1_x86_64.whl (139.7 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

quicktions-1.18-cp39-cp39-musllinux_1_1_aarch64.whl (130.6 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

quicktions-1.18-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (135.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (124.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (154.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp39-cp39-macosx_11_0_arm64.whl (115.4 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

quicktions-1.18-cp39-cp39-macosx_10_9_x86_64.whl (120.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

quicktions-1.18-cp38-cp38-win_amd64.whl (99.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

quicktions-1.18-cp38-cp38-win32.whl (90.9 kB view hashes)

Uploaded CPython 3.8 Windows x86

quicktions-1.18-cp38-cp38-musllinux_1_2_x86_64.whl (136.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

quicktions-1.18-cp38-cp38-musllinux_1_2_aarch64.whl (124.9 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ ARM64

quicktions-1.18-cp38-cp38-musllinux_1_1_x86_64.whl (141.2 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

quicktions-1.18-cp38-cp38-musllinux_1_1_aarch64.whl (129.3 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

quicktions-1.18-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (136.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (124.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (152.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp38-cp38-macosx_11_0_arm64.whl (115.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

quicktions-1.18-cp38-cp38-macosx_10_9_x86_64.whl (120.3 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

quicktions-1.18-cp37-cp37m-win_amd64.whl (96.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

quicktions-1.18-cp37-cp37m-win32.whl (89.2 kB view hashes)

Uploaded CPython 3.7m Windows x86

quicktions-1.18-cp37-cp37m-musllinux_1_2_x86_64.whl (131.3 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.2+ x86-64

quicktions-1.18-cp37-cp37m-musllinux_1_2_aarch64.whl (120.9 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.2+ ARM64

quicktions-1.18-cp37-cp37m-musllinux_1_1_x86_64.whl (134.8 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

quicktions-1.18-cp37-cp37m-musllinux_1_1_aarch64.whl (125.0 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

quicktions-1.18-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (130.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (120.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (147.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp37-cp37m-macosx_10_9_x86_64.whl (118.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

quicktions-1.18-cp36-cp36m-win_amd64.whl (106.1 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

quicktions-1.18-cp36-cp36m-win32.whl (95.4 kB view hashes)

Uploaded CPython 3.6m Windows x86

quicktions-1.18-cp36-cp36m-musllinux_1_2_x86_64.whl (127.7 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.2+ x86-64

quicktions-1.18-cp36-cp36m-musllinux_1_2_aarch64.whl (116.7 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.2+ ARM64

quicktions-1.18-cp36-cp36m-musllinux_1_1_x86_64.whl (132.0 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

quicktions-1.18-cp36-cp36m-musllinux_1_1_aarch64.whl (123.0 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ ARM64

quicktions-1.18-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (127.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

quicktions-1.18-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl (116.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.28+ ARM64

quicktions-1.18-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (143.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

quicktions-1.18-cp36-cp36m-macosx_10_9_x86_64.whl (116.1 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

quicktions-1.18-cp35-cp35m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (137.0 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.5+ x86-64

quicktions-1.18-cp35-cp35m-manylinux_2_5_i686.manylinux1_i686.whl (131.2 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.5+ i686

quicktions-1.18-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl (133.8 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.5+ x86-64

quicktions-1.18-cp27-cp27mu-manylinux_2_5_i686.manylinux1_i686.whl (131.0 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.5+ i686

quicktions-1.18-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (133.7 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.5+ x86-64

quicktions-1.18-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl (129.9 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.5+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page