@@ -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+
38653876static 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+
39073927static 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)
45124527Dec_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+
45154537static 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 },
0 commit comments