@@ -3862,21 +3862,27 @@ dec_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(dummy))
3862
3862
return result ;
3863
3863
}
3864
3864
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
+
3865
3876
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]*/
3867
3880
{
3868
- static char * kwlist [] = {"rounding" , "context" , NULL };
3869
3881
PyObject * result ;
3870
- PyObject * rounding = Py_None ;
3871
- PyObject * context = Py_None ;
3872
3882
uint32_t status = 0 ;
3873
3883
mpd_context_t workctx ;
3874
3884
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 ));
3880
3886
CONTEXT_CHECK_VA (state , context );
3881
3887
3882
3888
workctx = * CTX (context );
@@ -3895,7 +3901,7 @@ PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
3895
3901
return NULL ;
3896
3902
}
3897
3903
3898
- mpd_qround_to_int (MPD (result ), MPD (dec ), & workctx , & status );
3904
+ mpd_qround_to_int (MPD (result ), MPD (self ), & workctx , & status );
3899
3905
if (dec_addstatus (context , status )) {
3900
3906
Py_DECREF (result );
3901
3907
return NULL ;
@@ -3904,21 +3910,30 @@ PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
3904
3910
return result ;
3905
3911
}
3906
3912
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
+
3907
3927
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]*/
3909
3931
{
3910
- static char * kwlist [] = {"rounding" , "context" , NULL };
3911
3932
PyObject * result ;
3912
- PyObject * rounding = Py_None ;
3913
- PyObject * context = Py_None ;
3914
3933
uint32_t status = 0 ;
3915
3934
mpd_context_t workctx ;
3916
3935
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 ));
3922
3937
CONTEXT_CHECK_VA (state , context );
3923
3938
3924
3939
workctx = * CTX (context );
@@ -3937,7 +3952,7 @@ PyDec_ToIntegralExact(PyObject *dec, PyObject *args, PyObject *kwds)
3937
3952
return NULL ;
3938
3953
}
3939
3954
3940
- mpd_qround_to_intx (MPD (result ), MPD (dec ), & workctx , & status );
3955
+ mpd_qround_to_intx (MPD (result ), MPD (self ), & workctx , & status );
3941
3956
if (dec_addstatus (context , status )) {
3942
3957
Py_DECREF (result );
3943
3958
return NULL ;
@@ -4512,8 +4527,16 @@ Dec_BoolFuncVA(mpd_isnormal)
4512
4527
Dec_BoolFuncVA (mpd_issubnormal )
4513
4528
4514
4529
/* 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
+
4515
4537
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]*/
4517
4540
{
4518
4541
mpd_ssize_t retval ;
4519
4542
@@ -5126,9 +5149,9 @@ static PyMethodDef dec_methods [] =
5126
5149
{ "next_minus" , _PyCFunction_CAST (dec_mpd_qnext_minus ), METH_VARARGS |METH_KEYWORDS , doc_next_minus },
5127
5150
{ "next_plus" , _PyCFunction_CAST (dec_mpd_qnext_plus ), METH_VARARGS |METH_KEYWORDS , doc_next_plus },
5128
5151
{ "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 },
5132
5155
{ "sqrt" , _PyCFunction_CAST (dec_mpd_qsqrt ), METH_VARARGS |METH_KEYWORDS , doc_sqrt },
5133
5156
5134
5157
/* Binary arithmetic functions, optional context arg */
@@ -5160,7 +5183,7 @@ static PyMethodDef dec_methods [] =
5160
5183
{ "is_subnormal" , _PyCFunction_CAST (dec_mpd_issubnormal ), METH_VARARGS |METH_KEYWORDS , doc_is_subnormal },
5161
5184
5162
5185
/* Unary functions, no context arg */
5163
- { "adjusted" , dec_mpd_adjexp , METH_NOARGS , doc_adjusted },
5186
+ _DECIMAL_DECIMAL_ADJUSTED_METHODDEF
5164
5187
{ "canonical" , dec_canonical , METH_NOARGS , doc_canonical },
5165
5188
{ "conjugate" , dec_conjugate , METH_NOARGS , doc_conjugate },
5166
5189
{ "radix" , dec_mpd_radix , METH_NOARGS , doc_radix },
0 commit comments