Skip to content

Commit a0947fd

Browse files
committed
+1
1 parent fe48aa0 commit a0947fd

File tree

3 files changed

+537
-146
lines changed

3 files changed

+537
-146
lines changed

Modules/_decimal/_decimal.c

Lines changed: 182 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,23 +4288,16 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \
42884288
/* Boolean function without a context arg. */
42894289
#define Dec_BoolFunc(MPDFUNC) \
42904290
static PyObject * \
4291-
dec_##MPDFUNC(PyObject *self, PyObject *Py_UNUSED(dummy)) \
4291+
dec_##MPDFUNC(PyObject *self) \
42924292
{ \
42934293
return MPDFUNC(MPD(self)) ? incr_true() : incr_false(); \
42944294
}
42954295

42964296
/* Boolean function with an optional context arg. */
42974297
#define Dec_BoolFuncVA(MPDFUNC) \
42984298
static PyObject * \
4299-
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
4299+
dec_##MPDFUNC(PyObject *self, PyObject *context) \
43004300
{ \
4301-
static char *kwlist[] = {"context", NULL}; \
4302-
PyObject *context = Py_None; \
4303-
\
4304-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \
4305-
&context)) { \
4306-
return NULL; \
4307-
} \
43084301
decimal_state *state = get_module_state_by_def(Py_TYPE(self)); \
43094302
CONTEXT_CHECK_VA(state, context); \
43104303
\
@@ -4395,19 +4388,11 @@ dec_##MPDFUNC(PyObject *self, PyObject *other, PyObject *context)\
43954388
/* Ternary function with an optional context arg. */
43964389
#define Dec_TernaryFuncVA(MPDFUNC) \
43974390
static PyObject * \
4398-
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
4391+
dec_##MPDFUNC(PyObject *self, PyObject *other, PyObject *third, PyObject *context) \
43994392
{ \
4400-
static char *kwlist[] = {"other", "third", "context", NULL}; \
4401-
PyObject *other, *third; \
44024393
PyObject *a, *b, *c; \
44034394
PyObject *result; \
4404-
PyObject *context = Py_None; \
44054395
uint32_t status = 0; \
4406-
\
4407-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, \
4408-
&other, &third, &context)) { \
4409-
return NULL; \
4410-
} \
44114396
decimal_state *state = get_module_state_by_def(Py_TYPE(self)); \
44124397
CONTEXT_CHECK_VA(state, context); \
44134398
CONVERT_TERNOP_RAISE(&a, &b, &c, self, other, third, context); \
@@ -4859,6 +4844,30 @@ _decimal_Decimal_remainder_near_impl(PyObject *self, PyObject *other,
48594844
/* Ternary arithmetic functions, optional context arg */
48604845
Dec_TernaryFuncVA(mpd_qfma)
48614846

4847+
/*[clinic input]
4848+
_decimal.Decimal.fma
4849+
4850+
other: object
4851+
third: object
4852+
context: object = None
4853+
4854+
Fused multiply-add.
4855+
4856+
Return self*other+third with no rounding of the intermediate product
4857+
self*other.
4858+
4859+
>>> Decimal(2).fma(3, 5)
4860+
Decimal('11')
4861+
[clinic start generated code]*/
4862+
4863+
static PyObject *
4864+
_decimal_Decimal_fma_impl(PyObject *self, PyObject *other, PyObject *third,
4865+
PyObject *context)
4866+
/*[clinic end generated code: output=74a82b984e227b69 input=48f9aec6f389227a]*/
4867+
{
4868+
return dec_mpd_qfma(self, other, third, context);
4869+
}
4870+
48624871
/* Boolean functions, no context arg */
48634872
Dec_BoolFunc(mpd_iscanonical)
48644873
Dec_BoolFunc(mpd_isfinite)
@@ -4869,10 +4878,154 @@ Dec_BoolFunc(mpd_issnan)
48694878
Dec_BoolFunc(mpd_issigned)
48704879
Dec_BoolFunc(mpd_iszero)
48714880

4881+
/*[clinic input]
4882+
_decimal.Decimal.is_canonical
4883+
4884+
Return True if the argument is canonical and False otherwise.
4885+
4886+
Currently, a Decimal instance is always canonical, so this operation
4887+
always returns True.
4888+
[clinic start generated code]*/
4889+
4890+
static PyObject *
4891+
_decimal_Decimal_is_canonical_impl(PyObject *self)
4892+
/*[clinic end generated code: output=b29668684f45443e input=b3b3e6878ccf40b8]*/
4893+
{
4894+
return dec_mpd_iscanonical(self);
4895+
}
4896+
4897+
/*[clinic input]
4898+
_decimal.Decimal.is_finite
4899+
4900+
Return True if the argument is a finite number, and False otherwise.
4901+
[clinic start generated code]*/
4902+
4903+
static PyObject *
4904+
_decimal_Decimal_is_finite_impl(PyObject *self)
4905+
/*[clinic end generated code: output=537306fbfc9131f8 input=e9b8b5866704bae6]*/
4906+
{
4907+
return dec_mpd_isfinite(self);
4908+
}
4909+
4910+
/*[clinic input]
4911+
_decimal.Decimal.is_infinite
4912+
4913+
Return True if the argument is infinite, and False otherwise.
4914+
[clinic start generated code]*/
4915+
4916+
static PyObject *
4917+
_decimal_Decimal_is_infinite_impl(PyObject *self)
4918+
/*[clinic end generated code: output=31b775ff28f05ce2 input=8f3937a790ee4ec2]*/
4919+
{
4920+
return dec_mpd_isinfinite(self);
4921+
}
4922+
4923+
/*[clinic input]
4924+
_decimal.Decimal.is_nan
4925+
4926+
Return True if the argument is a (quiet or signaling) NaN and False otherwise.
4927+
[clinic start generated code]*/
4928+
4929+
static PyObject *
4930+
_decimal_Decimal_is_nan_impl(PyObject *self)
4931+
/*[clinic end generated code: output=b704e8b49a164388 input=fadb52a8da692c5b]*/
4932+
{
4933+
return dec_mpd_isnan(self);
4934+
}
4935+
4936+
/*[clinic input]
4937+
_decimal.Decimal.is_qnan
4938+
4939+
Return True if the argument is a quiet NaN, and False otherwise.
4940+
[clinic start generated code]*/
4941+
4942+
static PyObject *
4943+
_decimal_Decimal_is_qnan_impl(PyObject *self)
4944+
/*[clinic end generated code: output=85b5241f43798376 input=00485f3c3cfae0af]*/
4945+
{
4946+
return dec_mpd_isqnan(self);
4947+
}
4948+
4949+
/*[clinic input]
4950+
_decimal.Decimal.is_snan
4951+
4952+
Return True if the argument is a signaling NaN and False otherwise.
4953+
[clinic start generated code]*/
4954+
4955+
static PyObject *
4956+
_decimal_Decimal_is_snan_impl(PyObject *self)
4957+
/*[clinic end generated code: output=50de9ec6507e4a4f input=f3b0f8592c921879]*/
4958+
{
4959+
return dec_mpd_issnan(self);
4960+
}
4961+
4962+
/*[clinic input]
4963+
_decimal.Decimal.is_signed
4964+
4965+
Return True if the argument has a negative sign and False otherwise.
4966+
4967+
Note that both zeros and NaNs can carry signs.
4968+
[clinic start generated code]*/
4969+
4970+
static PyObject *
4971+
_decimal_Decimal_is_signed_impl(PyObject *self)
4972+
/*[clinic end generated code: output=8ec7bc85d8e755e4 input=97c3437ab5dffecc]*/
4973+
{
4974+
return dec_mpd_issigned(self);
4975+
}
4976+
4977+
/*[clinic input]
4978+
_decimal.Decimal.is_zero
4979+
4980+
Return True if the argument is a (positive or negative) zero and False otherwise.
4981+
[clinic start generated code]*/
4982+
4983+
static PyObject *
4984+
_decimal_Decimal_is_zero_impl(PyObject *self)
4985+
/*[clinic end generated code: output=2d87ea1b15879112 input=35de901ce2554a4d]*/
4986+
{
4987+
return dec_mpd_iszero(self);
4988+
}
4989+
48724990
/* Boolean functions, optional context arg */
48734991
Dec_BoolFuncVA(mpd_isnormal)
48744992
Dec_BoolFuncVA(mpd_issubnormal)
48754993

4994+
/*[clinic input]
4995+
_decimal.Decimal.is_normal
4996+
4997+
context: object = None
4998+
4999+
Return True if the argument is a normal number and False otherwise.
5000+
5001+
Normal number is a finite nonzero number, which is not subnormal.
5002+
[clinic start generated code]*/
5003+
5004+
static PyObject *
5005+
_decimal_Decimal_is_normal_impl(PyObject *self, PyObject *context)
5006+
/*[clinic end generated code: output=40cc429d388eb464 input=9def7316be59ce4e]*/
5007+
{
5008+
return dec_mpd_isnormal(self, context);
5009+
}
5010+
5011+
/*[clinic input]
5012+
_decimal.Decimal.is_subnormal
5013+
5014+
context: object = None
5015+
5016+
Return True if the argument is subnormal, and False otherwise.
5017+
5018+
A number is subnormal if it is non-zero, finite, and has an adjusted
5019+
exponent less than Emin.
5020+
[clinic start generated code]*/
5021+
5022+
static PyObject *
5023+
_decimal_Decimal_is_subnormal_impl(PyObject *self, PyObject *context)
5024+
/*[clinic end generated code: output=6f7d422b1f387d7f input=08e90e1d9fb87300]*/
5025+
{
5026+
return dec_mpd_issubnormal(self, context);
5027+
}
5028+
48765029
/* Unary functions, no context arg */
48775030

48785031
/*[clinic input]
@@ -5804,21 +5957,21 @@ static PyMethodDef dec_methods [] =
58045957
_DECIMAL_DECIMAL_REMAINDER_NEAR_METHODDEF
58055958

58065959
/* Ternary arithmetic functions, optional context arg */
5807-
{ "fma", _PyCFunction_CAST(dec_mpd_qfma), METH_VARARGS|METH_KEYWORDS, doc_fma },
5960+
_DECIMAL_DECIMAL_FMA_METHODDEF
58085961

58095962
/* Boolean functions, no context arg */
5810-
{ "is_canonical", dec_mpd_iscanonical, METH_NOARGS, doc_is_canonical },
5811-
{ "is_finite", dec_mpd_isfinite, METH_NOARGS, doc_is_finite },
5812-
{ "is_infinite", dec_mpd_isinfinite, METH_NOARGS, doc_is_infinite },
5813-
{ "is_nan", dec_mpd_isnan, METH_NOARGS, doc_is_nan },
5814-
{ "is_qnan", dec_mpd_isqnan, METH_NOARGS, doc_is_qnan },
5815-
{ "is_snan", dec_mpd_issnan, METH_NOARGS, doc_is_snan },
5816-
{ "is_signed", dec_mpd_issigned, METH_NOARGS, doc_is_signed },
5817-
{ "is_zero", dec_mpd_iszero, METH_NOARGS, doc_is_zero },
5963+
_DECIMAL_DECIMAL_IS_CANONICAL_METHODDEF
5964+
_DECIMAL_DECIMAL_IS_FINITE_METHODDEF
5965+
_DECIMAL_DECIMAL_IS_INFINITE_METHODDEF
5966+
_DECIMAL_DECIMAL_IS_NAN_METHODDEF
5967+
_DECIMAL_DECIMAL_IS_QNAN_METHODDEF
5968+
_DECIMAL_DECIMAL_IS_SNAN_METHODDEF
5969+
_DECIMAL_DECIMAL_IS_SIGNED_METHODDEF
5970+
_DECIMAL_DECIMAL_IS_ZERO_METHODDEF
58185971

58195972
/* Boolean functions, optional context arg */
5820-
{ "is_normal", _PyCFunction_CAST(dec_mpd_isnormal), METH_VARARGS|METH_KEYWORDS, doc_is_normal },
5821-
{ "is_subnormal", _PyCFunction_CAST(dec_mpd_issubnormal), METH_VARARGS|METH_KEYWORDS, doc_is_subnormal },
5973+
_DECIMAL_DECIMAL_IS_NORMAL_METHODDEF
5974+
_DECIMAL_DECIMAL_IS_SUBNORMAL_METHODDEF
58225975

58235976
/* Unary functions, no context arg */
58245977
_DECIMAL_DECIMAL_ADJUSTED_METHODDEF

0 commit comments

Comments
 (0)