gh-73487: Convert `_decimal` to use Argument Clinic (part 4) (#137931)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Sergey B Kirpichev 2025-08-21 00:59:40 +03:00 committed by GitHub
parent 7dc42b67a7
commit c056a089d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 489 additions and 129 deletions

View file

@ -923,14 +923,34 @@ context_getallcr(PyObject *self, void *Py_UNUSED(closure))
}
#endif
/*[clinic input]
_decimal.Context.Etiny
Return a value equal to Emin - prec + 1.
This is the minimum exponent value for subnormal results. When
underflow occurs, the exponent is set to Etiny.
[clinic start generated code]*/
static PyObject *
context_getetiny(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Context_Etiny_impl(PyObject *self)
/*[clinic end generated code: output=c9a4a1a3e3575289 input=1274040f303f2244]*/
{
return PyLong_FromSsize_t(mpd_etiny(CTX(self)));
}
/*[clinic input]
_decimal.Context.Etop
Return a value equal to Emax - prec + 1.
This is the maximum exponent if the _clamp field of the context is set
to 1 (IEEE clamp mode). Etop() must not be negative.
[clinic start generated code]*/
static PyObject *
context_getetop(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Context_Etop_impl(PyObject *self)
/*[clinic end generated code: output=f0a3f6e1b829074e input=838a4409316ec728]*/
{
return PyLong_FromSsize_t(mpd_etop(CTX(self)));
}
@ -3149,21 +3169,29 @@ PyDec_FromObject(PyObject *v, PyObject *context)
}
}
static PyObject *
dec_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"value", "context", NULL};
PyObject *v = NULL;
PyObject *context = Py_None;
/*[clinic input]
@classmethod
_decimal.Decimal.__new__ as dec_new
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist,
&v, &context)) {
return NULL;
}
value: object(c_default="NULL") = "0"
context: object = None
Construct a new Decimal object.
value can be an integer, string, tuple, or another Decimal object. If
no value is given, return Decimal('0'). The context does not affect
the conversion and is only passed to determine if the InvalidOperation
trap is active.
[clinic start generated code]*/
static PyObject *
dec_new_impl(PyTypeObject *type, PyObject *value, PyObject *context)
/*[clinic end generated code: output=35f48a40c65625ba input=5f8a0892d3fcef80]*/
{
decimal_state *state = get_module_state_by_def(type);
CONTEXT_CHECK_VA(state, context);
return PyDecType_FromObjectExact(type, v, context);
return PyDecType_FromObjectExact(type, value, context);
}
static PyObject *
@ -4105,32 +4133,36 @@ PyDec_AsFloat(PyObject *dec)
return f;
}
/*[clinic input]
_decimal.Decimal.__round__
ndigits: object = NULL
/
Return the Integral closest to self, rounding half toward even.
[clinic start generated code]*/
static PyObject *
PyDec_Round(PyObject *dec, PyObject *args)
_decimal_Decimal___round___impl(PyObject *self, PyObject *ndigits)
/*[clinic end generated code: output=ca6b3570a8df0c91 input=dc72084114f59380]*/
{
PyObject *result;
PyObject *x = NULL;
uint32_t status = 0;
PyObject *context;
decimal_state *state = get_module_state_by_def(Py_TYPE(dec));
decimal_state *state = get_module_state_by_def(Py_TYPE(self));
CURRENT_CONTEXT(state, context);
if (!PyArg_ParseTuple(args, "|O", &x)) {
return NULL;
}
if (x) {
if (ndigits) {
mpd_uint_t dq[1] = {1};
mpd_t q = {MPD_STATIC|MPD_CONST_DATA,0,1,1,1,dq};
mpd_ssize_t y;
if (!PyLong_Check(x)) {
if (!PyLong_Check(ndigits)) {
PyErr_SetString(PyExc_TypeError,
"optional arg must be an integer");
return NULL;
}
y = PyLong_AsSsize_t(x);
y = PyLong_AsSsize_t(ndigits);
if (y == -1 && PyErr_Occurred()) {
return NULL;
}
@ -4140,7 +4172,7 @@ PyDec_Round(PyObject *dec, PyObject *args)
}
q.exp = (y == MPD_SSIZE_MIN) ? MPD_SSIZE_MAX : -y;
mpd_qquantize(MPD(result), MPD(dec), &q, CTX(context), &status);
mpd_qquantize(MPD(result), MPD(self), &q, CTX(context), &status);
if (dec_addstatus(context, status)) {
Py_DECREF(result);
return NULL;
@ -4149,7 +4181,7 @@ PyDec_Round(PyObject *dec, PyObject *args)
return result;
}
else {
return dec_as_long(dec, context, MPD_ROUND_HALF_EVEN);
return dec_as_long(self, context, MPD_ROUND_HALF_EVEN);
}
}
@ -5418,9 +5450,15 @@ dec_richcompare(PyObject *v, PyObject *w, int op)
return PyBool_FromLong(r);
}
/* __ceil__ */
/*[clinic input]
_decimal.Decimal.__ceil__
Return the ceiling as an Integral.
[clinic start generated code]*/
static PyObject *
dec_ceil(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___ceil___impl(PyObject *self)
/*[clinic end generated code: output=e755a6fb7bceac19 input=4a18ef307ac57da0]*/
{
PyObject *context;
@ -5429,9 +5467,15 @@ dec_ceil(PyObject *self, PyObject *Py_UNUSED(dummy))
return dec_as_long(self, context, MPD_ROUND_CEILING);
}
/* __complex__ */
/*[clinic input]
_decimal.Decimal.__complex__
Convert this value to exact type complex.
[clinic start generated code]*/
static PyObject *
dec_complex(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___complex___impl(PyObject *self)
/*[clinic end generated code: output=c9b5b4a9fdebc912 input=6b11c6f20af7061a]*/
{
PyObject *f;
double x;
@ -5450,16 +5494,42 @@ dec_complex(PyObject *self, PyObject *Py_UNUSED(dummy))
return PyComplex_FromDoubles(x, 0);
}
/* __copy__ (METH_NOARGS) and __deepcopy__ (METH_O) */
/*[clinic input]
_decimal.Decimal.__copy__
[clinic start generated code]*/
static PyObject *
dec_copy(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___copy___impl(PyObject *self)
/*[clinic end generated code: output=8eb3656c0250762b input=3dfd30a3e1493c01]*/
{
return Py_NewRef(self);
}
/* __floor__ */
/*[clinic input]
_decimal.Decimal.__deepcopy__
memo: object
/
[clinic start generated code]*/
static PyObject *
dec_floor(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___deepcopy__(PyObject *self, PyObject *memo)
/*[clinic end generated code: output=988fb34e0136b376 input=f95598c6f43233aa]*/
{
return Py_NewRef(self);
}
/*[clinic input]
_decimal.Decimal.__floor__
Return the floor as an Integral.
[clinic start generated code]*/
static PyObject *
_decimal_Decimal___floor___impl(PyObject *self)
/*[clinic end generated code: output=56767050ac1a1d5a input=cabcc5618564548b]*/
{
PyObject *context;
@ -5595,9 +5665,15 @@ dec_hash(PyObject *op)
return self->hash;
}
/* __reduce__ */
/*[clinic input]
_decimal.Decimal.__reduce__
Return state information for pickling.
[clinic start generated code]*/
static PyObject *
dec_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___reduce___impl(PyObject *self)
/*[clinic end generated code: output=84fa6648a496a8d2 input=0345ea951d9b986f]*/
{
PyObject *result, *str;
@ -5612,9 +5688,17 @@ dec_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
return result;
}
/* __sizeof__ */
/*[clinic input]
_decimal.Decimal.__sizeof__
self as v: self
Returns size in memory, in bytes
[clinic start generated code]*/
static PyObject *
dec_sizeof(PyObject *v, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___sizeof___impl(PyObject *v)
/*[clinic end generated code: output=f16de05097c62b79 input=a557db538cfddbb7]*/
{
size_t res = _PyObject_SIZE(Py_TYPE(v));
if (mpd_isdynamic_data(MPD(v))) {
@ -5623,9 +5707,15 @@ dec_sizeof(PyObject *v, PyObject *Py_UNUSED(dummy))
return PyLong_FromSize_t(res);
}
/* __trunc__ */
/*[clinic input]
_decimal.Decimal.__trunc__
Return the Integral closest to x between 0 and x.
[clinic start generated code]*/
static PyObject *
dec_trunc(PyObject *self, PyObject *Py_UNUSED(dummy))
_decimal_Decimal___trunc___impl(PyObject *self)
/*[clinic end generated code: output=9ef59578960f80c0 input=a965a61096dcefeb]*/
{
PyObject *context;
@ -5743,16 +5833,16 @@ static PyMethodDef dec_methods [] =
_DECIMAL_DECIMAL_AS_INTEGER_RATIO_METHODDEF
/* Special methods */
{ "__copy__", dec_copy, METH_NOARGS, NULL },
{ "__deepcopy__", dec_copy, METH_O, NULL },
_DECIMAL_DECIMAL___COPY___METHODDEF
_DECIMAL_DECIMAL___DEEPCOPY___METHODDEF
_DECIMAL_DECIMAL___FORMAT___METHODDEF
{ "__reduce__", dec_reduce, METH_NOARGS, NULL },
{ "__round__", PyDec_Round, METH_VARARGS, NULL },
{ "__ceil__", dec_ceil, METH_NOARGS, NULL },
{ "__floor__", dec_floor, METH_NOARGS, NULL },
{ "__trunc__", dec_trunc, METH_NOARGS, NULL },
{ "__complex__", dec_complex, METH_NOARGS, NULL },
{ "__sizeof__", dec_sizeof, METH_NOARGS, NULL },
_DECIMAL_DECIMAL___REDUCE___METHODDEF
_DECIMAL_DECIMAL___ROUND___METHODDEF
_DECIMAL_DECIMAL___CEIL___METHODDEF
_DECIMAL_DECIMAL___FLOOR___METHODDEF
_DECIMAL_DECIMAL___TRUNC___METHODDEF
_DECIMAL_DECIMAL___COMPLEX___METHODDEF
_DECIMAL_DECIMAL___SIZEOF___METHODDEF
{ NULL, NULL, 1 }
};
@ -5765,7 +5855,7 @@ static PyType_Slot dec_slots[] = {
{Py_tp_repr, dec_repr},
{Py_tp_hash, dec_hash},
{Py_tp_str, dec_str},
{Py_tp_doc, (void *)doc_decimal},
{Py_tp_doc, (void *)dec_new__doc__},
{Py_tp_richcompare, dec_richcompare},
{Py_tp_methods, dec_methods},
{Py_tp_getset, dec_getsets},
@ -6119,8 +6209,18 @@ _decimal_Context_power_impl(PyObject *context, PyObject *base, PyObject *exp,
DecCtx_TernaryFunc(mpd_qfma)
/* No argument */
/*[clinic input]
_decimal.Context.radix
self as context: self
Return 10.
[clinic start generated code]*/
static PyObject *
ctx_mpd_radix(PyObject *context, PyObject *dummy)
_decimal_Context_radix_impl(PyObject *context)
/*[clinic end generated code: output=9218fa309e0fcaa1 input=faeaa5b71f838c38]*/
{
decimal_state *state = get_module_state_from_ctx(context);
return _dec_mpd_radix(state);
@ -6403,9 +6503,9 @@ static PyMethodDef context_methods [] =
{ "fma", ctx_mpd_qfma, METH_VARARGS, doc_ctx_fma },
/* No argument */
{ "Etiny", context_getetiny, METH_NOARGS, doc_ctx_Etiny },
{ "Etop", context_getetop, METH_NOARGS, doc_ctx_Etop },
{ "radix", ctx_mpd_radix, METH_NOARGS, doc_ctx_radix },
_DECIMAL_CONTEXT_ETINY_METHODDEF
_DECIMAL_CONTEXT_ETOP_METHODDEF
_DECIMAL_CONTEXT_RADIX_METHODDEF
/* Boolean functions */
{ "is_canonical", ctx_iscanonical, METH_O, doc_ctx_is_canonical },
@ -6932,7 +7032,7 @@ static struct PyModuleDef_Slot _decimal_slots[] = {
static struct PyModuleDef _decimal_module = {
PyModuleDef_HEAD_INIT,
.m_name = "decimal",
.m_doc = doc__decimal,
.m_doc = "C decimal arithmetic module",
.m_size = sizeof(decimal_state),
.m_methods = _decimal_methods,
.m_slots = _decimal_slots,

View file

@ -9,6 +9,48 @@ preserve
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(_decimal_Context_Etiny__doc__,
"Etiny($self, /)\n"
"--\n"
"\n"
"Return a value equal to Emin - prec + 1.\n"
"\n"
"This is the minimum exponent value for subnormal results. When\n"
"underflow occurs, the exponent is set to Etiny.");
#define _DECIMAL_CONTEXT_ETINY_METHODDEF \
{"Etiny", (PyCFunction)_decimal_Context_Etiny, METH_NOARGS, _decimal_Context_Etiny__doc__},
static PyObject *
_decimal_Context_Etiny_impl(PyObject *self);
static PyObject *
_decimal_Context_Etiny(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Context_Etiny_impl(self);
}
PyDoc_STRVAR(_decimal_Context_Etop__doc__,
"Etop($self, /)\n"
"--\n"
"\n"
"Return a value equal to Emax - prec + 1.\n"
"\n"
"This is the maximum exponent if the _clamp field of the context is set\n"
"to 1 (IEEE clamp mode). Etop() must not be negative.");
#define _DECIMAL_CONTEXT_ETOP_METHODDEF \
{"Etop", (PyCFunction)_decimal_Context_Etop, METH_NOARGS, _decimal_Context_Etop__doc__},
static PyObject *
_decimal_Context_Etop_impl(PyObject *self);
static PyObject *
_decimal_Context_Etop(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Context_Etop_impl(self);
}
PyDoc_STRVAR(_decimal_IEEEContext__doc__,
"IEEEContext($module, bits, /)\n"
"--\n"
@ -269,6 +311,80 @@ _decimal_Decimal_from_number(PyObject *type, PyObject *number)
return return_value;
}
PyDoc_STRVAR(dec_new__doc__,
"Decimal(value=\'0\', context=None)\n"
"--\n"
"\n"
"Construct a new Decimal object.\n"
"\n"
"value can be an integer, string, tuple, or another Decimal object. If\n"
"no value is given, return Decimal(\'0\'). The context does not affect\n"
"the conversion and is only passed to determine if the InvalidOperation\n"
"trap is active.");
static PyObject *
dec_new_impl(PyTypeObject *type, PyObject *value, PyObject *context);
static PyObject *
dec_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
#define NUM_KEYWORDS 2
static struct {
PyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
Py_hash_t ob_hash;
PyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
.ob_hash = -1,
.ob_item = { &_Py_ID(value), &_Py_ID(context), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
#else // !Py_BUILD_CORE
# define KWTUPLE NULL
#endif // !Py_BUILD_CORE
static const char * const _keywords[] = {"value", "context", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "Decimal",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
PyObject *argsbuf[2];
PyObject * const *fastargs;
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
PyObject *value = NULL;
PyObject *context = Py_None;
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
/*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
if (!fastargs) {
goto exit;
}
if (!noptargs) {
goto skip_optional_pos;
}
if (fastargs[0]) {
value = fastargs[0];
if (!--noptargs) {
goto skip_optional_pos;
}
}
context = fastargs[1];
skip_optional_pos:
return_value = dec_new_impl(type, value, context);
exit:
return return_value;
}
PyDoc_STRVAR(_decimal_Decimal___format____doc__,
"__format__($self, format_spec, override=<unrepresentable>, /)\n"
"--\n"
@ -554,6 +670,38 @@ exit:
return return_value;
}
PyDoc_STRVAR(_decimal_Decimal___round____doc__,
"__round__($self, ndigits=<unrepresentable>, /)\n"
"--\n"
"\n"
"Return the Integral closest to self, rounding half toward even.");
#define _DECIMAL_DECIMAL___ROUND___METHODDEF \
{"__round__", _PyCFunction_CAST(_decimal_Decimal___round__), METH_FASTCALL, _decimal_Decimal___round____doc__},
static PyObject *
_decimal_Decimal___round___impl(PyObject *self, PyObject *ndigits);
static PyObject *
_decimal_Decimal___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
PyObject *ndigits = NULL;
if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
ndigits = args[0];
skip_optional:
return_value = _decimal_Decimal___round___impl(self, ndigits);
exit:
return return_value;
}
PyDoc_STRVAR(_decimal_Decimal_as_tuple__doc__,
"as_tuple($self, /)\n"
"--\n"
@ -2841,6 +2989,139 @@ exit:
return return_value;
}
PyDoc_STRVAR(_decimal_Decimal___ceil____doc__,
"__ceil__($self, /)\n"
"--\n"
"\n"
"Return the ceiling as an Integral.");
#define _DECIMAL_DECIMAL___CEIL___METHODDEF \
{"__ceil__", (PyCFunction)_decimal_Decimal___ceil__, METH_NOARGS, _decimal_Decimal___ceil____doc__},
static PyObject *
_decimal_Decimal___ceil___impl(PyObject *self);
static PyObject *
_decimal_Decimal___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___ceil___impl(self);
}
PyDoc_STRVAR(_decimal_Decimal___complex____doc__,
"__complex__($self, /)\n"
"--\n"
"\n"
"Convert this value to exact type complex.");
#define _DECIMAL_DECIMAL___COMPLEX___METHODDEF \
{"__complex__", (PyCFunction)_decimal_Decimal___complex__, METH_NOARGS, _decimal_Decimal___complex____doc__},
static PyObject *
_decimal_Decimal___complex___impl(PyObject *self);
static PyObject *
_decimal_Decimal___complex__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___complex___impl(self);
}
PyDoc_STRVAR(_decimal_Decimal___copy____doc__,
"__copy__($self, /)\n"
"--\n"
"\n");
#define _DECIMAL_DECIMAL___COPY___METHODDEF \
{"__copy__", (PyCFunction)_decimal_Decimal___copy__, METH_NOARGS, _decimal_Decimal___copy____doc__},
static PyObject *
_decimal_Decimal___copy___impl(PyObject *self);
static PyObject *
_decimal_Decimal___copy__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___copy___impl(self);
}
PyDoc_STRVAR(_decimal_Decimal___deepcopy____doc__,
"__deepcopy__($self, memo, /)\n"
"--\n"
"\n");
#define _DECIMAL_DECIMAL___DEEPCOPY___METHODDEF \
{"__deepcopy__", (PyCFunction)_decimal_Decimal___deepcopy__, METH_O, _decimal_Decimal___deepcopy____doc__},
PyDoc_STRVAR(_decimal_Decimal___floor____doc__,
"__floor__($self, /)\n"
"--\n"
"\n"
"Return the floor as an Integral.");
#define _DECIMAL_DECIMAL___FLOOR___METHODDEF \
{"__floor__", (PyCFunction)_decimal_Decimal___floor__, METH_NOARGS, _decimal_Decimal___floor____doc__},
static PyObject *
_decimal_Decimal___floor___impl(PyObject *self);
static PyObject *
_decimal_Decimal___floor__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___floor___impl(self);
}
PyDoc_STRVAR(_decimal_Decimal___reduce____doc__,
"__reduce__($self, /)\n"
"--\n"
"\n"
"Return state information for pickling.");
#define _DECIMAL_DECIMAL___REDUCE___METHODDEF \
{"__reduce__", (PyCFunction)_decimal_Decimal___reduce__, METH_NOARGS, _decimal_Decimal___reduce____doc__},
static PyObject *
_decimal_Decimal___reduce___impl(PyObject *self);
static PyObject *
_decimal_Decimal___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___reduce___impl(self);
}
PyDoc_STRVAR(_decimal_Decimal___sizeof____doc__,
"__sizeof__($self, /)\n"
"--\n"
"\n"
"Returns size in memory, in bytes");
#define _DECIMAL_DECIMAL___SIZEOF___METHODDEF \
{"__sizeof__", (PyCFunction)_decimal_Decimal___sizeof__, METH_NOARGS, _decimal_Decimal___sizeof____doc__},
static PyObject *
_decimal_Decimal___sizeof___impl(PyObject *v);
static PyObject *
_decimal_Decimal___sizeof__(PyObject *v, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___sizeof___impl(v);
}
PyDoc_STRVAR(_decimal_Decimal___trunc____doc__,
"__trunc__($self, /)\n"
"--\n"
"\n"
"Return the Integral closest to x between 0 and x.");
#define _DECIMAL_DECIMAL___TRUNC___METHODDEF \
{"__trunc__", (PyCFunction)_decimal_Decimal___trunc__, METH_NOARGS, _decimal_Decimal___trunc____doc__},
static PyObject *
_decimal_Decimal___trunc___impl(PyObject *self);
static PyObject *
_decimal_Decimal___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _decimal_Decimal___trunc___impl(self);
}
PyDoc_STRVAR(_decimal_Context_power__doc__,
"power($self, /, a, b, modulo=None)\n"
"--\n"
@ -2922,4 +3203,22 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=9bbde3e723166dd3 input=a9049054013a1b77]*/
PyDoc_STRVAR(_decimal_Context_radix__doc__,
"radix($self, /)\n"
"--\n"
"\n"
"Return 10.");
#define _DECIMAL_CONTEXT_RADIX_METHODDEF \
{"radix", (PyCFunction)_decimal_Context_radix, METH_NOARGS, _decimal_Context_radix__doc__},
static PyObject *
_decimal_Context_radix_impl(PyObject *context);
static PyObject *
_decimal_Context_radix(PyObject *context, PyObject *Py_UNUSED(ignored))
{
return _decimal_Context_radix_impl(context);
}
/*[clinic end generated code: output=ffc58f98fffed531 input=a9049054013a1b77]*/

View file

@ -10,61 +10,6 @@
#include "pymacro.h"
/******************************************************************************/
/* Module */
/******************************************************************************/
PyDoc_STRVAR(doc__decimal,
"C decimal arithmetic module");
/******************************************************************************/
/* Decimal Object and Methods */
/******************************************************************************/
PyDoc_STRVAR(doc_decimal,
"Decimal(value=\"0\", context=None)\n--\n\n\
Construct a new Decimal object. 'value' can be an integer, string, tuple,\n\
or another Decimal object. If no value is given, return Decimal('0'). The\n\
context does not affect the conversion and is only passed to determine if\n\
the InvalidOperation trap is active.\n\
\n");
PyDoc_STRVAR(doc_compare_total,
"compare_total($self, /, other, context=None)\n--\n\n\
Compare two operands using their abstract representation rather than\n\
their numerical value. Similar to the compare() method, but the result\n\
gives a total ordering on Decimal instances. Two Decimal instances with\n\
the same numeric value but different representations compare unequal\n\
in this ordering:\n\
\n\
>>> Decimal('12.0').compare_total(Decimal('12'))\n\
Decimal('-1')\n\
\n\
Quiet and signaling NaNs are also included in the total ordering. The result\n\
of this function is Decimal('0') if both operands have the same representation,\n\
Decimal('-1') if the first operand is lower in the total order than the second,\n\
and Decimal('1') if the first operand is higher in the total order than the\n\
second operand. See the specification for details of the total order.\n\
\n\
This operation is unaffected by context and is quiet: no flags are changed\n\
and no rounding is performed. As an exception, the C version may raise\n\
InvalidOperation if the second operand cannot be converted exactly.\n\
\n");
PyDoc_STRVAR(doc_compare_total_mag,
"compare_total_mag($self, /, other, context=None)\n--\n\n\
Compare two operands using their abstract representation rather than their\n\
value as in compare_total(), but ignoring the sign of each operand.\n\
\n\
x.compare_total_mag(y) is equivalent to x.copy_abs().compare_total(y.copy_abs()).\n\
\n\
This operation is unaffected by context and is quiet: no flags are changed\n\
and no rounding is performed. As an exception, the C version may raise\n\
InvalidOperation if the second operand cannot be converted exactly.\n\
\n");
PyDoc_STRVAR(doc_is_canonical,
"is_canonical($self, /)\n--\n\n\
Return True if the argument is canonical and False otherwise. Currently,\n\
@ -169,19 +114,6 @@ Create a new Decimal instance from float f. Unlike the Decimal.from_float()\n\
class method, this function observes the context limits.\n\
\n");
PyDoc_STRVAR(doc_ctx_Etiny,
"Etiny($self, /)\n--\n\n\
Return a value equal to Emin - prec + 1, which is the minimum exponent value\n\
for subnormal results. When underflow occurs, the exponent is set to Etiny.\n\
\n");
PyDoc_STRVAR(doc_ctx_Etop,
"Etop($self, /)\n--\n\n\
Return a value equal to Emax - prec + 1. This is the maximum exponent\n\
if the _clamp field of the context is set to 1 (IEEE clamp mode). Etop()\n\
must not be negative.\n\
\n");
PyDoc_STRVAR(doc_ctx_abs,
"abs($self, x, /)\n--\n\n\
Return the absolute value of x.\n\
@ -257,6 +189,40 @@ PyDoc_STRVAR(doc_ctx_fma,
Return x multiplied by y, plus z.\n\
\n");
PyDoc_STRVAR(doc_compare_total,
"compare_total($self, /, other, context=None)\n--\n\n\
Compare two operands using their abstract representation rather than\n\
their numerical value. Similar to the compare() method, but the result\n\
gives a total ordering on Decimal instances. Two Decimal instances with\n\
the same numeric value but different representations compare unequal\n\
in this ordering:\n\
\n\
>>> Decimal('12.0').compare_total(Decimal('12'))\n\
Decimal('-1')\n\
\n\
Quiet and signaling NaNs are also included in the total ordering. The result\n\
of this function is Decimal('0') if both operands have the same representation,\n\
Decimal('-1') if the first operand is lower in the total order than the second,\n\
and Decimal('1') if the first operand is higher in the total order than the\n\
second operand. See the specification for details of the total order.\n\
\n\
This operation is unaffected by context and is quiet: no flags are changed\n\
and no rounding is performed. As an exception, the C version may raise\n\
InvalidOperation if the second operand cannot be converted exactly.\n\
\n");
PyDoc_STRVAR(doc_compare_total_mag,
"compare_total_mag($self, /, other, context=None)\n--\n\n\
Compare two operands using their abstract representation rather than their\n\
value as in compare_total(), but ignoring the sign of each operand.\n\
\n\
x.compare_total_mag(y) is equivalent to x.copy_abs().compare_total(y.copy_abs()).\n\
\n\
This operation is unaffected by context and is quiet: no flags are changed\n\
and no rounding is performed. As an exception, the C version may raise\n\
InvalidOperation if the second operand cannot be converted exactly.\n\
\n");
PyDoc_STRVAR(doc_ctx_is_canonical,
"is_canonical($self, x, /)\n--\n\n\
Return True if x is canonical, False otherwise.\n\
@ -409,11 +375,6 @@ PyDoc_STRVAR(doc_ctx_quantize,
Return a value equal to x (rounded), having the exponent of y.\n\
\n");
PyDoc_STRVAR(doc_ctx_radix,
"radix($self, /)\n--\n\n\
Return 10.\n\
\n");
PyDoc_STRVAR(doc_ctx_remainder,
"remainder($self, x, y, /)\n--\n\n\
Return the remainder from integer division. The sign of the result,\n\