Skip to main content

Fast float repr

Project description


Fast float repr() for CPython using Approximately 8X faster than the built-in function.

Quick Start

>>> import frepr
>>> frepr.frepr(-1.8397892359791307e+134)
>>> from timeit import timeit
>>> timeit('repr(-1.8397892359791307e+134)')
>>> frepr.install()
>>> timeit('repr(-1.8397892359791307e+134)')
>>> frepr.uninstall()



Returns shortest string representation of a floating point value. The argument doesn’t have to be a float, as long as it is coercible to one (i.e. it has a __float__() method).


Monkey-patches the Python runtime. Subsequent calls to repr() on floats will use the faster algorithm. This is safe to call multiple times.


Reverses the monkey-patching done by install(). Subsequent calls to repr() will use the original built-in algorithm. This is safe to call multiple times, even if install() was not called first.


  • On average, approximately 8X faster than the standard function. (This result obtained on Python 3.6.0 64-bit/Windows 7/Intel Core i3 @ 2.93GHz. Test your own system with tests/

  • Speeds up the standard json package (and any other library that relies on repr()).

  • Output is guaranteed to contain the shortest string of decimal digits necessary to uniquely identify the original IEEE 754 floating-point value.

  • Guaranteed to satisfy value == ast.literal_eval(frepr(value)).

  • Tested on CPython 2.6 through 3.6; probably works on other versions too.


  • Currently, there is no support for alternative Python implementations (e.g. PyPy).

  • Output can be slightly different from the native function, due to floating-point rounding (but see accuracy guarantees above).

  • Has no effect on other built-in methods of converting floats to strings (e.g. str(), str.format(), "%f", "%g").

See Also

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

frepr-0.1.1.tar.gz (58.2 kB view hashes)

Uploaded source

Built Distributions

frepr-0.1.1-cp36-cp36m-win_amd64.whl (25.1 kB view hashes)

Uploaded cp36

frepr-0.1.1-cp36-cp36m-win32.whl (20.8 kB view hashes)

Uploaded cp36

frepr-0.1.1-cp35-cp35m-win_amd64.whl (25.1 kB view hashes)

Uploaded cp35

frepr-0.1.1-cp35-cp35m-win32.whl (20.8 kB view hashes)

Uploaded cp35

frepr-0.1.1-cp34-cp34m-win_amd64.whl (31.5 kB view hashes)

Uploaded cp34

frepr-0.1.1-cp34-cp34m-win32.whl (26.7 kB view hashes)

Uploaded cp34

frepr-0.1.1-cp27-cp27m-win_amd64.whl (31.1 kB view hashes)

Uploaded cp27

frepr-0.1.1-cp27-cp27m-win32.whl (26.7 kB view hashes)

Uploaded cp27

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page