python decimals

Discussion in 'Python' started by Andrew Svetlov, Sep 15, 2009.

  1. Is there some kind of python binding for decNumber library?
    Standard decimal.Decimal is good enough, but very slow.
    My current project toughly coupled with 'currency' operations and we
    have performance problems related to decimal calculations.
    From my perspective decNumber is fast and has well wide domain to
    represent and process all required set of numbers - we don't need to
    work with 'almost infinite numbers' as python decimal can.
    I tried to google for desired binding - but found nothing.
    gmpy is interesting project, but supported types is not exactly what
    we need - rationals and big floats is not decimals in fixed point
    My team discussed about making own python binding of decNumber - but
    before we start this task I like to ask python community: is there
    existing implementation? I don't want to invent the wheel again.

    Andrew Svetlov, Sep 15, 2009
    1. Advertisements

  2. As far as I know, no such bindings exist. There have been various
    efforts to rewrite the decimal module in C, but (again as far as I
    know) none of those efforts have come to fruition yet.
    Mark Dickinson, Sep 15, 2009
    1. Advertisements

  3. Andrew Svetlov

    Terry Reedy Guest

    Searching "Python decNumber binding" puts your query, from various
    sources, in several of the top 10 sports ;-) Did not seen anythng in the
    next 20 either.
    Terry Reedy, Sep 15, 2009
  4. It only reflects the fact what comp.lang.python replicated by several
    web sites.
    Unfortunately looks like there are no link to library implements that :
    Andrew Svetlov, Sep 16, 2009
  5. A few random thoughts:

    If you just want fixed-precision decimal, there may be simpler
    than using the decimal module. Contrary to popular belief, the
    module (and decNumber) provides floating-point decimal arithmetic, not
    fixed-point (though its treatment of exponents means that it can
    fixed-point arithmetic well).

    Can you use the ctypes module to wrap the decnumber library? That
    might be faster than writing a full-fledged extension module. Cython
    might be useful, too.

    If you do create your own Python bindings for decnumber, is there any
    chance you'd be allowed make them public (e.g., on PyPI)? I think
    there are many people who would find such bindings useful.
    Mark Dickinson, Sep 16, 2009
  6. Decimal has good enough API and we need to follow it as lot of our
    code already operates with Decimal.
    Maybe with different Context and exception types and limited subset of
    operations - but switching should be not very hard.
    Decimal arithmetic is good for as. We need to support several types
    like Currency and standard floating point arithmetic make well known
    failures in fraction point for some cases.
    Really standard decimal module is exact what we need except

    I'm skeptical about ctypes for this specific case but like to use

    Of course library will be open source. Perhaps I will start to work on
    it about end of next week - it's high priority task for my company.
    Andrew Svetlov, Sep 16, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.