[issue41324] Add a minimal decimal capsule API

Stefan Krah report at bugs.python.org
Fri Jul 17 07:18:33 EDT 2020


New submission from Stefan Krah <stefan at bytereef.org>:

This adds a minimal decimal capsule API.  As can be seen from the patch,
adding anything to decimal while doing it properly is quite labor and
testing intensive, so the intent is to *keep* the API minimal!

That said, some functions are really necessary:

  1) PyDec_TypeCheck()         -- for obvious reasons.

  2) PyDec_Alloc()             -- create new decimals.

  3) PyDec_Get()               -- get the mpd_t, enables the use of all libmpdec functions.

  4) PyDec_AsUint128Triple()   -- export the decimal as (sign, hi, lo, exp).

  5) PyDec_FromUint128Triple() -- create a decimal from (sign, hi, lo, exp).


4) and 5) have been requested by Antoine for a real world use case.  (hi, lo)
is the coefficient as a __uint128_t split in two uint64_t.


Antoine, could you verify that this is sufficient for the database use case?

----------
nosy: +mark.dickinson, pitrou, rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41324>
_______________________________________


More information about the Python-bugs-list mailing list