Metadata-Version: 2.0
Name: rr.approx
Version: 0.1.1
Summary: A simple module for approximate floating point arithmetic.
Home-page: https://github.com/2xR/rr.approx
Author: Rui Jorge Rei
Author-email: rui.jorge.rei@googlemail.com
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7

=========
rr.approx
=========

Approximate floating point arithmetic library. This simple module can be used to compare numbers using a relative and absolute tolerance, to mitigate floating point rounding errors.

.. code-block:: python

    from rr.approx import Approx

    x = Approx(0.1) * 3
    print x == 0.3  # True

The ``Approx`` class is very simple to use as a replacement for "regular" floats -- you can use ``Approx`` objects instead of floats in most (if not all) contexts: arithmetic and comparisons.

The ``ApproxContext`` class, also accessible as ``Approx.Context``, provides a context manager to temporarily modify the module's tolerance parameters.

.. code-block:: python

    from rr.approx import Approx

    print Approx.Context()  # display current context
    Approx.Context(1e-4, 1e-2).apply()  # permanently modify tolerances
    print Approx.Context()
    with Approx.Context(rtol=1e-5, atol=1e-3):  # temporary modification
        print Approx.Context()
    print Approx.Context()


Installation
------------

.. code-block:: bash

    pip install rr.approx


