python decimals

A

Andrew Svetlov

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

Thanks.
 
M

Mark Dickinson

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

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

Terry Reedy

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

Andrew Svetlov

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 :
(
 
M

Mark Dickinson

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 :
(

A few random thoughts:

If you just want fixed-precision decimal, there may be simpler
solutions
than using the decimal module. Contrary to popular belief, the
decimal
module (and decNumber) provides floating-point decimal arithmetic, not
fixed-point (though its treatment of exponents means that it can
emulate
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.
 
A

Andrew Svetlov

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

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

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top