Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Fast fractions data type for rational numbers. Cythonized version of 'fractions.Fraction'.
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 <https://cython.org/>
_ into a fast, native extension module.
Compared to the standard library fractions
module of CPython,
computations in quicktions
are about
Compared to the fractions
module in CPython 3.10, instantiation of a
Fraction
in quicktions
is also
Fraction("123.456789")
)Fraction(123.456789)
)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:
.. code-block::
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
Support for Python 2.7 as well as 3.7 and earlier has been removed.
Generally use .as_integer_ratio()
in the constructor if available.
https://github.com/python/cpython/pull/120271
Add a classmethod .from_number()
that requires a number argument, not a string.
https://github.com/python/cpython/pull/121800
Mixed calculations with other Rational
classes could return the wrong type.
https://github.com/python/cpython/issues/119189
In mixed calculations with complex
, the Fraction is now converted to float
instead of complex
to avoid certain corner cases in complex calculation.
https://github.com/python/cpython/pull/119839
Using complex
numbers in division shows better tracebacks.
https://github.com/python/cpython/pull/102842
Subclass instantiations and calculations could fail in some cases.
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.
Formatting support was improved, following CPython 3.13a3 as of https://github.com/python/cpython/pull/111320
Add support for Python 3.13 by using Cython 3.0.8 and calling math.gcd()
.
Implement __format__
for Fraction
, following
https://github.com/python/cpython/pull/100161
Implement Fraction.is_integer()
, following
https://github.com/python/cpython/issues/100488
Fraction.limit_denominator()
is faster, following
https://github.com/python/cpython/pull/93730
Internal creation of result Fractions is about 10% faster if the calculated numerator/denominator pair is already normalised, following https://github.com/python/cpython/pull/101780
Built using Cython 3.0.0b1.
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
Faster and more space friendly pickling and unpickling. https://bugs.python.org/issue44154
Algorithmically faster arithmetic for large denominators, although slower for small fraction components. https://bugs.python.org/issue43420 Original patch for CPython by Sergey B. Kirpichev and Raymond Hettinger.
Make sure bool(Fraction)
always returns a bool
.
https://bugs.python.org/issue39274
Built using Cython 3.0.0a10.
OverflowError
when parsing string values with long decimal parts.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()
.
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 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.
repair the faster instantiation from Decimal values in Python 3.6
avoid potential glitch for certain large numbers in normalisation under Python 2.x
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
FAQs
Fast fractions data type for rational numbers. Cythonized version of 'fractions.Fraction'.
We found that quicktions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.