Skip to content

Commit 43a9798

Browse files
committed
+1 // more unary
1 parent 30abd3a commit 43a9798

File tree

3 files changed

+243
-57
lines changed

3 files changed

+243
-57
lines changed

Modules/_decimal/_decimal.c

Lines changed: 157 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6419,6 +6419,154 @@ _decimal_Context_log10(PyObject *self, PyObject *x)
64196419
return ctx_mpd_qlog10(self, x);
64206420
}
64216421

6422+
/*[clinic input]
6423+
_decimal.Context.minus
6424+
6425+
x: object
6426+
/
6427+
6428+
Minus corresponds to unary prefix minus in Python.
6429+
6430+
This operation applies the context to the result.
6431+
[clinic start generated code]*/
6432+
6433+
static PyObject *
6434+
_decimal_Context_minus(PyObject *self, PyObject *x)
6435+
/*[clinic end generated code: output=8352f35b26cf4493 input=4cbb654187cf6e69]*/
6436+
{
6437+
return ctx_mpd_qminus(self, x);
6438+
}
6439+
6440+
/*[clinic input]
6441+
_decimal.Context.next_minus
6442+
6443+
x: object
6444+
/
6445+
6446+
Return the largest representable number smaller than x.
6447+
[clinic start generated code]*/
6448+
6449+
static PyObject *
6450+
_decimal_Context_next_minus(PyObject *self, PyObject *x)
6451+
/*[clinic end generated code: output=ff826537eb841b3e input=3e672b2302650914]*/
6452+
{
6453+
return ctx_mpd_qnext_minus(self, x);
6454+
}
6455+
6456+
/*[clinic input]
6457+
_decimal.Context.next_plus
6458+
6459+
x: object
6460+
/
6461+
6462+
Return the smallest representable number larger than x.
6463+
[clinic start generated code]*/
6464+
6465+
static PyObject *
6466+
_decimal_Context_next_plus(PyObject *self, PyObject *x)
6467+
/*[clinic end generated code: output=2a2ae1e3253efc1b input=dbf8636c5ee0b3f0]*/
6468+
{
6469+
return ctx_mpd_qnext_plus(self, x);
6470+
}
6471+
6472+
/*[clinic input]
6473+
_decimal.Context.normalize
6474+
6475+
x: object
6476+
/
6477+
6478+
Reduce x to its simplest form. Alias for reduce(x).
6479+
[clinic start generated code]*/
6480+
6481+
static PyObject *
6482+
_decimal_Context_normalize(PyObject *self, PyObject *x)
6483+
/*[clinic end generated code: output=aa671c1aec4547cc input=f0b0fa9384f5da94]*/
6484+
{
6485+
return ctx_mpd_qreduce(self, x);
6486+
}
6487+
6488+
/*[clinic input]
6489+
_decimal.Context.plus
6490+
6491+
x: object
6492+
/
6493+
6494+
Plus corresponds to the unary prefix plus operator in Python.
6495+
6496+
This operation applies the context to the result.
6497+
[clinic start generated code]*/
6498+
6499+
static PyObject *
6500+
_decimal_Context_plus(PyObject *self, PyObject *x)
6501+
/*[clinic end generated code: output=b98165faa988e531 input=a3f9833ca90ec079]*/
6502+
{
6503+
return ctx_mpd_qplus(self, x);
6504+
}
6505+
6506+
/*[clinic input]
6507+
_decimal.Context.to_integral_value
6508+
6509+
x: object
6510+
/
6511+
6512+
Round to an integer.
6513+
[clinic start generated code]*/
6514+
6515+
static PyObject *
6516+
_decimal_Context_to_integral_value(PyObject *self, PyObject *x)
6517+
/*[clinic end generated code: output=41383a5b39dcd0d0 input=c6dc6ea5ea1e89c5]*/
6518+
{
6519+
return ctx_mpd_qround_to_int(self, x);
6520+
}
6521+
6522+
/*[clinic input]
6523+
_decimal.Context.to_integral_exact
6524+
6525+
x: object
6526+
/
6527+
6528+
Round to an integer. Signal if the result is rounded or inexact.
6529+
[clinic start generated code]*/
6530+
6531+
static PyObject *
6532+
_decimal_Context_to_integral_exact(PyObject *self, PyObject *x)
6533+
/*[clinic end generated code: output=2480c73e9fb130a1 input=7fbed586d5991bc2]*/
6534+
{
6535+
return ctx_mpd_qround_to_intx(self, x);
6536+
}
6537+
6538+
/*[clinic input]
6539+
_decimal.Context.to_integral
6540+
6541+
x: object
6542+
/
6543+
6544+
Identical to to_integral_value(x).
6545+
[clinic start generated code]*/
6546+
6547+
static PyObject *
6548+
_decimal_Context_to_integral(PyObject *self, PyObject *x)
6549+
/*[clinic end generated code: output=6c5808344ce33746 input=fb37223022ffc973]*/
6550+
{
6551+
return ctx_mpd_qround_to_int(self, x);
6552+
}
6553+
6554+
/*[clinic input]
6555+
_decimal.Context.sqrt
6556+
6557+
x: object
6558+
/
6559+
6560+
Square root of a non-negative number to context precision.
6561+
[clinic start generated code]*/
6562+
6563+
static PyObject *
6564+
_decimal_Context_sqrt(PyObject *self, PyObject *x)
6565+
/*[clinic end generated code: output=7f5cab169abf8a1a input=37375b6ff339cc93]*/
6566+
{
6567+
return ctx_mpd_qsqrt(self, x);
6568+
}
6569+
64226570
/* Binary arithmetic functions */
64236571
DecCtx_BinaryFunc(mpd_qadd)
64246572
DecCtx_BinaryFunc(mpd_qcompare)
@@ -6786,15 +6934,15 @@ static PyMethodDef context_methods [] =
67866934
_DECIMAL_CONTEXT_EXP_METHODDEF
67876935
_DECIMAL_CONTEXT_LN_METHODDEF
67886936
_DECIMAL_CONTEXT_LOG10_METHODDEF
6789-
{ "minus", ctx_mpd_qminus, METH_O, doc_ctx_minus },
6790-
{ "next_minus", ctx_mpd_qnext_minus, METH_O, doc_ctx_next_minus },
6791-
{ "next_plus", ctx_mpd_qnext_plus, METH_O, doc_ctx_next_plus },
6792-
{ "normalize", ctx_mpd_qreduce, METH_O, doc_ctx_normalize },
6793-
{ "plus", ctx_mpd_qplus, METH_O, doc_ctx_plus },
6794-
{ "to_integral", ctx_mpd_qround_to_int, METH_O, doc_ctx_to_integral },
6795-
{ "to_integral_exact", ctx_mpd_qround_to_intx, METH_O, doc_ctx_to_integral_exact },
6796-
{ "to_integral_value", ctx_mpd_qround_to_int, METH_O, doc_ctx_to_integral_value },
6797-
{ "sqrt", ctx_mpd_qsqrt, METH_O, doc_ctx_sqrt },
6937+
_DECIMAL_CONTEXT_MINUS_METHODDEF
6938+
_DECIMAL_CONTEXT_NEXT_MINUS_METHODDEF
6939+
_DECIMAL_CONTEXT_NEXT_PLUS_METHODDEF
6940+
_DECIMAL_CONTEXT_NORMALIZE_METHODDEF
6941+
_DECIMAL_CONTEXT_PLUS_METHODDEF
6942+
_DECIMAL_CONTEXT_TO_INTEGRAL_METHODDEF
6943+
_DECIMAL_CONTEXT_TO_INTEGRAL_EXACT_METHODDEF
6944+
_DECIMAL_CONTEXT_TO_INTEGRAL_VALUE_METHODDEF
6945+
_DECIMAL_CONTEXT_SQRT_METHODDEF
67986946

