Skip to content

Commit ada9e7e

Browse files
committed
+1
1 parent 439380e commit ada9e7e

File tree

3 files changed

+216
-45
lines changed

3 files changed

+216
-45
lines changed

Modules/_decimal/_decimal.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,21 +3862,27 @@ dec_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(dummy))
38623862
return result;
38633863
}
38643864

3865+
/*[clinic input]
3866+
_decimal.Decimal.to_integral
3867+
3868+
rounding: object = None
3869+
context: object = None
3870+
3871+
Identical to the to_integral_value() method.
3872+
3873+
The to_integral() name has been kept for compatibility with older versions.
3874+
[clinic start generated code]*/
3875+
38653876
static PyObject *
3866-
PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
3877+
_decimal_Decimal_to_integral_impl(PyObject *self, PyObject *rounding,
3878+
PyObject *context)
3879+
/*[clinic end generated code: output=a0c7188686ee7f5c input=a57d62d1d29aed1b]*/
38673880
{
3868-
static char *kwlist[] = {"rounding", "context", NULL};
38693881
PyObject *result;
3870-
PyObject *rounding = Py_None;
3871-
PyObject *context = Py_None;
38723882
uint32_t status = 0;
38733883
mpd_context_t workctx;
38743884

3875-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist,
3876-
&rounding, &context)) {
3877-
return NULL;
3878-
}
3879-
decimal_state *state = get_module_state_by_def(Py_TYPE(dec));
3885+
decimal_state *state = get_module_state_by_def(Py_TYPE(self));
38803886
CONTEXT_CHECK_VA(state, context);
38813887

38823888
workctx = *CTX(context);
@@ -3895,7 +3901,7 @@ PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
38953901
return NULL;
38963902
}
38973903

3898-
mpd_qround_to_int(MPD(result), MPD(dec), &workctx, &status);
3904+
mpd_qround_to_int(MPD(result), MPD(self), &workctx, &status);
38993905
if (dec_addstatus(context, status)) {
39003906
Py_DECREF(result);
39013907
return NULL;
@@ -3904,21 +3910,30 @@ PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
39043910
return result;
39053911
}
39063912

3913+
/*[clinic input]
3914+
_decimal.Decimal.to_integral_exact
3915+
3916+
rounding: object = None
3917+
context: object = None
3918+
3919+
Rounds to a nearby integer.
3920+
3921+
Round to the nearest integer, signaling Inexact or Rounded as appropriate if
3922+
rounding occurs. The rounding mode is determined by the rounding parameter
3923+
if given, else by the given context. If neither parameter is given, then the
3924+
rounding mode of the current default context is used.
3925+
[clinic start generated code]*/
3926+
39073927
static PyObject *
3908-
PyDec_ToIntegralExact(PyObject *dec, PyObject *args, PyObject *kwds)
3928+
_decimal_Decimal_to_integral_exact_impl(PyObject *self, PyObject *rounding,
3929+
PyObject *context)
3930+
/*[clinic end generated code: output=8b004f9b45ac7746 input=e98e6aabbc97a92c]*/
39093931
{
3910-
static char *kwlist[] = {"rounding", "context", NULL};
39113932
PyObject *result;
3912-
PyObject *rounding = Py_None;
3913-
PyObject *context = Py_None;
39143933
uint32_t status = 0;
39153934
mpd_context_t workctx;
39163935

3917-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist,
3918-
&rounding, &context)) {
3919-
return NULL;
3920-
}
3921-
decimal_state *state = get_module_state_by_def(Py_TYPE(dec));
3936+
decimal_state *state = get_module_state_by_def(Py_TYPE(self));
39223937
CONTEXT_CHECK_VA(state, context);
39233938

39243939
workctx = *CTX(context);
@@ -3937,7 +3952,7 @@ PyDec_ToIntegralExact(PyObject *dec, PyObject *args, PyObject *kwds)
39373952
return NULL;
39383953
}
39393954

