Skip to content

Commit 82e562f

Browse files
committed
start Context class...
1 parent 4394954 commit 82e562f

File tree

3 files changed

+107
-26
lines changed

3 files changed

+107
-26
lines changed

Modules/_decimal/_decimal.c

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@
6363
/*[clinic input]
6464
module _decimal
6565
class _decimal.Decimal "PyObject *" "&dec_spec"
66+
class _decimal.Context "PyObject *" "&ctx_spec"
6667
[clinic start generated code]*/
67-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e0e1f68f1f413f5f]*/
68+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=8c3aa7cfde934d7b]*/
6869

6970
struct PyDecContextObject;
7071
struct DecCondMap;
@@ -6369,6 +6370,70 @@ DecCtx_UnaryFunc(mpd_qround_to_int)
63696370
DecCtx_UnaryFunc(mpd_qround_to_intx)
63706371
DecCtx_UnaryFunc(mpd_qsqrt)
63716372

6373+
/*[clinic input]
6374+
_decimal.Context.abs
6375+
6376+
x: object
6377+
/
6378+
6379+
Return the absolute value of x.
6380+
[clinic start generated code]*/
6381+
6382+
static PyObject *
6383+
_decimal_Context_abs(PyObject *self, PyObject *x)
6384+
/*[clinic end generated code: output=91c87f912542b183 input=2b69fea7e24c710f]*/
6385+
{
6386+
return ctx_mpd_qabs(self, x);
6387+
}
6388+
6389+
/*[clinic input]
6390+
_decimal.Context.exp
6391+
6392+
x: object
6393+
/
6394+
6395+
Return e ** x.
6396+
[clinic start generated code]*/
6397+
6398+
static PyObject *
6399+
_decimal_Context_exp(PyObject *self, PyObject *x)
6400+
/*[clinic end generated code: output=f8d14995cc8c76e7 input=37f44653b0f7397e]*/
6401+
{
6402+
return ctx_mpd_qexp(self, x);
6403+
}
6404+
6405+
/*[clinic input]
6406+
_decimal.Context.ln
6407+
6408+
x: object
6409+
/
6410+
6411+
Return the natural (base e) logarithm of x.
6412+
[clinic start generated code]*/
6413+
6414+
static PyObject *
6415+
_decimal_Context_ln(PyObject *self, PyObject *x)
6416+
/*[clinic end generated code: output=9caae5de322ac831 input=e76c7d7b8912accb]*/
6417+
{
6418+
return ctx_mpd_qln(self, x);
6419+
}
6420+
6421+
/*[clinic input]
6422+
_decimal.Context.log10
6423+
6424+
x: object
6425+
/
6426+
6427+
Return the base 10 logarithm of x.
6428+
[clinic start generated code]*/
6429+
6430+
static PyObject *
6431+
_decimal_Context_log10(PyObject *self, PyObject *x)
6432+
/*[clinic end generated code: output=480e54cfd384b3ef input=c0199e3f92fc3075]*/
6433+
{
6434+
return ctx_mpd_qlog10(self, x);
6435+
}
6436+
63726437
/* Binary arithmetic functions */
63736438
DecCtx_BinaryFunc(mpd_qadd)
63746439
DecCtx_BinaryFunc(mpd_qcompare)
@@ -6732,10 +6797,10 @@ ctx_mpd_same_quantum(PyObject *context, PyObject *args)
67326797
static PyMethodDef context_methods [] =
67336798
{
67346799
/* Unary arithmetic functions */
6735-
{ "abs", ctx_mpd_qabs, METH_O, doc_ctx_abs },
6736-
{ "exp", ctx_mpd_qexp, METH_O, doc_ctx_exp },
6737-
{ "ln", ctx_mpd_qln, METH_O, doc_ctx_ln },
6738-
{ "log10", ctx_mpd_qlog10, METH_O, doc_ctx_log10 },
6800+
_DECIMAL_CONTEXT_ABS_METHODDEF
6801+
_DECIMAL_CONTEXT_EXP_METHODDEF
6802+
_DECIMAL_CONTEXT_LN_METHODDEF
6803+
_DECIMAL_CONTEXT_LOG10_METHODDEF
67396804
{ "minus", ctx_mpd_qminus, METH_O, doc_ctx_minus },
67406805
{ "next_minus", ctx_mpd_qnext_minus, METH_O, doc_ctx_next_minus },
67416806
{ "next_plus", ctx_mpd_qnext_plus, METH_O, doc_ctx_next_plus },

Modules/_decimal/clinic/_decimal.c.h

Lines changed: 37 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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ if the _clamp field of the context is set to 1 (IEEE clamp mode). Etop()\n\
135135
must not be negative.\n\
136136
\n");
137137

138-
PyDoc_STRVAR(doc_ctx_abs,
139-
"abs($self, x, /)\n--\n\n\
140-
Return the absolute value of x.\n\
141-
\n");
142-
143138
PyDoc_STRVAR(doc_ctx_add,
144139
"add($self, x, y, /)\n--\n\n\
145140
Return the sum of x and y.\n\
@@ -200,11 +195,6 @@ PyDoc_STRVAR(doc_ctx_divmod,
200195
Return quotient and remainder of the division x / y.\n\
201196
\n");
202197

203-
PyDoc_STRVAR(doc_ctx_exp,
204-
"exp($self, x, /)\n--\n\n\
205-
Return e ** x.\n\
206-
\n");
207-
208198
PyDoc_STRVAR(doc_ctx_fma,
209199
"fma($self, x, y, z, /)\n--\n\n\
210200
Return x multiplied by y, plus z.\n\
@@ -260,16 +250,6 @@ PyDoc_STRVAR(doc_ctx_is_zero,
260250
Return True if x is a zero, False otherwise.\n\
261251
\n");
262252

263-
PyDoc_STRVAR(doc_ctx_ln,
264-
"ln($self, x, /)\n--\n\n\
265-
Return the natural (base e) logarithm of x.\n\
266-
\n");
267-
268-
PyDoc_STRVAR(doc_ctx_log10,
269-
"log10($self, x, /)\n--\n\n\
270-
Return the base 10 logarithm of x.\n\
271-
\n");
272-
273253
PyDoc_STRVAR(doc_ctx_logb,
274254
"logb($self, x, /)\n--\n\n\
275255
Return the exponent of the magnitude of the operand's MSD.\n\

0 commit comments

Comments
 (0)