67996947
/* Binary arithmetic functions */
68006948
{ "add", ctx_mpd_qadd, METH_VARARGS, doc_ctx_add },

Modules/_decimal/clinic/_decimal.c.h

Lines changed: 86 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 & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -295,48 +295,21 @@ PyDoc_STRVAR(doc_ctx_min_mag,
295295
Compare the values numerically with their sign ignored.\n\
296296
\n");
297297

298-
PyDoc_STRVAR(doc_ctx_minus,
299-
"minus($self, x, /)\n--\n\n\
300-
Minus corresponds to the unary prefix minus operator in Python, but applies\n\
301-
the context to the result.\n\
302-
\n");
303-
304298
PyDoc_STRVAR(doc_ctx_multiply,
305299
"multiply($self, x, y, /)\n--\n\n\
306300
Return the product of x and y.\n\
307301
\n");
308302

309-
PyDoc_STRVAR(doc_ctx_next_minus,
310-
"next_minus($self, x, /)\n--\n\n\
311-
Return the largest representable number smaller than x.\n\
312-
\n");
313-
314-
PyDoc_STRVAR(doc_ctx_next_plus,
315-
"next_plus($self, x, /)\n--\n\n\
316-
Return the smallest representable number larger than x.\n\
317-
\n");
318-
319303
PyDoc_STRVAR(doc_ctx_next_toward,
320304
"next_toward($self, x, y, /)\n--\n\n\
321305
Return the number closest to x, in the direction towards y.\n\
322306
\n");
323307

324-
PyDoc_STRVAR(doc_ctx_normalize,
325-
"normalize($self, x, /)\n--\n\n\
326-
Reduce x to its simplest form. Alias for reduce(x).\n\
327-
\n");
328-
329308
PyDoc_STRVAR(doc_ctx_number_class,
330309
"number_class($self, x, /)\n--\n\n\
331310
Return an indication of the class of x.\n\
332311
\n");
333312

334-
PyDoc_STRVAR(doc_ctx_plus,
335-
"plus($self, x, /)\n--\n\n\
336-
Plus corresponds to the unary prefix plus operator in Python, but applies\n\
337-
the context to the result.\n\
338-
\n");
339-
340313
PyDoc_STRVAR(doc_ctx_power,
341314
"power($self, /, a, b, modulo=None)\n--\n\n\
342315
Compute a**b. If 'a' is negative, then 'b' must be integral. The result\n\
@@ -397,11 +370,6 @@ PyDoc_STRVAR(doc_ctx_shift,
397370
Return a copy of x, shifted by y places.\n\
398371
\n");
399372

400-
PyDoc_STRVAR(doc_ctx_sqrt,
401-
"sqrt($self, x, /)\n--\n\n\
402-
Square root of a non-negative number to context precision.\n\
403-
\n");
404-
405373
PyDoc_STRVAR(doc_ctx_subtract,
406374
"subtract($self, x, y, /)\n--\n\n\
407375
Return the difference between x and y.\n\
@@ -412,21 +380,6 @@ PyDoc_STRVAR(doc_ctx_to_eng_string,
412380
Convert a number to a string, using engineering notation.\n\
413381
\n");
414382

415-
PyDoc_STRVAR(doc_ctx_to_integral,
416-
"to_integral($self, x, /)\n--\n\n\
417-
Identical to to_integral_value(x).\n\
418-
\n");
419-
420-
PyDoc_STRVAR(doc_ctx_to_integral_exact,
421-
"to_integral_exact($self, x, /)\n--\n\n\
422-
Round to an integer. Signal if the result is rounded or inexact.\n\
423-
\n");
424-
425-
PyDoc_STRVAR(doc_ctx_to_integral_value,
426-
"to_integral_value($self, x, /)\n--\n\n\
427-
Round to an integer.\n\
428-
\n");
429-
430383
PyDoc_STRVAR(doc_ctx_to_sci_string,
431384
"to_sci_string($self, x, /)\n--\n\n\
432385
Convert a number to a string using scientific notation.\n\

0 commit comments

Comments
 (0)