Skip to content

Commit 621f4f1

Browse files
committed
+1 // more unary
1 parent 82e562f commit 621f4f1

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
@@ -6434,6 +6434,154 @@ _decimal_Context_log10(PyObject *self, PyObject *x)
64346434
return ctx_mpd_qlog10(self, x);
64356435
}
64366436

6437+
/*[clinic input]
6438+
_decimal.Context.minus
6439+
6440+
x: object
6441+
/
6442+
6443+
Minus corresponds to unary prefix minus in Python.
6444+
6445+
This operation applies the context to the result.
6446+
[clinic start generated code]*/
6447+
6448+
static PyObject *
6449+
_decimal_Context_minus(PyObject *self, PyObject *x)
6450+
/*[clinic end generated code: output=8352f35b26cf4493 input=4cbb654187cf6e69]*/
6451+
{
6452+
return ctx_mpd_qminus(self, x);
6453+
}
6454+
6455+
/*[clinic input]
6456+
_decimal.Context.next_minus
6457+
6458+
x: object
6459+
/
6460+
6461+
Return the largest representable number smaller than x.
6462+
[clinic start generated code]*/
6463+
6464+
static PyObject *
6465+
_decimal_Context_next_minus(PyObject *self, PyObject *x)
6466+
/*[clinic end generated code: output=ff826537eb841b3e input=3e672b2302650914]*/
6467+
{
6468+
return ctx_mpd_qnext_minus(self, x);
6469+
}
6470+
6471+
/*[clinic input]
6472+
_decimal.Context.next_plus
6473+
6474+
x: object
6475+
/
6476+
6477+
Return the smallest representable number larger than x.
6478+
[clinic start generated code]*/
6479+
6480+
static PyObject *
6481+
_decimal_Context_next_plus(PyObject *self, PyObject *x)
6482+
/*[clinic end generated code: output=2a2ae1e3253efc1b input=dbf8636c5ee0b3f0]*/
6483+
{
6484+
return ctx_mpd_qnext_plus(self, x);
6485+
}
6486+
6487+
/*[clinic input]
6488+
_decimal.Context.normalize
6489+
6490+
x: object
6491+
/
6492+
6493+
Reduce x to its simplest form. Alias for reduce(x).
6494+
[clinic start generated code]*/
6495+
6496+
static PyObject *
6497+
_decimal_Context_normalize(PyObject *self, PyObject *x)
6498+
/*[clinic end generated code: output=aa671c1aec4547cc input=f0b0fa9384f5da94]*/
6499+
{
6500+
return ctx_mpd_qreduce(self, x);
6501+
}
6502+
6503+
/*[clinic input]
6504+
_decimal.Context.plus
6505+
6506+
x: object
6507+
/
6508+
6509+
Plus corresponds to the unary prefix plus operator in Python.
6510+
6511+
This operation applies the context to the result.
6512+
[clinic start generated code]*/
6513+
6514+
static PyObject *
6515+
_decimal_Context_plus(PyObject *self, PyObject *x)
6516+
/*[clinic end generated code: output=b98165faa988e531 input=a3f9833ca90ec079]*/
6517+
{
6518+
return ctx_mpd_qplus(self, x);
6519+
}
6520+
6521+
/*[clinic input]
6522+
_decimal.Context.to_integral_value
6523+
6524+
x: object
6525+
/
6526+
6527+
Round to an integer.
6528+
[clinic start generated code]*/
6529+
6530+
static PyObject *
6531+
_decimal_Context_to_integral_value(PyObject *self, PyObject *x)
6532+
/*[clinic end generated code: output=41383a5b39dcd0d0 input=c6dc6ea5ea1e89c5]*/
6533+
{
6534+
return ctx_mpd_qround_to_int(self, x);
6535+
}
6536+
6537+
/*[clinic input]
6538+
_decimal.Context.to_integral_exact
6539+
6540+
x: object
6541+
/
6542+
6543+
Round to an integer. Signal if the result is rounded or inexact.
6544+
[clinic start generated code]*/
6545+
6546+
static PyObject *
6547+
_decimal_Context_to_integral_exact(PyObject *self, PyObject *x)
6548+
/*[clinic end generated code: output=2480c73e9fb130a1 input=7fbed586d5991bc2]*/
6549+
{
6550+
return ctx_mpd_qround_to_intx(self, x);
6551+
}
6552+
6553+
/*[clinic input]
6554+
_decimal.Context.to_integral
6555+
6556+
x: object
6557+
/
6558+
6559+
Identical to to_integral_value(x).
6560+
[clinic start generated code]*/
6561+
6562+
static PyObject *
6563+
_decimal_Context_to_integral(PyObject *self, PyObject *x)
6564+
/*[clinic end generated code: output=6c5808344ce33746 input=fb37223022ffc973]*/
6565+
{
6566+
return ctx_mpd_qround_to_int(self, x);
6567+
}
6568+
6569+
/*[clinic input]
6570+
_decimal.Context.sqrt
6571+
6572+
x: object
6573+
/
6574+
6575+
Square root of a non-negative number to context precision.
6576+
[clinic start generated code]*/
6577+
6578+
static PyObject *
6579+
_decimal_Context_sqrt(PyObject *self, PyObject *x)
6580+
/*[clinic end generated code: output=7f5cab169abf8a1a input=37375b6ff339cc93]*/
6581+
{
6582+
return ctx_mpd_qsqrt(self, x);
6583+
}
6584+
64376585
/* Binary arithmetic functions */
64386586
DecCtx_BinaryFunc(mpd_qadd)
64396587
DecCtx_BinaryFunc(mpd_qcompare)
@@ -6801,15 +6949,15 @@ static PyMethodDef context_methods [] =
68016949
_DECIMAL_CONTEXT_EXP_METHODDEF
68026950
_DECIMAL_CONTEXT_LN_METHODDEF
68036951
_DECIMAL_CONTEXT_LOG10_METHODDEF
6804-
{ "minus", ctx_mpd_qminus, METH_O, doc_ctx_minus },
6805-
{ "next_minus", ctx_mpd_qnext_minus, METH_O, doc_ctx_next_minus },
6806-
{ "next_plus", ctx_mpd_qnext_plus, METH_O, doc_ctx_next_plus },
6807-
{ "normalize", ctx_mpd_qreduce, METH_O, doc_ctx_normalize },
6808-
{ "plus", ctx_mpd_qplus, METH_O, doc_ctx_plus },
6809-
{ "to_integral", ctx_mpd_qround_to_int, METH_O, doc_ctx_to_integral },
6810-
{ "to_integral_exact", ctx_mpd_qround_to_intx, METH_O, doc_ctx_to_integral_exact },
6811-
{ "to_integral_value", ctx_mpd_qround_to_int, METH_O, doc_ctx_to_integral_value },
6812-
{ "sqrt", ctx_mpd_qsqrt, METH_O, doc_ctx_sqrt },
6952+
_DECIMAL_CONTEXT_MINUS_METHODDEF
6953+
_DECIMAL_CONTEXT_NEXT_MINUS_METHODDEF
6954+
_DECIMAL_CONTEXT_NEXT_PLUS_METHODDEF
6955+
_DECIMAL_CONTEXT_NORMALIZE_METHODDEF
6956+
_DECIMAL_CONTEXT_PLUS_METHODDEF
6957+
_DECIMAL_CONTEXT_TO_INTEGRAL_METHODDEF
6958+
_DECIMAL_CONTEXT_TO_INTEGRAL_EXACT_METHODDEF
6959+
_DECIMAL_CONTEXT_TO_INTEGRAL_VALUE_METHODDEF
6960+
_DECIMAL_CONTEXT_SQRT_METHODDEF
68136961

68146962
/* Binary arithmetic functions */
68156963
{ "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)