3940-
mpd_qround_to_intx(MPD(result), MPD(dec), &workctx, &status);
3955+
mpd_qround_to_intx(MPD(result), MPD(self), &workctx, &status);
39413956
if (dec_addstatus(context, status)) {
39423957
Py_DECREF(result);
39433958
return NULL;
@@ -4512,8 +4527,16 @@ Dec_BoolFuncVA(mpd_isnormal)
45124527
Dec_BoolFuncVA(mpd_issubnormal)
45134528

45144529
/* Unary functions, no context arg */
4530+
4531+
/*[clinic input]
4532+
_decimal.Decimal.adjusted
4533+
4534+
Return the adjusted exponent of the number. Defined as exp + digits - 1.
4535+
[clinic start generated code]*/
4536+
45154537
static PyObject *
4516-
dec_mpd_adjexp(PyObject *self, PyObject *Py_UNUSED(dummy))
4538+
_decimal_Decimal_adjusted_impl(PyObject *self)
4539+
/*[clinic end generated code: output=21ea2c9f23994c52 input=775a14d44f31f787]*/
45174540
{
45184541
mpd_ssize_t retval;
45194542

@@ -5126,9 +5149,9 @@ static PyMethodDef dec_methods [] =
51265149
{ "next_minus", _PyCFunction_CAST(dec_mpd_qnext_minus), METH_VARARGS|METH_KEYWORDS, doc_next_minus },
51275150
{ "next_plus", _PyCFunction_CAST(dec_mpd_qnext_plus), METH_VARARGS|METH_KEYWORDS, doc_next_plus },
51285151
{ "normalize", _PyCFunction_CAST(dec_mpd_qreduce), METH_VARARGS|METH_KEYWORDS, doc_normalize },
5129-
{ "to_integral", _PyCFunction_CAST(PyDec_ToIntegralValue), METH_VARARGS|METH_KEYWORDS, doc_to_integral },
5130-
{ "to_integral_exact", _PyCFunction_CAST(PyDec_ToIntegralExact), METH_VARARGS|METH_KEYWORDS, doc_to_integral_exact },
5131-
{ "to_integral_value", _PyCFunction_CAST(PyDec_ToIntegralValue), METH_VARARGS|METH_KEYWORDS, doc_to_integral_value },
5152+
_DECIMAL_DECIMAL_TO_INTEGRAL_METHODDEF
5153+
_DECIMAL_DECIMAL_TO_INTEGRAL_EXACT_METHODDEF
5154+
{ "to_integral_value", _PyCFunction_CAST(_decimal_Decimal_to_integral), METH_FASTCALL|METH_KEYWORDS, doc_to_integral_value },
51325155
{ "sqrt", _PyCFunction_CAST(dec_mpd_qsqrt), METH_VARARGS|METH_KEYWORDS, doc_sqrt },
51335156

51345157
/* Binary arithmetic functions, optional context arg */
@@ -5160,7 +5183,7 @@ static PyMethodDef dec_methods [] =
51605183
{ "is_subnormal", _PyCFunction_CAST(dec_mpd_issubnormal), METH_VARARGS|METH_KEYWORDS, doc_is_subnormal },
51615184

51625185
/* Unary functions, no context arg */
5163-
{ "adjusted", dec_mpd_adjexp, METH_NOARGS, doc_adjusted },
5186+
_DECIMAL_DECIMAL_ADJUSTED_METHODDEF
51645187
{ "canonical", dec_canonical, METH_NOARGS, doc_canonical },
51655188
{ "conjugate", dec_conjugate, METH_NOARGS, doc_conjugate },
51665189
{ "radix", dec_mpd_radix, METH_NOARGS, doc_radix },

Modules/_decimal/clinic/_decimal.c.h

Lines changed: 168 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_decimal/docstrings.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ context does not affect the conversion and is only passed to determine if\n\
5757
the InvalidOperation trap is active.\n\
5858
\n");
5959

60-
PyDoc_STRVAR(doc_adjusted,
61-
"adjusted($self, /)\n--\n\n\
62-
Return the adjusted exponent of the number. Defined as exp + digits - 1.\n\
63-
\n");
64-
6560
PyDoc_STRVAR(doc_as_tuple,
6661
"as_tuple($self, /)\n--\n\n\
6762
Return a tuple representation of the number.\n\
@@ -442,20 +437,6 @@ The value of context.capitals determines whether the exponent sign is lower\n\
442437
or upper case. Otherwise, the context does not affect the operation.\n\
443438
\n");
444439

445-
PyDoc_STRVAR(doc_to_integral,
446-
"to_integral($self, /, rounding=None, context=None)\n--\n\n\
447-
Identical to the to_integral_value() method. The to_integral() name has been\n\
448-
kept for compatibility with older versions.\n\
449-
\n");
450-
451-
PyDoc_STRVAR(doc_to_integral_exact,
452-
"to_integral_exact($self, /, rounding=None, context=None)\n--\n\n\
453-
Round to the nearest integer, signaling Inexact or Rounded as appropriate if\n\
454-
rounding occurs. The rounding mode is determined by the rounding parameter\n\
455-
if given, else by the given context. If neither parameter is given, then the\n\
456-
rounding mode of the current default context is used.\n\
457-
\n");
458-
459440
PyDoc_STRVAR(doc_to_integral_value,
460441
"to_integral_value($self, /, rounding=None, context=None)\n--\n\n\
461442
Round to the nearest integer without signaling Inexact or Rounded. The\n\

0 commit comments

Comments
 (0)