Skip to content

Commit 9c9ec72

Browse files
committed
start Context class...
1 parent d0b03ff commit 9c9ec72

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;
@@ -6362,6 +6363,70 @@ DecCtx_UnaryFunc(mpd_qround_to_int)
63626363
DecCtx_UnaryFunc(mpd_qround_to_intx)
63636364
DecCtx_UnaryFunc(mpd_qsqrt)
63646365

6366+
/*[clinic input]
6367+
_decimal.Context.abs
6368+
6369+
x: object
6370+
/
6371+
6372+
Return the absolute value of x.
6373+
[clinic start generated code]*/
6374+
6375+
static PyObject *
6376+
_decimal_Context_abs(PyObject *self, PyObject *x)
6377+
/*[clinic end generated code: output=91c87f912542b183 input=2b69fea7e24c710f]*/
6378+
{
6379+
return ctx_mpd_qabs(self, x);
6380+
}
6381+
6382+
/*[clinic input]
6383+
_decimal.Context.exp
6384+
6385+
x: object
6386+
/
6387+
6388+
Return e ** x.
6389+
[clinic start generated code]*/
6390+
6391+
static PyObject *
6392+
_decimal_Context_exp(PyObject *self, PyObject *x)
6393+
/*[clinic end generated code: output=f8d14995cc8c76e7 input=37f44653b0f7397e]*/
6394+
{
6395+
return ctx_mpd_qexp(self, x);
6396+
}
6397+
6398+
/*[clinic input]
6399+
_decimal.Context.ln
6400+
6401+
x: object
6402+
/
6403+
6404+
Return the natural (base e) logarithm of x.
6405+
[clinic start generated code]*/
6406+
6407+
static PyObject *
6408+
_decimal_Context_ln(PyObject *self, PyObject *x)
6409+
/*[clinic end generated code: output=9caae5de322ac831 input=e76c7d7b8912accb]*/
6410+
{
6411+
return ctx_mpd_qln(self, x);
6412+
}
6413+
6414+
/*[clinic input]
6415+
_decimal.Context.log10
6416+
6417+
x: object
6418+
/
6419+
6420+
Return the base 10 logarithm of x.
6421+
[clinic start generated code]*/
6422+
6423+
static PyObject *
6424+
_decimal_Context_log10(PyObject *self, PyObject *x)
6425+
/*[clinic end generated code: output=480e54cfd384b3ef input=c0199e3f92fc3075]*/
6426+
{
6427+
return ctx_mpd_qlog10(self, x);
6428+
}
6429+
63656430
/* Binary arithmetic functions */
63666431
DecCtx_BinaryFunc(mpd_qadd)
63676432
DecCtx_BinaryFunc(mpd_qcompare)
@@ -6725,10 +6790,10 @@ ctx_mpd_same_quantum(PyObject *context, PyObject *args)
67256790
static PyMethodDef context_methods [] =
67266791
{
67276792
/* Unary arithmetic functions */
6728-
{ "abs", ctx_mpd_qabs, METH_O, doc_ctx_abs },
6729-
{ "exp", ctx_mpd_qexp, METH_O, doc_ctx_exp },
6730-
{ "ln", ctx_mpd_qln, METH_O, doc_ctx_ln },
6731-
{ "log10", ctx_mpd_qlog10, METH_O, doc_ctx_log10 },
6793+
_DECIMAL_CONTEXT_ABS_METHODDEF
6794+
_DECIMAL_CONTEXT_EXP_METHODDEF
6795+
_DECIMAL_CONTEXT_LN_METHODDEF
6796+
_DECIMAL_CONTEXT_LOG10_METHODDEF
67326797
{ "minus", ctx_mpd_qminus, METH_O, doc_ctx_minus },
67336798
{ "next_minus", ctx_mpd_qnext_minus, METH_O, doc_ctx_next_minus },
67346799
{ "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)