Mercurial > cpython-lru_cache-weakref
annotate Modules/_decimal/_decimal.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | cbd78679080b |
| children |
| rev | line source |
|---|---|
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2 * Copyright (c) 2008-2012 Stefan Krah. All rights reserved. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3 * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4 * Redistribution and use in source and binary forms, with or without |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5 * modification, are permitted provided that the following conditions |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
6 * are met: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
7 * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
8 * 1. Redistributions of source code must retain the above copyright |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
9 * notice, this list of conditions and the following disclaimer. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
10 * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
12 * notice, this list of conditions and the following disclaimer in the |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
13 * documentation and/or other materials provided with the distribution. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
14 * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
25 * SUCH DAMAGE. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
26 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
27 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
28 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
29 #include <Python.h> |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
30 #include "longintrepr.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
31 #include "pythread.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
32 #include "structmember.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
33 #include "complexobject.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
34 #include "mpdecimal.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
35 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
36 #include <stdlib.h> |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
37 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
38 #include "docstrings.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
39 #include "memory.h" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
40 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
41 |
|
87517
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
42 #if MPD_MAJOR_VERSION != 2 |
|
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
43 #error "libmpdec major version 2 required" |
|
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
44 #endif |
|
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
45 |
|
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
46 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
47 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
48 * Type sizes with assertions in mpdecimal.h and pyport.h: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
49 * sizeof(size_t) == sizeof(Py_ssize_t) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
50 * sizeof(size_t) == sizeof(mpd_uint_t) == sizeof(mpd_ssize_t) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
51 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
52 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
53 #ifdef TEST_COVERAGE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
54 #undef Py_LOCAL_INLINE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
55 #define Py_LOCAL_INLINE Py_LOCAL |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
56 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
57 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
58 #define MPD_Float_operation MPD_Not_implemented |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
59 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
60 #define BOUNDS_CHECK(x, MIN, MAX) x = (x < MIN || MAX < x) ? MAX : x |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
61 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
62 |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
63 /* _Py_DEC_MINALLOC >= MPD_MINALLOC */ |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
64 #define _Py_DEC_MINALLOC 4 |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
65 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
66 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
67 PyObject_HEAD |
|
76206
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
68 Py_hash_t hash; |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
69 mpd_t dec; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
70 mpd_uint_t data[_Py_DEC_MINALLOC]; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
71 } PyDecObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
72 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
73 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
74 PyObject_HEAD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
75 uint32_t *flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
76 } PyDecSignalDictObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
77 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
78 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
79 PyObject_HEAD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
80 mpd_context_t ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
81 PyObject *traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
82 PyObject *flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
83 int capitals; |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
84 #ifndef WITHOUT_THREADS |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
85 PyThreadState *tstate; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
86 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
87 } PyDecContextObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
88 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
89 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
90 PyObject_HEAD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
91 PyObject *local; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
92 PyObject *global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
93 } PyDecContextManagerObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
94 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
95 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
96 #undef MPD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
97 #undef CTX |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
98 static PyTypeObject PyDec_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
99 static PyTypeObject *PyDecSignalDict_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
100 static PyTypeObject PyDecContext_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
101 static PyTypeObject PyDecContextManager_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
102 #define PyDec_CheckExact(v) (Py_TYPE(v) == &PyDec_Type) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
103 #define PyDec_Check(v) PyObject_TypeCheck(v, &PyDec_Type) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
104 #define PyDecSignalDict_Check(v) (Py_TYPE(v) == PyDecSignalDict_Type) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
105 #define PyDecContext_Check(v) PyObject_TypeCheck(v, &PyDecContext_Type) |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
106 #define MPD(v) (&((PyDecObject *)v)->dec) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
107 #define SdFlagAddr(v) (((PyDecSignalDictObject *)v)->flags) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
108 #define SdFlags(v) (*((PyDecSignalDictObject *)v)->flags) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
109 #define CTX(v) (&((PyDecContextObject *)v)->ctx) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
110 #define CtxCaps(v) (((PyDecContextObject *)v)->capitals) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
111 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
112 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
113 Py_LOCAL_INLINE(PyObject *) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
114 incr_true(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
115 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
116 Py_INCREF(Py_True); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
117 return Py_True; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
118 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
119 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
120 Py_LOCAL_INLINE(PyObject *) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
121 incr_false(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
122 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
123 Py_INCREF(Py_False); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
124 return Py_False; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
125 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
126 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
127 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
128 #ifdef WITHOUT_THREADS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
129 /* Default module context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
130 static PyObject *module_context = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
131 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
132 /* Key for thread state dictionary */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
133 static PyObject *tls_context_key = NULL; |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
134 /* Invariant: NULL or the most recently accessed thread local context */ |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
135 static PyDecContextObject *cached_context = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
136 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
137 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
138 /* Template for creating new thread contexts, calling Context() without |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
139 * arguments and initializing the module_context on first access. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
140 static PyObject *default_context_template = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
141 /* Basic and extended context templates */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
142 static PyObject *basic_context_template = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
143 static PyObject *extended_context_template = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
144 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
145 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
146 /* Error codes for functions that return signals or conditions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
147 #define DEC_INVALID_SIGNALS (MPD_Max_status+1U) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
148 #define DEC_ERR_OCCURRED (DEC_INVALID_SIGNALS<<1) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
149 #define DEC_ERRORS (DEC_INVALID_SIGNALS|DEC_ERR_OCCURRED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
150 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
151 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
152 const char *name; /* condition or signal name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
153 const char *fqname; /* fully qualified name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
154 uint32_t flag; /* libmpdec flag */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
155 PyObject *ex; /* corresponding exception */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
156 } DecCondMap; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
157 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
158 /* Top level Exception; inherits from ArithmeticError */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
159 static PyObject *DecimalException = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
160 |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
161 /* Exceptions that correspond to IEEE signals */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
162 #define SUBNORMAL 5 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
163 #define INEXACT 6 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
164 #define ROUNDED 7 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
165 #define SIGNAL_MAP_LEN 9 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
166 static DecCondMap signal_map[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
167 {"InvalidOperation", "decimal.InvalidOperation", MPD_IEEE_Invalid_operation, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
168 {"FloatOperation", "decimal.FloatOperation", MPD_Float_operation, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
169 {"DivisionByZero", "decimal.DivisionByZero", MPD_Division_by_zero, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
170 {"Overflow", "decimal.Overflow", MPD_Overflow, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
171 {"Underflow", "decimal.Underflow", MPD_Underflow, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
172 {"Subnormal", "decimal.Subnormal", MPD_Subnormal, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
173 {"Inexact", "decimal.Inexact", MPD_Inexact, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
174 {"Rounded", "decimal.Rounded", MPD_Rounded, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
175 {"Clamped", "decimal.Clamped", MPD_Clamped, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
176 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
177 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
178 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
179 /* Exceptions that inherit from InvalidOperation */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
180 static DecCondMap cond_map[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
181 {"InvalidOperation", "decimal.InvalidOperation", MPD_Invalid_operation, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
182 {"ConversionSyntax", "decimal.ConversionSyntax", MPD_Conversion_syntax, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
183 {"DivisionImpossible", "decimal.DivisionImpossible", MPD_Division_impossible, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
184 {"DivisionUndefined", "decimal.DivisionUndefined", MPD_Division_undefined, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
185 {"InvalidContext", "decimal.InvalidContext", MPD_Invalid_context, NULL}, |
|
75923
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
186 #ifdef EXTRA_FUNCTIONALITY |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
187 {"MallocError", "decimal.MallocError", MPD_Malloc_error, NULL}, |
|
75923
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
188 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
189 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
190 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
191 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
192 static const char *dec_signal_string[MPD_NUM_FLAGS] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
193 "Clamped", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
194 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
195 "DivisionByZero", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
196 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
197 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
198 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
199 "Inexact", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
200 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
201 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
202 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
203 "FloatOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
204 "Overflow", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
205 "Rounded", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
206 "Subnormal", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
207 "Underflow", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
208 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
209 |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
210 #ifdef EXTRA_FUNCTIONALITY |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
211 #define _PY_DEC_ROUND_GUARD MPD_ROUND_GUARD |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
212 #else |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
213 #define _PY_DEC_ROUND_GUARD (MPD_ROUND_GUARD-1) |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
214 #endif |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
215 static PyObject *round_map[_PY_DEC_ROUND_GUARD]; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
216 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
217 static const char *invalid_rounding_err = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
218 "valid values for rounding are:\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
219 [ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
220 ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
221 ROUND_05UP]"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
222 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
223 static const char *invalid_signals_err = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
224 "valid values for signals are:\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
225 [InvalidOperation, FloatOperation, DivisionByZero,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
226 Overflow, Underflow, Subnormal, Inexact, Rounded,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
227 Clamped]"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
228 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
229 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
230 static const char *invalid_flags_err = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
231 "valid values for _flags or _traps are:\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
232 signals:\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
233 [DecIEEEInvalidOperation, DecFloatOperation, DecDivisionByZero,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
234 DecOverflow, DecUnderflow, DecSubnormal, DecInexact, DecRounded,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
235 DecClamped]\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
236 conditions which trigger DecIEEEInvalidOperation:\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
237 [DecInvalidOperation, DecConversionSyntax, DecDivisionImpossible,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
238 DecDivisionUndefined, DecFpuError, DecInvalidContext, DecMallocError]"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
239 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
240 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
241 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
242 value_error_int(const char *mesg) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
243 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
244 PyErr_SetString(PyExc_ValueError, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
245 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
246 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
247 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
248 #ifdef CONFIG_32 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
249 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
250 value_error_ptr(const char *mesg) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
251 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
252 PyErr_SetString(PyExc_ValueError, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
253 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
254 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
255 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
256 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
257 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
258 type_error_int(const char *mesg) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
259 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
260 PyErr_SetString(PyExc_TypeError, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
261 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
262 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
263 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
264 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
265 runtime_error_int(const char *mesg) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
266 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
267 PyErr_SetString(PyExc_RuntimeError, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
268 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
269 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
270 #define INTERNAL_ERROR_INT(funcname) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
271 return runtime_error_int("internal error in " funcname) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
272 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
273 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
274 runtime_error_ptr(const char *mesg) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
275 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
276 PyErr_SetString(PyExc_RuntimeError, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
277 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
278 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
279 #define INTERNAL_ERROR_PTR(funcname) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
280 return runtime_error_ptr("internal error in " funcname) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
281 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
282 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
283 dec_traphandler(mpd_context_t *ctx UNUSED) /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
284 { /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
285 return; /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
286 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
287 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
288 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
289 flags_as_exception(uint32_t flags) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
290 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
291 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
292 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
293 for (cm = signal_map; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
294 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
295 return cm->ex; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
296 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
297 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
298 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
299 INTERNAL_ERROR_PTR("flags_as_exception"); /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
300 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
301 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
302 Py_LOCAL_INLINE(uint32_t) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
303 exception_as_flag(PyObject *ex) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
304 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
305 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
306 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
307 for (cm = signal_map; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
308 if (cm->ex == ex) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
309 return cm->flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
310 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
311 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
312 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
313 PyErr_SetString(PyExc_KeyError, invalid_signals_err); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
314 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
315 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
316 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
317 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
318 flags_as_list(uint32_t flags) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
319 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
320 PyObject *list; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
321 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
322 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
323 list = PyList_New(0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
324 if (list == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
325 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
326 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
327 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
328 for (cm = cond_map; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
329 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
330 if (PyList_Append(list, cm->ex) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
331 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
332 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
333 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
334 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
335 for (cm = signal_map+1; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
336 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
337 if (PyList_Append(list, cm->ex) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
338 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
339 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
340 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
341 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
342 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
343 return list; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
344 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
345 error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
346 Py_DECREF(list); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
347 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
348 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
349 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
350 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
351 signals_as_list(uint32_t flags) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
352 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
353 PyObject *list; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
354 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
355 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
356 list = PyList_New(0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
357 if (list == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
358 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
359 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
360 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
361 for (cm = signal_map; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
362 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
363 if (PyList_Append(list, cm->ex) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
364 Py_DECREF(list); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
365 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
366 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
367 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
368 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
369 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
370 return list; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
371 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
372 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
373 static uint32_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
374 list_as_flags(PyObject *list) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
375 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
376 PyObject *item; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
377 uint32_t flags, x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
378 Py_ssize_t n, j; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
379 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
380 assert(PyList_Check(list)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
381 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
382 n = PyList_Size(list); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
383 flags = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
384 for (j = 0; j < n; j++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
385 item = PyList_GetItem(list, j); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
386 x = exception_as_flag(item); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
387 if (x & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
388 return x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
389 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
390 flags |= x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
391 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
392 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
393 return flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
394 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
395 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
396 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
397 flags_as_dict(uint32_t flags) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
398 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
399 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
400 PyObject *dict; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
401 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
402 dict = PyDict_New(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
403 if (dict == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
404 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
405 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
406 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
407 for (cm = signal_map; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
408 PyObject *b = flags&cm->flag ? Py_True : Py_False; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
409 if (PyDict_SetItem(dict, cm->ex, b) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
410 Py_DECREF(dict); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
411 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
412 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
413 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
414 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
415 return dict; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
416 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
417 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
418 static uint32_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
419 dict_as_flags(PyObject *val) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
420 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
421 PyObject *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
422 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
423 uint32_t flags = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
424 int x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
425 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
426 if (!PyDict_Check(val)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
427 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
428 "argument must be a signal dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
429 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
430 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
431 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
432 if (PyDict_Size(val) != SIGNAL_MAP_LEN) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
433 PyErr_SetString(PyExc_KeyError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
434 "invalid signal dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
435 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
436 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
437 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
438 for (cm = signal_map; cm->name != NULL; cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
439 b = PyDict_GetItemWithError(val, cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
440 if (b == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
441 if (PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
442 return DEC_ERR_OCCURRED; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
443 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
444 PyErr_SetString(PyExc_KeyError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
445 "invalid signal dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
446 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
447 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
448 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
449 x = PyObject_IsTrue(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
450 if (x < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
451 return DEC_ERR_OCCURRED; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
452 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
453 if (x == 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
454 flags |= cm->flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
455 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
456 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
457 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
458 return flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
459 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
460 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
461 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
462 static uint32_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
463 long_as_flags(PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
464 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
465 long x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
466 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
467 x = PyLong_AsLong(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
468 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
469 return DEC_ERR_OCCURRED; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
470 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
471 if (x < 0 || x > (long)MPD_Max_status) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
472 PyErr_SetString(PyExc_TypeError, invalid_flags_err); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
473 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
474 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
475 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
476 return x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
477 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
478 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
479 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
480 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
481 dec_addstatus(PyObject *context, uint32_t status) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
482 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
483 mpd_context_t *ctx = CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
484 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
485 ctx->status |= status; |
|
75923
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
486 if (status & (ctx->traps|MPD_Malloc_error)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
487 PyObject *ex, *siglist; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
488 |
|
75923
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
489 if (status & MPD_Malloc_error) { |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
490 PyErr_NoMemory(); |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
491 return 1; |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
492 } |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
493 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
494 ex = flags_as_exception(ctx->traps&status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
495 if (ex == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
496 return 1; /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
497 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
498 siglist = flags_as_list(ctx->traps&status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
499 if (siglist == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
500 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
501 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
502 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
503 PyErr_SetObject(ex, siglist); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
504 Py_DECREF(siglist); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
505 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
506 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
507 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
508 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
509 |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
510 static int |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
511 getround(PyObject *v) |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
512 { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
513 int i; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
514 |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
515 if (PyUnicode_Check(v)) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
516 for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
517 if (v == round_map[i]) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
518 return i; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
519 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
520 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
521 for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
522 if (PyUnicode_Compare(v, round_map[i]) == 0) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
523 return i; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
524 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
525 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
526 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
527 |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
528 return type_error_int(invalid_rounding_err); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
529 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
530 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
531 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
532 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
533 /* SignalDict Object */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
534 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
535 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
536 /* The SignalDict is a MutableMapping that provides access to the |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
537 mpd_context_t flags, which reside in the context object. When a |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
538 new context is created, context.traps and context.flags are |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
539 initialized to new SignalDicts. Once a SignalDict is tied to |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
540 a context, it cannot be deleted. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
541 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
542 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
543 signaldict_init(PyObject *self, PyObject *args UNUSED, PyObject *kwds UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
544 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
545 SdFlagAddr(self) = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
546 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
547 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
548 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
549 static Py_ssize_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
550 signaldict_len(PyObject *self UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
551 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
552 return SIGNAL_MAP_LEN; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
553 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
554 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
555 static PyObject *SignalTuple; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
556 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
557 signaldict_iter(PyObject *self UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
558 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
559 return PyTuple_Type.tp_iter(SignalTuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
560 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
561 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
562 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
563 signaldict_getitem(PyObject *self, PyObject *key) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
564 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
565 uint32_t flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
566 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
567 flag = exception_as_flag(key); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
568 if (flag & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
569 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
570 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
571 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
572 return SdFlags(self)&flag ? incr_true() : incr_false(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
573 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
574 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
575 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
576 signaldict_setitem(PyObject *self, PyObject *key, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
577 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
578 uint32_t flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
579 int x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
580 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
581 if (value == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
582 return value_error_int("signal keys cannot be deleted"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
583 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
584 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
585 flag = exception_as_flag(key); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
586 if (flag & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
587 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
588 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
589 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
590 x = PyObject_IsTrue(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
591 if (x < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
592 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
593 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
594 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
595 if (x == 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
596 SdFlags(self) |= flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
597 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
598 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
599 SdFlags(self) &= ~flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
600 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
601 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
602 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
603 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
604 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
605 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
606 signaldict_repr(PyObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
607 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
608 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
609 const char *n[SIGNAL_MAP_LEN]; /* name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
610 const char *b[SIGNAL_MAP_LEN]; /* bool */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
611 int i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
612 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
613 assert(SIGNAL_MAP_LEN == 9); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
614 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
615 for (cm=signal_map, i=0; cm->name != NULL; cm++, i++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
616 n[i] = cm->fqname; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
617 b[i] = SdFlags(self)&cm->flag ? "True" : "False"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
618 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
619 return PyUnicode_FromFormat( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
620 "{<class '%s'>:%s, <class '%s'>:%s, <class '%s'>:%s, " |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
621 "<class '%s'>:%s, <class '%s'>:%s, <class '%s'>:%s, " |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
622 "<class '%s'>:%s, <class '%s'>:%s, <class '%s'>:%s}", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
623 n[0], b[0], n[1], b[1], n[2], b[2], |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
624 n[3], b[3], n[4], b[4], n[5], b[5], |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
625 n[6], b[6], n[7], b[7], n[8], b[8]); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
626 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
627 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
628 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
629 signaldict_richcompare(PyObject *v, PyObject *w, int op) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
630 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
631 PyObject *res = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
632 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
633 assert(PyDecSignalDict_Check(v)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
634 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
635 if (op == Py_EQ || op == Py_NE) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
636 if (PyDecSignalDict_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
637 res = (SdFlags(v)==SdFlags(w)) ^ (op==Py_NE) ? Py_True : Py_False; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
638 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
639 else if (PyDict_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
640 uint32_t flags = dict_as_flags(w); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
641 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
642 if (flags & DEC_INVALID_SIGNALS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
643 /* non-comparable: Py_NotImplemented */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
644 PyErr_Clear(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
645 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
646 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
647 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
648 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
649 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
650 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
651 res = (SdFlags(v)==flags) ^ (op==Py_NE) ? Py_True : Py_False; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
652 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
653 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
654 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
655 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
656 Py_INCREF(res); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
657 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
658 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
659 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
660 static PyObject * |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
661 signaldict_copy(PyObject *self, PyObject *args UNUSED) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
662 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
663 return flags_as_dict(SdFlags(self)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
664 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
665 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
666 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
667 static PyMappingMethods signaldict_as_mapping = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
668 (lenfunc)signaldict_len, /* mp_length */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
669 (binaryfunc)signaldict_getitem, /* mp_subscript */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
670 (objobjargproc)signaldict_setitem /* mp_ass_subscript */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
671 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
672 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
673 static PyMethodDef signaldict_methods[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
674 { "copy", (PyCFunction)signaldict_copy, METH_NOARGS, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
675 {NULL, NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
676 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
677 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
678 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
679 static PyTypeObject PyDecSignalDictMixin_Type = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
680 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
681 PyVarObject_HEAD_INIT(0, 0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
682 "decimal.SignalDictMixin", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
683 sizeof(PyDecSignalDictObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
684 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
685 0, /* tp_dealloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
686 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
687 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
688 (setattrfunc) 0, /* tp_setattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
689 0, /* tp_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
690 (reprfunc) signaldict_repr, /* tp_repr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
691 0, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
692 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
693 &signaldict_as_mapping, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
694 PyObject_HashNotImplemented, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
695 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
696 (reprfunc) 0, /* tp_str */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
697 PyObject_GenericGetAttr, /* tp_getattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
698 (setattrofunc) 0, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
699 (PyBufferProcs *) 0, /* tp_as_buffer */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
700 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE| |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
701 Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
702 0, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
703 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
704 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
705 signaldict_richcompare, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
706 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
707 (getiterfunc)signaldict_iter, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
708 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
709 signaldict_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
710 0, /* tp_members */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
711 0, /* tp_getset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
712 0, /* tp_base */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
713 0, /* tp_dict */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
714 0, /* tp_descr_get */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
715 0, /* tp_descr_set */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
716 0, /* tp_dictoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
717 (initproc)signaldict_init, /* tp_init */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
718 0, /* tp_alloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
719 PyType_GenericNew, /* tp_new */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
720 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
721 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
722 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
723 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
724 /* Context Object, Part 1 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
725 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
726 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
727 #define Dec_CONTEXT_GET_SSIZE(mem) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
728 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
729 context_get##mem(PyObject *self, void *closure UNUSED) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
730 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
731 return PyLong_FromSsize_t(mpd_get##mem(CTX(self))); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
732 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
733 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
734 #define Dec_CONTEXT_GET_ULONG(mem) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
735 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
736 context_get##mem(PyObject *self, void *closure UNUSED) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
737 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
738 return PyLong_FromUnsignedLong(mpd_get##mem(CTX(self))); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
739 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
740 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
741 Dec_CONTEXT_GET_SSIZE(prec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
742 Dec_CONTEXT_GET_SSIZE(emax) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
743 Dec_CONTEXT_GET_SSIZE(emin) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
744 Dec_CONTEXT_GET_SSIZE(clamp) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
745 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
746 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
747 Dec_CONTEXT_GET_ULONG(traps) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
748 Dec_CONTEXT_GET_ULONG(status) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
749 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
750 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
751 static PyObject * |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
752 context_getround(PyObject *self, void *closure UNUSED) |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
753 { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
754 int i = mpd_getround(CTX(self)); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
755 |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
756 Py_INCREF(round_map[i]); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
757 return round_map[i]; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
758 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
759 |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
760 static PyObject * |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
761 context_getcapitals(PyObject *self, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
762 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
763 return PyLong_FromLong(CtxCaps(self)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
764 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
765 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
766 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
767 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
768 context_getallcr(PyObject *self, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
769 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
770 return PyLong_FromLong(mpd_getcr(CTX(self))); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
771 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
772 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
773 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
774 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
775 context_getetiny(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
776 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
777 return PyLong_FromSsize_t(mpd_etiny(CTX(self))); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
778 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
779 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
780 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
781 context_getetop(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
782 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
783 return PyLong_FromSsize_t(mpd_etop(CTX(self))); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
784 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
785 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
786 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
787 context_setprec(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
788 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
789 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
790 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
791 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
792 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
793 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
794 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
795 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
796 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
797 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
798 if (!mpd_qsetprec(ctx, x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
799 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
800 "valid range for prec is [1, MAX_PREC]"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
801 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
802 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
803 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
804 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
805 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
806 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
807 context_setemin(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
808 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
809 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
810 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
811 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
812 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
813 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
814 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
815 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
816 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
817 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
818 if (!mpd_qsetemin(ctx, x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
819 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
820 "valid range for Emin is [MIN_EMIN, 0]"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
821 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
822 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
823 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
824 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
825 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
826 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
827 context_setemax(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
828 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
829 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
830 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
831 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
832 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
833 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
834 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
835 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
836 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
837 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
838 if (!mpd_qsetemax(ctx, x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
839 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
840 "valid range for Emax is [0, MAX_EMAX]"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
841 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
842 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
843 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
844 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
845 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
846 #ifdef CONFIG_32 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
847 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
848 context_unsafe_setprec(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
849 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
850 mpd_context_t *ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
851 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
852 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
853 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
854 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
855 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
856 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
857 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
858 if (x < 1 || x > 1070000000L) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
859 return value_error_ptr( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
860 "valid range for unsafe prec is [1, 1070000000]"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
861 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
862 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
863 ctx->prec = x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
864 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
865 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
866 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
867 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
868 context_unsafe_setemin(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
869 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
870 mpd_context_t *ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
871 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
872 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
873 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
874 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
875 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
876 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
877 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
878 if (x < -1070000000L || x > 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
879 return value_error_ptr( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
880 "valid range for unsafe emin is [-1070000000, 0]"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
881 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
882 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
883 ctx->emin = x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
884 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
885 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
886 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
887 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
888 context_unsafe_setemax(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
889 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
890 mpd_context_t *ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
891 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
892 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
893 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
894 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
895 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
896 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
897 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
898 if (x < 0 || x > 1070000000L) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
899 return value_error_ptr( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
900 "valid range for unsafe emax is [0, 1070000000]"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
901 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
902 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
903 ctx->emax = x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
904 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
905 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
906 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
907 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
908 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
909 context_setround(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
910 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
911 mpd_context_t *ctx; |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
912 int x; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
913 |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
914 x = getround(value); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
915 if (x == -1) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
916 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
917 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
918 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
919 ctx = CTX(self); |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
920 if (!mpd_qsetround(ctx, x)) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
921 INTERNAL_ERROR_INT("context_setround"); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
922 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
923 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
924 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
925 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
926 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
927 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
928 context_setcapitals(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
929 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
930 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
931 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
932 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
933 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
934 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
935 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
936 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
937 if (x != 0 && x != 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
938 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
939 "valid values for capitals are 0 or 1"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
940 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
941 CtxCaps(self) = (int)x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
942 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
943 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
944 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
945 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
946 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
947 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
948 context_settraps(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
949 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
950 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
951 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
952 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
953 flags = long_as_flags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
954 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
955 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
956 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
957 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
958 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
959 if (!mpd_qsettraps(ctx, flags)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
960 INTERNAL_ERROR_INT("context_settraps"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
961 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
962 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
963 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
964 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
965 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
966 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
967 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
968 context_settraps_list(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
969 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
970 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
971 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
972 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
973 flags = list_as_flags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
974 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
975 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
976 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
977 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
978 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
979 if (!mpd_qsettraps(ctx, flags)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
980 INTERNAL_ERROR_INT("context_settraps_list"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
981 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
982 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
983 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
984 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
985 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
986 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
987 context_settraps_dict(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
988 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
989 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
990 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
991 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
992 if (PyDecSignalDict_Check(value)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
993 flags = SdFlags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
994 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
995 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
996 flags = dict_as_flags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
997 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
998 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
999 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1000 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1001 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1002 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1003 if (!mpd_qsettraps(ctx, flags)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1004 INTERNAL_ERROR_INT("context_settraps_dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1005 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1006 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1007 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1008 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1009 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1010 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1011 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1012 context_setstatus(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1013 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1014 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1015 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1016 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1017 flags = long_as_flags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1018 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1019 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1020 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1021 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1022 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1023 if (!mpd_qsetstatus(ctx, flags)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1024 INTERNAL_ERROR_INT("context_setstatus"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1025 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1026 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1027 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1028 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1029 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1030 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1031 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1032 context_setstatus_list(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1033 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1034 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1035 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1036 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1037 flags = list_as_flags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1038 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1039 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1040 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1041 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1042 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1043 if (!mpd_qsetstatus(ctx, flags)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1044 INTERNAL_ERROR_INT("context_setstatus_list"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1045 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1046 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1047 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1048 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1049 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1050 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1051 context_setstatus_dict(PyObject *self, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1052 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1053 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1054 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1055 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1056 if (PyDecSignalDict_Check(value)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1057 flags = SdFlags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1058 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1059 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1060 flags = dict_as_flags(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1061 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1062 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1063 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1064 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1065 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1066 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1067 if (!mpd_qsetstatus(ctx, flags)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1068 INTERNAL_ERROR_INT("context_setstatus_dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1069 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1070 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1071 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1072 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1073 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1074 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1075 context_setclamp(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1076 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1077 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1078 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1079 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1080 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1081 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1082 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1083 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1084 BOUNDS_CHECK(x, INT_MIN, INT_MAX); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1085 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1086 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1087 if (!mpd_qsetclamp(ctx, (int)x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1088 return value_error_int("valid values for clamp are 0 or 1"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1089 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1090 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1091 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1092 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1093 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1094 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1095 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1096 context_setallcr(PyObject *self, PyObject *value, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1097 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1098 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1099 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1100 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1101 x = PyLong_AsSsize_t(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1102 if (x == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1103 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1104 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1105 BOUNDS_CHECK(x, INT_MIN, INT_MAX); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1106 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1107 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1108 if (!mpd_qsetcr(ctx, (int)x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1109 return value_error_int("valid values for _allcr are 0 or 1"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1110 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1111 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1112 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1113 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1114 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1115 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1116 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1117 context_getattr(PyObject *self, PyObject *name) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1118 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1119 PyObject *retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1120 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1121 if (PyUnicode_Check(name)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1122 if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1123 retval = ((PyDecContextObject *)self)->traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1124 Py_INCREF(retval); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1125 return retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1126 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1127 if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1128 retval = ((PyDecContextObject *)self)->flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1129 Py_INCREF(retval); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1130 return retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1131 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1132 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1133 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1134 return PyObject_GenericGetAttr(self, name); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1135 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1136 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1137 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1138 context_setattr(PyObject *self, PyObject *name, PyObject *value) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1139 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1140 if (value == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1141 PyErr_SetString(PyExc_AttributeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1142 "context attributes cannot be deleted"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1143 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1144 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1145 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1146 if (PyUnicode_Check(name)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1147 if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1148 return context_settraps_dict(self, value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1149 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1150 if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1151 return context_setstatus_dict(self, value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1152 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1153 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1154 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1155 return PyObject_GenericSetAttr(self, name, value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1156 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1157 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1158 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1159 context_clear_traps(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1160 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1161 CTX(self)->traps = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1162 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1163 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1164 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1165 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1166 context_clear_flags(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1167 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1168 CTX(self)->status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1169 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1170 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1171 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1172 #define DEC_DFLT_EMAX 999999 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1173 #define DEC_DFLT_EMIN -999999 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1174 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1175 static mpd_context_t dflt_ctx = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1176 28, DEC_DFLT_EMAX, DEC_DFLT_EMIN, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1177 MPD_IEEE_Invalid_operation|MPD_Division_by_zero|MPD_Overflow, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1178 0, 0, MPD_ROUND_HALF_EVEN, 0, 1 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1179 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1180 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1181 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1182 context_new(PyTypeObject *type, PyObject *args UNUSED, PyObject *kwds UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1183 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1184 PyDecContextObject *self = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1185 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1186 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1187 if (type == &PyDecContext_Type) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1188 self = PyObject_New(PyDecContextObject, &PyDecContext_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1189 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1190 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1191 self = (PyDecContextObject *)type->tp_alloc(type, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1192 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1193 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1194 if (self == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1195 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1196 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1197 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1198 self->traps = PyObject_CallObject((PyObject *)PyDecSignalDict_Type, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1199 if (self->traps == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1200 self->flags = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1201 Py_DECREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1202 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1203 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1204 self->flags = PyObject_CallObject((PyObject *)PyDecSignalDict_Type, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1205 if (self->flags == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1206 Py_DECREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1207 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1208 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1209 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1210 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1211 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1212 if (default_context_template) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1213 *ctx = *CTX(default_context_template); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1214 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1215 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1216 *ctx = dflt_ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1217 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1218 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1219 SdFlagAddr(self->traps) = &ctx->traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1220 SdFlagAddr(self->flags) = &ctx->status; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1221 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1222 CtxCaps(self) = 1; |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1223 #ifndef WITHOUT_THREADS |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1224 self->tstate = NULL; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1225 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1226 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1227 return (PyObject *)self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1228 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1229 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1230 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1231 context_dealloc(PyDecContextObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1232 { |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1233 #ifndef WITHOUT_THREADS |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1234 if (self == cached_context) { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1235 cached_context = NULL; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1236 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1237 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1238 Py_XDECREF(self->traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1239 Py_XDECREF(self->flags); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1240 Py_TYPE(self)->tp_free(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1241 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1242 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1243 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1244 context_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1245 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1246 static char *kwlist[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1247 "prec", "rounding", "Emin", "Emax", "capitals", "clamp", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1248 "flags", "traps", NULL |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1249 }; |
|
80891
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1250 PyObject *prec = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1251 PyObject *rounding = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1252 PyObject *emin = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1253 PyObject *emax = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1254 PyObject *capitals = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1255 PyObject *clamp = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1256 PyObject *status = Py_None; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1257 PyObject *traps = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1258 int ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1259 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1260 assert(PyTuple_Check(args)); |
|
80891
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1261 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1262 if (!PyArg_ParseTupleAndKeywords( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1263 args, kwds, |
|
80891
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1264 "|OOOOOOOO", kwlist, |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1265 &prec, &rounding, &emin, &emax, &capitals, &clamp, &status, &traps |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1266 )) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1267 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1268 } |
|
80891
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1269 |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1270 if (prec != Py_None && context_setprec(self, prec, NULL) < 0) { |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1271 return -1; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1272 } |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
1273 if (rounding != Py_None && context_setround(self, rounding, NULL) < 0) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
1274 return -1; |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
1275 } |
|
80891
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1276 if (emin != Py_None && context_setemin(self, emin, NULL) < 0) { |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1277 return -1; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1278 } |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1279 if (emax != Py_None && context_setemax(self, emax, NULL) < 0) { |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1280 return -1; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1281 } |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1282 if (capitals != Py_None && context_setcapitals(self, capitals, NULL) < 0) { |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1283 return -1; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1284 } |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1285 if (clamp != Py_None && context_setclamp(self, clamp, NULL) < 0) { |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1286 return -1; |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1287 } |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1288 |
|
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1289 if (traps != Py_None) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1290 if (PyList_Check(traps)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1291 ret = context_settraps_list(self, traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1292 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1293 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1294 else if (PyLong_Check(traps)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1295 ret = context_settraps(self, traps, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1296 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1297 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1298 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1299 ret = context_settraps_dict(self, traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1300 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1301 if (ret < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1302 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1303 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1304 } |
|
80891
907d71668d3c
Issue #15783: Support None default values in the Context() constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80872
diff
changeset
|
1305 if (status != Py_None) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1306 if (PyList_Check(status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1307 ret = context_setstatus_list(self, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1308 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1309 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1310 else if (PyLong_Check(status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1311 ret = context_setstatus(self, status, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1312 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1313 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1314 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1315 ret = context_setstatus_dict(self, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1316 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1317 if (ret < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1318 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1319 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1320 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1321 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1322 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1323 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1324 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1325 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1326 context_repr(PyDecContextObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1327 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1328 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1329 char flags[MPD_MAX_SIGNAL_LIST]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1330 char traps[MPD_MAX_SIGNAL_LIST]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1331 int n, mem; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1332 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1333 assert(PyDecContext_Check(self)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1334 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1335 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1336 mem = MPD_MAX_SIGNAL_LIST; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1337 n = mpd_lsnprint_signals(flags, mem, ctx->status, dec_signal_string); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1338 if (n < 0 || n >= mem) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1339 INTERNAL_ERROR_PTR("context_repr"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1340 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1341 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1342 n = mpd_lsnprint_signals(traps, mem, ctx->traps, dec_signal_string); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1343 if (n < 0 || n >= mem) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1344 INTERNAL_ERROR_PTR("context_repr"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1345 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1346 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1347 return PyUnicode_FromFormat( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1348 "Context(prec=%zd, rounding=%s, Emin=%zd, Emax=%zd, " |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1349 "capitals=%d, clamp=%d, flags=%s, traps=%s)", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1350 ctx->prec, mpd_round_string[ctx->round], ctx->emin, ctx->emax, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1351 self->capitals, ctx->clamp, flags, traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1352 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1353 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1354 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1355 init_basic_context(PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1356 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1357 mpd_context_t ctx = dflt_ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1358 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1359 ctx.prec = 9; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1360 ctx.traps |= (MPD_Underflow|MPD_Clamped); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1361 ctx.round = MPD_ROUND_HALF_UP; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1362 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1363 *CTX(v) = ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1364 CtxCaps(v) = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1365 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1366 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1367 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1368 init_extended_context(PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1369 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1370 mpd_context_t ctx = dflt_ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1371 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1372 ctx.prec = 9; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1373 ctx.traps = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1374 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1375 *CTX(v) = ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1376 CtxCaps(v) = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1377 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1378 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1379 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1380 /* Factory function for creating IEEE interchange format contexts */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1381 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1382 ieee_context(PyObject *dummy UNUSED, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1383 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1384 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1385 mpd_ssize_t bits; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1386 mpd_context_t ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1387 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1388 bits = PyLong_AsSsize_t(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1389 if (bits == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1390 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1391 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1392 if (bits <= 0 || bits > INT_MAX) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1393 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1394 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1395 if (mpd_ieee_context(&ctx, (int)bits) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1396 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1397 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1398 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1399 context = PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1400 if (context == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1401 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1402 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1403 *CTX(context) = ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1404 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1405 return context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1406 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1407 error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1408 PyErr_Format(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1409 "argument must be a multiple of 32, with a maximum of %d", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1410 MPD_IEEE_CONTEXT_MAX_BITS); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1411 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1412 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1413 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1414 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1415 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1416 static PyObject * |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1417 context_copy(PyObject *self, PyObject *args UNUSED) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1418 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1419 PyObject *copy; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1420 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1421 copy = PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1422 if (copy == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1423 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1424 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1425 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1426 *CTX(copy) = *CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1427 CTX(copy)->newtrap = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1428 CtxCaps(copy) = CtxCaps(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1429 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1430 return copy; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1431 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1432 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1433 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1434 context_reduce(PyObject *self, PyObject *args UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1435 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1436 PyObject *flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1437 PyObject *traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1438 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1439 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1440 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1441 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1442 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1443 flags = signals_as_list(ctx->status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1444 if (flags == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1445 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1446 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1447 traps = signals_as_list(ctx->traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1448 if (traps == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1449 Py_DECREF(flags); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1450 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1451 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1452 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1453 ret = Py_BuildValue( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1454 "O(nsnniiOO)", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1455 Py_TYPE(self), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1456 ctx->prec, mpd_round_string[ctx->round], ctx->emin, ctx->emax, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1457 CtxCaps(self), ctx->clamp, flags, traps |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1458 ); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1459 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1460 Py_DECREF(flags); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1461 Py_DECREF(traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1462 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1463 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1464 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1465 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1466 static PyGetSetDef context_getsets [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1467 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1468 { "prec", (getter)context_getprec, (setter)context_setprec, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1469 { "Emax", (getter)context_getemax, (setter)context_setemax, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1470 { "Emin", (getter)context_getemin, (setter)context_setemin, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1471 { "rounding", (getter)context_getround, (setter)context_setround, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1472 { "capitals", (getter)context_getcapitals, (setter)context_setcapitals, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1473 { "clamp", (getter)context_getclamp, (setter)context_setclamp, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1474 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1475 { "_allcr", (getter)context_getallcr, (setter)context_setallcr, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1476 { "_traps", (getter)context_gettraps, (setter)context_settraps, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1477 { "_flags", (getter)context_getstatus, (setter)context_setstatus, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1478 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1479 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1480 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1481 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1482 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1483 #define CONTEXT_CHECK(obj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1484 if (!PyDecContext_Check(obj)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1485 PyErr_SetString(PyExc_TypeError, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1486 "argument must be a context"); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1487 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1488 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1489 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1490 #define CONTEXT_CHECK_VA(obj) \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1491 if (obj == Py_None) { \ |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1492 CURRENT_CONTEXT(obj); \ |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1493 } \ |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1494 else if (!PyDecContext_Check(obj)) { \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1495 PyErr_SetString(PyExc_TypeError, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1496 "optional argument must be a context"); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1497 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1498 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1499 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1500 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1501 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1502 /* Global, thread local and temporary contexts */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1503 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1504 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1505 #ifdef WITHOUT_THREADS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1506 /* Return borrowed reference to the current context. When compiled |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1507 * without threads, this is always the module context. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1508 static int module_context_set = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1509 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1510 current_context(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1511 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1512 /* In decimal.py, the module context is automatically initialized |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1513 * from the DefaultContext when it is first accessed. This |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1514 * complicates the code and has a speed penalty of 1-2%. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1515 if (module_context_set) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1516 return module_context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1517 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1518 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1519 *CTX(module_context) = *CTX(default_context_template); |
|
76063
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1520 CTX(module_context)->status = 0; |
|
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1521 CTX(module_context)->newtrap = 0; |
|
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1522 CtxCaps(module_context) = CtxCaps(default_context_template); |
|
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1523 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1524 module_context_set = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1525 return module_context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1526 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1527 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1528 /* ctxobj := borrowed reference to the current context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1529 #define CURRENT_CONTEXT(ctxobj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1530 ctxobj = current_context() |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1531 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1532 /* ctx := pointer to the mpd_context_t struct of the current context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1533 #define CURRENT_CONTEXT_ADDR(ctx) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1534 ctx = CTX(current_context()) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1535 |
| 76077 | 1536 /* Return a new reference to the current context */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1537 static PyObject * |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1538 PyDec_GetCurrentContext(PyObject *self UNUSED, PyObject *args UNUSED) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1539 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1540 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1541 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1542 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1543 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1544 Py_INCREF(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1545 return context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1546 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1547 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1548 /* Set the module context to a new context, decrement old reference */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1549 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1550 PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1551 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1552 CONTEXT_CHECK(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1553 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1554 /* If the new context is one of the templates, make a copy. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1555 * This is the current behavior of decimal.py. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1556 if (v == default_context_template || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1557 v == basic_context_template || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1558 v == extended_context_template) { |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1559 v = context_copy(v, NULL); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1560 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1561 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1562 } |
|
76063
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1563 CTX(v)->status = 0; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1564 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1565 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1566 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1567 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1568 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1569 Py_XDECREF(module_context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1570 module_context = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1571 module_context_set = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1572 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1573 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1574 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1575 /* |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1576 * Thread local storage currently has a speed penalty of about 4%. |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1577 * All functions that map Python's arithmetic operators to mpdecimal |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1578 * functions have to look up the current context for each and every |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1579 * operation. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1580 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1581 |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1582 /* Get the context from the thread state dictionary. */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1583 static PyObject * |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1584 current_context_from_dict(void) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1585 { |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1586 PyObject *dict; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1587 PyObject *tl_context; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1588 PyThreadState *tstate; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1589 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1590 dict = PyThreadState_GetDict(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1591 if (dict == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1592 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1593 "cannot get thread state"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1594 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1595 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1596 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1597 tl_context = PyDict_GetItemWithError(dict, tls_context_key); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1598 if (tl_context != NULL) { |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1599 /* We already have a thread local context. */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1600 CONTEXT_CHECK(tl_context); |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1601 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1602 else { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1603 if (PyErr_Occurred()) { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1604 return NULL; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1605 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1606 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1607 /* Set up a new thread local context. */ |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1608 tl_context = context_copy(default_context_template, NULL); |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1609 if (tl_context == NULL) { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1610 return NULL; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1611 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1612 CTX(tl_context)->status = 0; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1613 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1614 if (PyDict_SetItem(dict, tls_context_key, tl_context) < 0) { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1615 Py_DECREF(tl_context); |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1616 return NULL; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1617 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1618 Py_DECREF(tl_context); |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1619 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1620 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1621 /* Cache the context of the current thread, assuming that it |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1622 * will be accessed several times before a thread switch. */ |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1623 tstate = PyThreadState_GET(); |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1624 if (tstate) { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1625 cached_context = (PyDecContextObject *)tl_context; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1626 cached_context->tstate = tstate; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1627 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1628 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1629 /* Borrowed reference with refcount==1 */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1630 return tl_context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1631 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1632 |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1633 /* Return borrowed reference to thread local context. */ |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1634 static PyObject * |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1635 current_context(void) |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1636 { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1637 PyThreadState *tstate; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1638 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1639 tstate = PyThreadState_GET(); |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1640 if (cached_context && cached_context->tstate == tstate) { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1641 return (PyObject *)cached_context; |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1642 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1643 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1644 return current_context_from_dict(); |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1645 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1646 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1647 /* ctxobj := borrowed reference to the current context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1648 #define CURRENT_CONTEXT(ctxobj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1649 ctxobj = current_context(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1650 if (ctxobj == NULL) { \ |
| 75862 | 1651 return NULL; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1652 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1653 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1654 /* ctx := pointer to the mpd_context_t struct of the current context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1655 #define CURRENT_CONTEXT_ADDR(ctx) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1656 PyObject *_c_t_x_o_b_j = current_context(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1657 if (_c_t_x_o_b_j == NULL) { \ |
| 75862 | 1658 return NULL; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1659 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1660 ctx = CTX(_c_t_x_o_b_j); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1661 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1662 |
| 76077 | 1663 /* Return a new reference to the current context */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1664 static PyObject * |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1665 PyDec_GetCurrentContext(PyObject *self UNUSED, PyObject *args UNUSED) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1666 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1667 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1668 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1669 context = current_context(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1670 if (context == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1671 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1672 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1673 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1674 Py_INCREF(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1675 return context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1676 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1677 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1678 /* Set the thread local context to a new context, decrement old reference */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1679 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1680 PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1681 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1682 PyObject *dict; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1683 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1684 CONTEXT_CHECK(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1685 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1686 dict = PyThreadState_GetDict(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1687 if (dict == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1688 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1689 "cannot get thread state"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1690 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1691 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1692 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1693 /* If the new context is one of the templates, make a copy. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1694 * This is the current behavior of decimal.py. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1695 if (v == default_context_template || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1696 v == basic_context_template || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1697 v == extended_context_template) { |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1698 v = context_copy(v, NULL); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1699 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1700 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1701 } |
|
76063
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1702 CTX(v)->status = 0; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1703 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1704 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1705 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1706 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1707 |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1708 cached_context = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1709 if (PyDict_SetItem(dict, tls_context_key, v) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1710 Py_DECREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1711 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1712 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1713 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1714 Py_DECREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1715 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1716 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1717 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1718 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1719 /* Context manager object for the 'with' statement. The manager |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1720 * owns one reference to the global (outer) context and one |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1721 * to the local (inner) context. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1722 static PyObject * |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1723 ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kwds) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1724 { |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1725 static char *kwlist[] = {"ctx", NULL}; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1726 PyDecContextManagerObject *self; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1727 PyObject *local = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1728 PyObject *global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1729 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1730 CURRENT_CONTEXT(global); |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1731 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &local)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1732 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1733 } |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1734 if (local == Py_None) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1735 local = global; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1736 } |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1737 else if (!PyDecContext_Check(local)) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1738 PyErr_SetString(PyExc_TypeError, |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1739 "optional argument must be a context"); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1740 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
1741 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1742 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1743 self = PyObject_New(PyDecContextManagerObject, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1744 &PyDecContextManager_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1745 if (self == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1746 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1747 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1748 |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1749 self->local = context_copy(local, NULL); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1750 if (self->local == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1751 self->global = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1752 Py_DECREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1753 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1754 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1755 self->global = global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1756 Py_INCREF(self->global); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1757 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1758 return (PyObject *)self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1759 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1760 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1761 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1762 ctxmanager_dealloc(PyDecContextManagerObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1763 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1764 Py_XDECREF(self->local); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1765 Py_XDECREF(self->global); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1766 PyObject_Del(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1767 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1768 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1769 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1770 ctxmanager_set_local(PyDecContextManagerObject *self, PyObject *args UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1771 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1772 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1773 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1774 ret = PyDec_SetCurrentContext(NULL, self->local); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1775 if (ret == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1776 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1777 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1778 Py_DECREF(ret); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1779 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1780 Py_INCREF(self->local); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1781 return self->local; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1782 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1783 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1784 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1785 ctxmanager_restore_global(PyDecContextManagerObject *self, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1786 PyObject *args UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1787 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1788 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1789 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1790 ret = PyDec_SetCurrentContext(NULL, self->global); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1791 if (ret == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1792 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1793 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1794 Py_DECREF(ret); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1795 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1796 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1797 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1798 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1799 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1800 static PyMethodDef ctxmanager_methods[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1801 {"__enter__", (PyCFunction)ctxmanager_set_local, METH_NOARGS, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1802 {"__exit__", (PyCFunction)ctxmanager_restore_global, METH_VARARGS, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1803 {NULL, NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1804 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1805 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1806 static PyTypeObject PyDecContextManager_Type = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1807 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1808 PyVarObject_HEAD_INIT(NULL, 0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1809 "decimal.ContextManager", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1810 sizeof(PyDecContextManagerObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1811 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1812 (destructor) ctxmanager_dealloc, /* tp_dealloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1813 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1814 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1815 (setattrfunc) 0, /* tp_setattr */ |
| 76077 | 1816 0, /* tp_reserved */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1817 (reprfunc) 0, /* tp_repr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1818 0, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1819 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1820 0, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1821 0, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1822 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1823 0, /* tp_str */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1824 (getattrofunc) PyObject_GenericGetAttr, /* tp_getattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1825 (setattrofunc) 0, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1826 (PyBufferProcs *) 0, /* tp_as_buffer */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1827 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1828 0, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1829 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1830 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1831 0, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1832 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1833 0, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1834 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1835 ctxmanager_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1836 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1837 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1838 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1839 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1840 /* New Decimal Object */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1841 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1842 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1843 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1844 PyDecType_New(PyTypeObject *type) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1845 { |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1846 PyDecObject *dec; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1847 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1848 if (type == &PyDec_Type) { |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1849 dec = PyObject_New(PyDecObject, &PyDec_Type); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1850 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1851 else { |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1852 dec = (PyDecObject *)type->tp_alloc(type, 0); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1853 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1854 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1855 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1856 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1857 |
|
76206
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
1858 dec->hash = -1; |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
1859 |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1860 MPD(dec)->flags = MPD_STATIC|MPD_STATIC_DATA; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1861 MPD(dec)->exp = 0; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1862 MPD(dec)->digits = 0; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1863 MPD(dec)->len = 0; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1864 MPD(dec)->alloc = _Py_DEC_MINALLOC; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1865 MPD(dec)->data = dec->data; |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1866 |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1867 return (PyObject *)dec; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1868 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1869 #define dec_alloc() PyDecType_New(&PyDec_Type) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1870 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1871 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1872 dec_dealloc(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1873 { |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1874 mpd_del(MPD(dec)); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1875 Py_TYPE(dec)->tp_free(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1876 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1877 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1878 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1879 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1880 /* Conversions to Decimal */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1881 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1882 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1883 Py_LOCAL_INLINE(int) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1884 is_space(enum PyUnicode_Kind kind, void *data, Py_ssize_t pos) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1885 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1886 Py_UCS4 ch = PyUnicode_READ(kind, data, pos); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1887 return Py_UNICODE_ISSPACE(ch); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1888 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1889 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1890 /* Return the ASCII representation of a numeric Unicode string. The numeric |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1891 string may contain ascii characters in the range [1, 127], any Unicode |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1892 space and any unicode digit. If strip_ws is true, leading and trailing |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1893 whitespace is stripped. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1894 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1895 Return NULL if malloc fails and an empty string if invalid characters |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1896 are found. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1897 static char * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1898 numeric_as_ascii(const PyObject *u, int strip_ws) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1899 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1900 enum PyUnicode_Kind kind; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1901 void *data; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1902 Py_UCS4 ch; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1903 char *res, *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1904 Py_ssize_t j, len; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1905 int d; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1906 |
|
80342
2f35cdd1497b
Accept Unicode legacy strings in the Decimal constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80311
diff
changeset
|
1907 if (PyUnicode_READY(u) == -1) { |
|
2f35cdd1497b
Accept Unicode legacy strings in the Decimal constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80311
diff
changeset
|
1908 return NULL; |
|
2f35cdd1497b
Accept Unicode legacy strings in the Decimal constructor.
Stefan Krah <skrah@bytereef.org>
parents:
80311
diff
changeset
|
1909 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1910 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1911 kind = PyUnicode_KIND(u); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1912 data = PyUnicode_DATA(u); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1913 len = PyUnicode_GET_LENGTH(u); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1914 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1915 cp = res = PyMem_Malloc(len+1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1916 if (res == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1917 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1918 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1919 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1920 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1921 j = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1922 if (strip_ws) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1923 while (len > 0 && is_space(kind, data, len-1)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1924 len--; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1925 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1926 while (j < len && is_space(kind, data, j)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1927 j++; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1928 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1929 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1930 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1931 for (; j < len; j++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1932 ch = PyUnicode_READ(kind, data, j); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1933 if (0 < ch && ch <= 127) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1934 *cp++ = ch; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1935 continue; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1936 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1937 if (Py_UNICODE_ISSPACE(ch)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1938 *cp++ = ' '; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1939 continue; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1940 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1941 d = Py_UNICODE_TODECIMAL(ch); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1942 if (d < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1943 /* empty string triggers ConversionSyntax */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1944 *res = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1945 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1946 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1947 *cp++ = '0' + d; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1948 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1949 *cp = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1950 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1951 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1952 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1953 /* Return a new PyDecObject or a subtype from a C string. Use the context |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1954 during conversion. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1955 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1956 PyDecType_FromCString(PyTypeObject *type, const char *s, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1957 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1958 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1959 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1960 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1961 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1962 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1963 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1964 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1965 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1966 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1967 mpd_qset_string(MPD(dec), s, CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1968 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1969 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1970 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1971 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1972 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1973 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1974 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1975 /* Return a new PyDecObject or a subtype from a C string. Attempt exact |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1976 conversion. If the operand cannot be converted exactly, set |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1977 InvalidOperation. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1978 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1979 PyDecType_FromCStringExact(PyTypeObject *type, const char *s, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1980 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1981 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1982 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1983 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1984 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1985 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1986 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1987 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1988 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1989 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1990 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1991 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1992 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1993 mpd_qset_string(MPD(dec), s, &maxctx, &status); |
|
76120
0f9d79998c79
Raise InvalidOperation if exponents of zeros are clamped during exact
Stefan Krah <skrah@bytereef.org>
parents:
76077
diff
changeset
|
1994 if (status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1995 /* we want exact results */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1996 mpd_seterror(MPD(dec), MPD_Invalid_operation, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1997 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1998 status &= MPD_Errors; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1999 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2000 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2001 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2002 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2003 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2004 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2005 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2006 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2007 /* Return a new PyDecObject or a subtype from a PyUnicodeObject. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2008 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2009 PyDecType_FromUnicode(PyTypeObject *type, const PyObject *u, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2010 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2011 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2012 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2013 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2014 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2015 s = numeric_as_ascii(u, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2016 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2017 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2018 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2019 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2020 dec = PyDecType_FromCString(type, s, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2021 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2022 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2023 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2024 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2025 /* Return a new PyDecObject or a subtype from a PyUnicodeObject. Attempt exact |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2026 * conversion. If the conversion is not exact, fail with InvalidOperation. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2027 * Allow leading and trailing whitespace in the input operand. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2028 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2029 PyDecType_FromUnicodeExactWS(PyTypeObject *type, const PyObject *u, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2030 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2031 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2032 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2033 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2034 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2035 s = numeric_as_ascii(u, 1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2036 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2037 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2038 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2039 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2040 dec = PyDecType_FromCStringExact(type, s, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2041 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2042 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2043 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2044 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2045 /* Set PyDecObject from triple without any error checking. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2046 Py_LOCAL_INLINE(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2047 _dec_settriple(PyObject *dec, uint8_t sign, uint32_t v, mpd_ssize_t exp) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2048 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2049 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2050 #ifdef CONFIG_64 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2051 MPD(dec)->data[0] = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2052 MPD(dec)->len = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2053 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2054 uint32_t q, r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2055 q = v / MPD_RADIX; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2056 r = v - q * MPD_RADIX; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2057 MPD(dec)->data[1] = q; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2058 MPD(dec)->data[0] = r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2059 MPD(dec)->len = q ? 2 : 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2060 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2061 mpd_set_flags(MPD(dec), sign); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2062 MPD(dec)->exp = exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2063 mpd_setdigits(MPD(dec)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2064 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2065 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2066 /* Return a new PyDecObject from an mpd_ssize_t. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2067 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2068 PyDecType_FromSsize(PyTypeObject *type, mpd_ssize_t v, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2069 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2070 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2071 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2072 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2073 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2074 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2075 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2076 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2077 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2078 mpd_qset_ssize(MPD(dec), v, CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2079 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2080 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2081 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2082 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2083 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2084 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2085 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2086 /* Return a new PyDecObject from an mpd_ssize_t. Conversion is exact. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2087 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2088 PyDecType_FromSsizeExact(PyTypeObject *type, mpd_ssize_t v, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2089 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2090 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2091 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2092 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2093 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2094 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2095 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2096 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2097 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2098 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2099 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2100 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2101 mpd_qset_ssize(MPD(dec), v, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2102 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2103 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2104 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2105 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2106 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2107 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2108 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2109 /* Convert from a PyLongObject. The context is not modified; flags set |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2110 during conversion are accumulated in the status parameter. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2111 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2112 dec_from_long(PyTypeObject *type, const PyObject *v, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2113 const mpd_context_t *ctx, uint32_t *status) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2114 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2115 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2116 PyLongObject *l = (PyLongObject *)v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2117 Py_ssize_t ob_size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2118 size_t len; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2119 uint8_t sign; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2120 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2121 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2122 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2123 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2124 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2125 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2126 ob_size = Py_SIZE(l); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2127 if (ob_size == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2128 _dec_settriple(dec, MPD_POS, 0, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2129 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2130 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2131 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2132 if (ob_size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2133 len = -ob_size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2134 sign = MPD_NEG; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2135 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2136 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2137 len = ob_size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2138 sign = MPD_POS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2139 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2140 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2141 if (len == 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2142 _dec_settriple(dec, sign, *l->ob_digit, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2143 mpd_qfinalize(MPD(dec), ctx, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2144 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2145 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2146 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2147 #if PYLONG_BITS_IN_DIGIT == 30 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2148 mpd_qimport_u32(MPD(dec), l->ob_digit, len, sign, PyLong_BASE, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2149 ctx, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2150 #elif PYLONG_BITS_IN_DIGIT == 15 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2151 mpd_qimport_u16(MPD(dec), l->ob_digit, len, sign, PyLong_BASE, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2152 ctx, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2153 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2154 #error "PYLONG_BITS_IN_DIGIT should be 15 or 30" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2155 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2156 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2157 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2158 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2159 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2160 /* Return a new PyDecObject from a PyLongObject. Use the context for |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2161 conversion. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2162 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2163 PyDecType_FromLong(PyTypeObject *type, const PyObject *pylong, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2164 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2165 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2166 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2167 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2168 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2169 dec = dec_from_long(type, pylong, CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2170 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2171 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2172 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2173 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2174 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2175 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2176 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2177 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2178 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2179 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2180 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2181 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2182 /* Return a new PyDecObject from a PyLongObject. Use a maximum context |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2183 for conversion. If the conversion is not exact, set InvalidOperation. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2184 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2185 PyDecType_FromLongExact(PyTypeObject *type, const PyObject *pylong, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2186 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2187 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2188 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2189 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2190 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2191 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2192 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2193 dec = dec_from_long(type, pylong, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2194 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2195 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2196 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2197 |
|
76120
0f9d79998c79
Raise InvalidOperation if exponents of zeros are clamped during exact
Stefan Krah <skrah@bytereef.org>
parents:
76077
diff
changeset
|
2198 if (status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2199 /* we want exact results */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2200 mpd_seterror(MPD(dec), MPD_Invalid_operation, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2201 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2202 status &= MPD_Errors; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2203 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2204 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2205 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2206 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2207 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2208 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2209 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2210 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2211 /* Return a PyDecObject or a subtype from a PyFloatObject. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2212 Conversion is exact. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2213 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2214 PyDecType_FromFloatExact(PyTypeObject *type, PyObject *v, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2215 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2216 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2217 PyObject *dec, *tmp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2218 PyObject *n, *d, *n_d; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2219 mpd_ssize_t k; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2220 double x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2221 int sign; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2222 mpd_t *d1, *d2; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2223 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2224 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2225 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2226 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2227 assert(PyType_IsSubtype(type, &PyDec_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2228 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2229 if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2230 return PyDecType_FromLongExact(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2231 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2232 if (!PyFloat_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2233 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2234 "argument must be int of float"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2235 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2236 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2237 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2238 x = PyFloat_AsDouble(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2239 if (x == -1.0 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2240 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2241 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2242 sign = (copysign(1.0, x) == 1.0) ? 0 : 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2243 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2244 if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2245 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2246 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2247 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2248 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2249 if (Py_IS_NAN(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2250 /* decimal.py calls repr(float(+-nan)), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2251 * which always gives a positive result. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2252 mpd_setspecial(MPD(dec), MPD_POS, MPD_NAN); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2253 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2254 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2255 mpd_setspecial(MPD(dec), sign, MPD_INF); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2256 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2257 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2258 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2259 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2260 /* absolute value of the float */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2261 tmp = PyObject_CallMethod(v, "__abs__", NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2262 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2263 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2264 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2265 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2266 /* float as integer ratio: numerator/denominator */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2267 n_d = PyObject_CallMethod(tmp, "as_integer_ratio", NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2268 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2269 if (n_d == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2270 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2271 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2272 n = PyTuple_GET_ITEM(n_d, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2273 d = PyTuple_GET_ITEM(n_d, 1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2274 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2275 tmp = PyObject_CallMethod(d, "bit_length", NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2276 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2277 Py_DECREF(n_d); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2278 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2279 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2280 k = PyLong_AsSsize_t(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2281 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2282 if (k == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2283 Py_DECREF(n_d); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2284 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2285 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2286 k--; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2287 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2288 dec = PyDecType_FromLongExact(type, n, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2289 Py_DECREF(n_d); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2290 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2291 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2292 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2293 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2294 d1 = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2295 if (d1 == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2296 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2297 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2298 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2299 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2300 d2 = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2301 if (d2 == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2302 mpd_del(d1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2303 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2304 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2305 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2306 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2307 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2308 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2309 mpd_qset_uint(d1, 5, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2310 mpd_qset_ssize(d2, k, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2311 mpd_qpow(d1, d1, d2, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2312 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2313 mpd_del(d1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2314 mpd_del(d2); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2315 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2316 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2317 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2318 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2319 /* result = n * 5**k */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2320 mpd_qmul(MPD(dec), MPD(dec), d1, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2321 mpd_del(d1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2322 mpd_del(d2); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2323 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2324 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2325 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2326 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2327 /* result = +- n * 5**k * 10**-k */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2328 mpd_set_sign(MPD(dec), sign); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2329 MPD(dec)->exp = -k; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2330 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2331 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2332 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2333 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2334 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2335 PyDecType_FromFloat(PyTypeObject *type, PyObject *v, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2336 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2337 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2338 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2339 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2340 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2341 dec = PyDecType_FromFloatExact(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2342 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2343 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2344 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2345 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2346 mpd_qfinalize(MPD(dec), CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2347 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2348 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2349 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2350 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2351 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2352 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2353 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2354 |
|
80311
9a701e8ec2c9
Issue #16431: Finally, consider all permutations.
Stefan Krah <skrah@bytereef.org>
parents:
80295
diff
changeset
|
2355 /* Return a new PyDecObject or a subtype from a Decimal. */ |
|
80293
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2356 static PyObject * |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2357 PyDecType_FromDecimalExact(PyTypeObject *type, PyObject *v, PyObject *context) |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2358 { |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2359 PyObject *dec; |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2360 uint32_t status = 0; |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2361 |
|
80311
9a701e8ec2c9
Issue #16431: Finally, consider all permutations.
Stefan Krah <skrah@bytereef.org>
parents:
80295
diff
changeset
|
2362 if (type == &PyDec_Type && PyDec_CheckExact(v)) { |
|
80293
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2363 Py_INCREF(v); |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2364 return v; |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2365 } |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2366 |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2367 dec = PyDecType_New(type); |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2368 if (dec == NULL) { |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2369 return NULL; |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2370 } |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2371 |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2372 mpd_qcopy(MPD(dec), MPD(v), &status); |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2373 if (dec_addstatus(context, status)) { |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2374 Py_DECREF(dec); |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2375 return NULL; |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2376 } |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2377 |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2378 return dec; |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2379 } |
|
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2380 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2381 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2382 sequence_as_tuple(PyObject *v, PyObject *ex, const char *mesg) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2383 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2384 if (PyTuple_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2385 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2386 return v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2387 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2388 if (PyList_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2389 return PyList_AsTuple(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2390 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2391 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2392 PyErr_SetString(ex, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2393 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2394 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2395 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2396 /* Return a new C string representation of a DecimalTuple. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2397 static char * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2398 dectuple_as_str(PyObject *dectuple) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2399 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2400 PyObject *digits = NULL, *tmp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2401 char *decstring = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2402 char sign_special[6]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2403 char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2404 long sign, l; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2405 mpd_ssize_t exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2406 Py_ssize_t i, mem, tsize; |
|
78970
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2407 int is_infinite = 0; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2408 int n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2409 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2410 assert(PyTuple_Check(dectuple)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2411 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2412 if (PyTuple_Size(dectuple) != 3) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2413 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2414 "argument must be a sequence of length 3"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2415 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2416 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2417 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2418 /* sign */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2419 tmp = PyTuple_GET_ITEM(dectuple, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2420 if (!PyLong_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2421 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2422 "sign must be an integer with the value 0 or 1"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2423 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2424 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2425 sign = PyLong_AsLong(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2426 if (sign == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2427 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2428 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2429 if (sign != 0 && sign != 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2430 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2431 "sign must be an integer with the value 0 or 1"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2432 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2433 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2434 sign_special[0] = sign ? '-' : '+'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2435 sign_special[1] = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2436 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2437 /* exponent or encoding for a special number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2438 tmp = PyTuple_GET_ITEM(dectuple, 2); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2439 if (PyUnicode_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2440 /* special */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2441 if (PyUnicode_CompareWithASCIIString(tmp, "F") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2442 strcat(sign_special, "Inf"); |
|
78970
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2443 is_infinite = 1; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2444 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2445 else if (PyUnicode_CompareWithASCIIString(tmp, "n") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2446 strcat(sign_special, "NaN"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2447 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2448 else if (PyUnicode_CompareWithASCIIString(tmp, "N") == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2449 strcat(sign_special, "sNaN"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2450 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2451 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2452 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2453 "string argument in the third position " |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2454 "must be 'F', 'n' or 'N'"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2455 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2456 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2457 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2458 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2459 /* exponent */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2460 if (!PyLong_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2461 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2462 "exponent must be an integer"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2463 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2464 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2465 exp = PyLong_AsSsize_t(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2466 if (exp == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2467 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2468 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2469 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2470 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2471 /* coefficient */ |
| 76122 | 2472 digits = sequence_as_tuple(PyTuple_GET_ITEM(dectuple, 1), PyExc_ValueError, |
| 2473 "coefficient must be a tuple of digits"); | |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2474 if (digits == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2475 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2476 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2477 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2478 tsize = PyTuple_Size(digits); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2479 /* [sign][coeffdigits+1][E][-][expdigits+1]['\0'] */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2480 mem = 1 + tsize + 3 + MPD_EXPDIGITS + 2; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2481 cp = decstring = PyMem_Malloc(mem); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2482 if (decstring == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2483 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2484 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2485 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2486 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2487 n = snprintf(cp, mem, "%s", sign_special); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2488 if (n < 0 || n >= mem) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2489 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2490 "internal error in dec_sequence_as_str"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2491 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2492 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2493 cp += n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2494 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2495 if (tsize == 0 && sign_special[1] == '\0') { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2496 /* empty tuple: zero coefficient, except for special numbers */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2497 *cp++ = '0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2498 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2499 for (i = 0; i < tsize; i++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2500 tmp = PyTuple_GET_ITEM(digits, i); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2501 if (!PyLong_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2502 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2503 "coefficient must be a tuple of digits"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2504 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2505 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2506 l = PyLong_AsLong(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2507 if (l == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2508 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2509 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2510 if (l < 0 || l > 9) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2511 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2512 "coefficient must be a tuple of digits"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2513 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2514 } |
|
78970
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2515 if (is_infinite) { |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2516 /* accept but ignore any well-formed coefficient for compatibility |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2517 with decimal.py */ |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2518 continue; |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2519 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2520 *cp++ = (char)l + '0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2521 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2522 *cp = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2523 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2524 if (sign_special[1] == '\0') { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2525 /* not a special number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2526 *cp++ = 'E'; |
|
76121
a99cd3b98425
Allow printing a leading '-' and the maximum number of exponent digits
Stefan Krah <skrah@bytereef.org>
parents:
76120
diff
changeset
|
2527 n = snprintf(cp, MPD_EXPDIGITS+2, "%" PRI_mpd_ssize_t, exp); |
|
a99cd3b98425
Allow printing a leading '-' and the maximum number of exponent digits
Stefan Krah <skrah@bytereef.org>
parents:
76120
diff
changeset
|
2528 if (n < 0 || n >= MPD_EXPDIGITS+2) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2529 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2530 "internal error in dec_sequence_as_str"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2531 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2532 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2533 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2534 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2535 Py_XDECREF(digits); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2536 return decstring; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2537 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2538 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2539 error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2540 Py_XDECREF(digits); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2541 if (decstring) PyMem_Free(decstring); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2542 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2543 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2544 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2545 /* Currently accepts tuples and lists. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2546 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2547 PyDecType_FromSequence(PyTypeObject *type, PyObject *v, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2548 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2549 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2550 PyObject *dectuple; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2551 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2552 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2553 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2554 dectuple = sequence_as_tuple(v, PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2555 "argument must be a tuple or list"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2556 if (dectuple == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2557 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2558 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2559 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2560 s = dectuple_as_str(dectuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2561 Py_DECREF(dectuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2562 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2563 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2564 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2565 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2566 dec = PyDecType_FromCString(type, s, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2567 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2568 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2569 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2570 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2571 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2572 /* Currently accepts tuples and lists. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2573 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2574 PyDecType_FromSequenceExact(PyTypeObject *type, PyObject *v, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2575 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2576 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2577 PyObject *dectuple; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2578 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2579 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2580 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2581 dectuple = sequence_as_tuple(v, PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2582 "argument must be a tuple or list"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2583 if (dectuple == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2584 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2585 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2586 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2587 s = dectuple_as_str(dectuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2588 Py_DECREF(dectuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2589 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2590 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2591 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2592 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2593 dec = PyDecType_FromCStringExact(type, s, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2594 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2595 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2596 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2597 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2598 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2599 #define PyDec_FromCString(str, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2600 PyDecType_FromCString(&PyDec_Type, str, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2601 #define PyDec_FromCStringExact(str, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2602 PyDecType_FromCStringExact(&PyDec_Type, str, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2603 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2604 #define PyDec_FromUnicode(unicode, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2605 PyDecType_FromUnicode(&PyDec_Type, unicode, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2606 #define PyDec_FromUnicodeExact(unicode, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2607 PyDecType_FromUnicodeExact(&PyDec_Type, unicode, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2608 #define PyDec_FromUnicodeExactWS(unicode, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2609 PyDecType_FromUnicodeExactWS(&PyDec_Type, unicode, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2610 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2611 #define PyDec_FromSsize(v, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2612 PyDecType_FromSsize(&PyDec_Type, v, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2613 #define PyDec_FromSsizeExact(v, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2614 PyDecType_FromSsizeExact(&PyDec_Type, v, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2615 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2616 #define PyDec_FromLong(pylong, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2617 PyDecType_FromLong(&PyDec_Type, pylong, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2618 #define PyDec_FromLongExact(pylong, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2619 PyDecType_FromLongExact(&PyDec_Type, pylong, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2620 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2621 #define PyDec_FromFloat(pyfloat, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2622 PyDecType_FromFloat(&PyDec_Type, pyfloat, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2623 #define PyDec_FromFloatExact(pyfloat, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2624 PyDecType_FromFloatExact(&PyDec_Type, pyfloat, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2625 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2626 #define PyDec_FromSequence(sequence, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2627 PyDecType_FromSequence(&PyDec_Type, sequence, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2628 #define PyDec_FromSequenceExact(sequence, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2629 PyDecType_FromSequenceExact(&PyDec_Type, sequence, context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2630 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2631 /* class method */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2632 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2633 dec_from_float(PyObject *dec, PyObject *pyfloat) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2634 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2635 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2636 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2637 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2638 return PyDecType_FromFloatExact((PyTypeObject *)dec, pyfloat, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2639 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2640 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2641 /* create_decimal_from_float */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2642 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2643 ctx_from_float(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2644 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2645 return PyDec_FromFloat(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2646 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2647 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2648 /* Apply the context to the input operand. Return a new PyDecObject. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2649 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2650 dec_apply(PyObject *v, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2651 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2652 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2653 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2654 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2655 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2656 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2657 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2658 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2659 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2660 mpd_qcopy(MPD(result), MPD(v), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2661 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2662 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2663 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2664 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2665 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2666 mpd_qfinalize(MPD(result), CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2667 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2668 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2669 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2670 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2671 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2672 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2673 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2674 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2675 /* 'v' can have any type accepted by the Decimal constructor. Attempt |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2676 an exact conversion. If the result does not meet the restrictions |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2677 for an mpd_t, fail with InvalidOperation. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2678 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2679 PyDecType_FromObjectExact(PyTypeObject *type, PyObject *v, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2680 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2681 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2682 return PyDecType_FromSsizeExact(type, 0, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2683 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2684 else if (PyDec_Check(v)) { |
|
80293
1b6c972457e6
Issue #16431: Use the type information when constructing a Decimal subtype
Stefan Krah <skrah@bytereef.org>
parents:
78970
diff
changeset
|
2685 return PyDecType_FromDecimalExact(type, v, context); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2686 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2687 else if (PyUnicode_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2688 return PyDecType_FromUnicodeExactWS(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2689 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2690 else if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2691 return PyDecType_FromLongExact(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2692 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2693 else if (PyTuple_Check(v) || PyList_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2694 return PyDecType_FromSequenceExact(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2695 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2696 else if (PyFloat_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2697 if (dec_addstatus(context, MPD_Float_operation)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2698 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2699 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2700 return PyDecType_FromFloatExact(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2701 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2702 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2703 PyErr_Format(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2704 "conversion from %s to Decimal is not supported", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2705 v->ob_type->tp_name); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2706 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2707 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2708 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2709 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2710 /* The context is used during conversion. This function is the |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2711 equivalent of context.create_decimal(). */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2712 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2713 PyDec_FromObject(PyObject *v, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2714 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2715 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2716 return PyDec_FromSsize(0, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2717 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2718 else if (PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2719 mpd_context_t *ctx = CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2720 if (mpd_isnan(MPD(v)) && |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2721 MPD(v)->digits > ctx->prec - ctx->clamp) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2722 /* Special case: too many NaN payload digits */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2723 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2724 if (dec_addstatus(context, MPD_Conversion_syntax)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2725 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2726 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2727 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2728 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2729 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2730 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2731 mpd_setspecial(MPD(result), MPD_POS, MPD_NAN); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2732 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2733 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2734 return dec_apply(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2735 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2736 else if (PyUnicode_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2737 return PyDec_FromUnicode(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2738 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2739 else if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2740 return PyDec_FromLong(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2741 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2742 else if (PyTuple_Check(v) || PyList_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2743 return PyDec_FromSequence(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2744 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2745 else if (PyFloat_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2746 if (dec_addstatus(context, MPD_Float_operation)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2747 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2748 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2749 return PyDec_FromFloat(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2750 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2751 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2752 PyErr_Format(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2753 "conversion from %s to Decimal is not supported", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2754 v->ob_type->tp_name); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2755 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2756 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2757 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2758 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2759 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2760 dec_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2761 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2762 static char *kwlist[] = {"value", "context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2763 PyObject *v = NULL; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
2764 PyObject *context = Py_None; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
2765 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2766 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2767 &v, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2768 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2769 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2770 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2771 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2772 return PyDecType_FromObjectExact(type, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2773 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2774 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2775 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2776 ctx_create_decimal(PyObject *context, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2777 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2778 PyObject *v = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2779 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2780 if (!PyArg_ParseTuple(args, "|O", &v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2781 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2782 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2783 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2784 return PyDec_FromObject(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2785 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2786 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2787 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2788 /******************************************************************************/ |
| 76077 | 2789 /* Implicit conversions to Decimal */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2790 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2791 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2792 /* Try to convert PyObject v to a new PyDecObject conv. If the conversion |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2793 fails, set conv to NULL (exception is set). If the conversion is not |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2794 implemented, set conv to Py_NotImplemented. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2795 #define NOT_IMPL 0 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2796 #define TYPE_ERR 1 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2797 Py_LOCAL_INLINE(int) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2798 convert_op(int type_err, PyObject **conv, PyObject *v, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2799 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2800 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2801 if (PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2802 *conv = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2803 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2804 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2805 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2806 if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2807 *conv = PyDec_FromLongExact(v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2808 if (*conv == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2809 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2810 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2811 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2812 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2813 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2814 if (type_err) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2815 PyErr_Format(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2816 "conversion from %s to Decimal is not supported", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2817 v->ob_type->tp_name); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2818 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2819 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2820 Py_INCREF(Py_NotImplemented); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2821 *conv = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2822 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2823 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2824 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2825 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2826 /* Return NotImplemented for unsupported types. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2827 #define CONVERT_OP(a, v, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2828 if (!convert_op(NOT_IMPL, a, v, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2829 return *(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2830 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2831 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2832 #define CONVERT_BINOP(a, b, v, w, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2833 if (!convert_op(NOT_IMPL, a, v, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2834 return *(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2835 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2836 if (!convert_op(NOT_IMPL, b, w, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2837 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2838 return *(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2839 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2840 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2841 #define CONVERT_TERNOP(a, b, c, v, w, x, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2842 if (!convert_op(NOT_IMPL, a, v, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2843 return *(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2844 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2845 if (!convert_op(NOT_IMPL, b, w, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2846 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2847 return *(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2848 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2849 if (!convert_op(NOT_IMPL, c, x, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2850 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2851 Py_DECREF(*(b)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2852 return *(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2853 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2854 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2855 /* Raise TypeError for unsupported types. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2856 #define CONVERT_OP_RAISE(a, v, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2857 if (!convert_op(TYPE_ERR, a, v, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2858 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2859 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2860 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2861 #define CONVERT_BINOP_RAISE(a, b, v, w, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2862 if (!convert_op(TYPE_ERR, a, v, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2863 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2864 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2865 if (!convert_op(TYPE_ERR, b, w, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2866 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2867 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2868 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2869 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2870 #define CONVERT_TERNOP_RAISE(a, b, c, v, w, x, context) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2871 if (!convert_op(TYPE_ERR, a, v, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2872 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2873 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2874 if (!convert_op(TYPE_ERR, b, w, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2875 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2876 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2877 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2878 if (!convert_op(TYPE_ERR, c, x, context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2879 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2880 Py_DECREF(*(b)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2881 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2882 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2883 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2884 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2885 /******************************************************************************/ |
| 76077 | 2886 /* Implicit conversions to Decimal for comparison */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2887 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2888 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2889 /* Convert rationals for comparison */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2890 static PyObject *Rational = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2891 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2892 multiply_by_denominator(PyObject *v, PyObject *r, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2893 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2894 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2895 PyObject *tmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2896 PyObject *denom = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2897 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2898 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2899 mpd_ssize_t exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2900 mpd_t *vv; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2901 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2902 /* v is not special, r is a rational */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2903 tmp = PyObject_GetAttrString(r, "denominator"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2904 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2905 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2906 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2907 denom = PyDec_FromLongExact(tmp, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2908 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2909 if (denom == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2910 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2911 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2912 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2913 vv = mpd_qncopy(MPD(v)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2914 if (vv == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2915 Py_DECREF(denom); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2916 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2917 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2918 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2919 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2920 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2921 Py_DECREF(denom); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2922 mpd_del(vv); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2923 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2924 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2925 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2926 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2927 /* Prevent Overflow in the following multiplication. The result of |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2928 the multiplication is only used in mpd_qcmp, which can handle |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2929 values that are technically out of bounds, like (for 32-bit) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2930 99999999999999999999...99999999e+425000000. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2931 exp = vv->exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2932 vv->exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2933 mpd_qmul(MPD(result), vv, MPD(denom), &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2934 MPD(result)->exp = exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2935 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2936 Py_DECREF(denom); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2937 mpd_del(vv); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2938 /* If any status has been accumulated during the multiplication, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2939 the result is invalid. This is very unlikely, since even the |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2940 32-bit version supports 425000000 digits. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2941 if (status) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2942 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2943 "exact conversion for comparison failed"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2944 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2945 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2946 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2947 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2948 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2949 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2950 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2951 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2952 numerator_as_decimal(PyObject *r, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2953 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2954 PyObject *tmp, *num; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2955 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2956 tmp = PyObject_GetAttrString(r, "numerator"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2957 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2958 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2959 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2960 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2961 num = PyDec_FromLongExact(tmp, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2962 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2963 return num; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2964 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2965 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2966 /* Convert v and w for comparison. v is a Decimal. If w is a Rational, both |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2967 v and w have to be transformed. Return 1 for success, with new references |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2968 to the converted objects in vcmp and wcmp. Return 0 for failure. In that |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2969 case wcmp is either NULL or Py_NotImplemented (new reference) and vcmp |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2970 is undefined. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2971 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2972 convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2973 int op, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2974 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2975 mpd_context_t *ctx = CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2976 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2977 *vcmp = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2978 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2979 if (PyDec_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2980 Py_INCREF(w); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2981 *wcmp = w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2982 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2983 else if (PyLong_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2984 *wcmp = PyDec_FromLongExact(w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2985 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2986 else if (PyFloat_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2987 if (op != Py_EQ && op != Py_NE && |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2988 dec_addstatus(context, MPD_Float_operation)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2989 *wcmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2990 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2991 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2992 ctx->status |= MPD_Float_operation; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2993 *wcmp = PyDec_FromFloatExact(w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2994 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2995 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2996 else if (PyComplex_Check(w) && (op == Py_EQ || op == Py_NE)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2997 Py_complex c = PyComplex_AsCComplex(w); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2998 if (c.real == -1.0 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2999 *wcmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3000 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3001 else if (c.imag == 0.0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3002 PyObject *tmp = PyFloat_FromDouble(c.real); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3003 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3004 *wcmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3005 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3006 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3007 ctx->status |= MPD_Float_operation; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3008 *wcmp = PyDec_FromFloatExact(tmp, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3009 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3010 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3011 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3012 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3013 Py_INCREF(Py_NotImplemented); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3014 *wcmp = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3015 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3016 } |
|
87015
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3017 else { |
|
87017
88b85b53f067
Change style to match the surrounding code (no early returns).
Stefan Krah <skrah@bytereef.org>
parents:
87016
diff
changeset
|
3018 int is_rational = PyObject_IsInstance(w, Rational); |
|
88b85b53f067
Change style to match the surrounding code (no early returns).
Stefan Krah <skrah@bytereef.org>
parents:
87016
diff
changeset
|
3019 if (is_rational < 0) { |
|
87015
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3020 *wcmp = NULL; |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3021 } |
|
87017
88b85b53f067
Change style to match the surrounding code (no early returns).
Stefan Krah <skrah@bytereef.org>
parents:
87016
diff
changeset
|
3022 else if (is_rational > 0) { |
|
87015
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3023 *wcmp = numerator_as_decimal(w, context); |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3024 if (*wcmp && !mpd_isspecial(MPD(v))) { |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3025 *vcmp = multiply_by_denominator(v, w, context); |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3026 if (*vcmp == NULL) { |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3027 Py_CLEAR(*wcmp); |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3028 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3029 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3030 } |
|
87015
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3031 else { |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3032 Py_INCREF(Py_NotImplemented); |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3033 *wcmp = Py_NotImplemented; |
|
08c81db35959
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
Victor Stinner <victor.stinner@gmail.com>
parents:
83979
diff
changeset
|
3034 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3035 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3036 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3037 if (*wcmp == NULL || *wcmp == Py_NotImplemented) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3038 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3039 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3040 if (*vcmp == v) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3041 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3042 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3043 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3044 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3045 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3046 #define CONVERT_BINOP_CMP(vcmp, wcmp, v, w, op, ctx) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3047 if (!convert_op_cmp(vcmp, wcmp, v, w, op, ctx)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3048 return *(wcmp); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3049 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3050 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3051 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3052 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3053 /* Conversions from decimal */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3054 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3055 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3056 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3057 unicode_fromascii(const char *s, Py_ssize_t size) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3058 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3059 PyObject *res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3060 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3061 res = PyUnicode_New(size, 127); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3062 if (res == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3063 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3064 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3065 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3066 memcpy(PyUnicode_1BYTE_DATA(res), s, size); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3067 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3068 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3069 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3070 /* PyDecObject as a string. The default module context is only used for |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3071 the value of 'capitals'. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3072 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3073 dec_str(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3074 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3075 PyObject *res, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3076 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3077 char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3078 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3079 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3080 size = mpd_to_sci_size(&cp, MPD(dec), CtxCaps(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3081 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3082 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3083 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3084 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3085 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3086 res = unicode_fromascii(cp, size); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3087 mpd_free(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3088 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3089 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3090 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3091 /* Representation of a PyDecObject. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3092 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3093 dec_repr(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3094 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3095 PyObject *res, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3096 char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3097 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3098 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3099 cp = mpd_to_sci(MPD(dec), CtxCaps(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3100 if (cp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3101 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3102 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3103 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3104 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3105 res = PyUnicode_FromFormat("Decimal('%s')", cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3106 mpd_free(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3107 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3108 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3109 |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3110 /* Return a duplicate of src, copy embedded null characters. */ |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3111 static char * |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3112 dec_strdup(const char *src, Py_ssize_t size) |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3113 { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3114 char *dest = PyMem_Malloc(size+1); |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3115 if (dest == NULL) { |
|
87018
73b6225ae9cd
Move PyErr_NoMemory() closer to the failure.
Stefan Krah <skrah@bytereef.org>
parents:
87017
diff
changeset
|
3116 PyErr_NoMemory(); |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3117 return NULL; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3118 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3119 |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3120 memcpy(dest, src, size); |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3121 dest[size] = '\0'; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3122 return dest; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3123 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3124 |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3125 static void |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3126 dec_replace_fillchar(char *dest) |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3127 { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3128 while (*dest != '\0') { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3129 if (*dest == '\xff') *dest = '\0'; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3130 dest++; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3131 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3132 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3133 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3134 /* Convert decimal_point or thousands_sep, which may be multibyte or in |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3135 the range [128, 255], to a UTF8 string. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3136 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3137 dotsep_as_utf8(const char *s) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3138 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3139 PyObject *utf8; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3140 PyObject *tmp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3141 wchar_t buf[2]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3142 size_t n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3143 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3144 n = mbstowcs(buf, s, 2); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3145 if (n != 1) { /* Issue #7442 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3146 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3147 "invalid decimal point or unsupported " |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3148 "combination of LC_CTYPE and LC_NUMERIC"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3149 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3150 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3151 tmp = PyUnicode_FromWideChar(buf, n); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3152 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3153 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3154 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3155 utf8 = PyUnicode_AsUTF8String(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3156 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3157 return utf8; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3158 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3159 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3160 /* Formatted representation of a PyDecObject. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3161 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3162 dec_format(PyObject *dec, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3163 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3164 PyObject *result = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3165 PyObject *override = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3166 PyObject *dot = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3167 PyObject *sep = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3168 PyObject *grouping = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3169 PyObject *fmtarg; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3170 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3171 mpd_spec_t spec; |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3172 char *fmt; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3173 char *decstring = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3174 uint32_t status = 0; |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3175 int replace_fillchar = 0; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3176 Py_ssize_t size; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3177 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3178 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3179 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3180 if (!PyArg_ParseTuple(args, "O|O", &fmtarg, &override)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3181 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3182 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3183 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3184 if (PyUnicode_Check(fmtarg)) { |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3185 fmt = PyUnicode_AsUTF8AndSize(fmtarg, &size); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3186 if (fmt == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3187 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3188 } |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3189 if (size > 0 && fmt[0] == '\0') { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3190 /* NUL fill character: must be replaced with a valid UTF-8 char |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3191 before calling mpd_parse_fmt_str(). */ |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3192 replace_fillchar = 1; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3193 fmt = dec_strdup(fmt, size); |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3194 if (fmt == NULL) { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3195 return NULL; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3196 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3197 fmt[0] = '_'; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3198 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3199 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3200 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3201 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3202 "format arg must be str"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3203 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3204 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3205 |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3206 if (!mpd_parse_fmt_str(&spec, fmt, CtxCaps(context))) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3207 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3208 "invalid format string"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3209 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3210 } |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3211 if (replace_fillchar) { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3212 /* In order to avoid clobbering parts of UTF-8 thousands separators or |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3213 decimal points when the substitution is reversed later, the actual |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3214 placeholder must be an invalid UTF-8 byte. */ |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3215 spec.fill[0] = '\xff'; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3216 spec.fill[1] = '\0'; |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3217 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3218 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3219 if (override) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3220 /* Values for decimal_point, thousands_sep and grouping can |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3221 be explicitly specified in the override dict. These values |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3222 take precedence over the values obtained from localeconv() |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3223 in mpd_parse_fmt_str(). The feature is not documented and |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3224 is only used in test_decimal. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3225 if (!PyDict_Check(override)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3226 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3227 "optional argument must be a dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3228 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3229 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3230 if ((dot = PyDict_GetItemString(override, "decimal_point"))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3231 if ((dot = PyUnicode_AsUTF8String(dot)) == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3232 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3233 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3234 spec.dot = PyBytes_AS_STRING(dot); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3235 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3236 if ((sep = PyDict_GetItemString(override, "thousands_sep"))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3237 if ((sep = PyUnicode_AsUTF8String(sep)) == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3238 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3239 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3240 spec.sep = PyBytes_AS_STRING(sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3241 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3242 if ((grouping = PyDict_GetItemString(override, "grouping"))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3243 if ((grouping = PyUnicode_AsUTF8String(grouping)) == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3244 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3245 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3246 spec.grouping = PyBytes_AS_STRING(grouping); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3247 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3248 if (mpd_validate_lconv(&spec) < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3249 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3250 "invalid override dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3251 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3252 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3253 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3254 else { |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3255 size_t n = strlen(spec.dot); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3256 if (n > 1 || (n == 1 && !isascii((uchar)spec.dot[0]))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3257 /* fix locale dependent non-ascii characters */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3258 dot = dotsep_as_utf8(spec.dot); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3259 if (dot == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3260 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3261 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3262 spec.dot = PyBytes_AS_STRING(dot); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3263 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3264 n = strlen(spec.sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3265 if (n > 1 || (n == 1 && !isascii((uchar)spec.sep[0]))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3266 /* fix locale dependent non-ascii characters */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3267 sep = dotsep_as_utf8(spec.sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3268 if (sep == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3269 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3270 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3271 spec.sep = PyBytes_AS_STRING(sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3272 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3273 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3274 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3275 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3276 decstring = mpd_qformat_spec(MPD(dec), &spec, CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3277 if (decstring == NULL) { |
|
81682
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3278 if (status & MPD_Malloc_error) { |
|
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3279 PyErr_NoMemory(); |
|
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3280 } |
|
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3281 else { |
|
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3282 PyErr_SetString(PyExc_ValueError, |
|
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3283 "format specification exceeds internal limits of _decimal"); |
|
999870e107f7
Since the return type of format() is not a Decimal, raise ValueError instead of
Stefan Krah <skrah@bytereef.org>
parents:
81538
diff
changeset
|
3284 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3285 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3286 } |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3287 size = strlen(decstring); |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3288 if (replace_fillchar) { |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3289 dec_replace_fillchar(decstring); |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3290 } |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3291 |
|
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3292 result = PyUnicode_DecodeUTF8(decstring, size, NULL); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3293 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3294 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3295 finish: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3296 Py_XDECREF(grouping); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3297 Py_XDECREF(sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3298 Py_XDECREF(dot); |
|
83974
9156c663d6aa
Issue #17768: Support newline fill character in decimal.py and NUL fill
Stefan Krah <skrah@bytereef.org>
parents:
81682
diff
changeset
|
3299 if (replace_fillchar) PyMem_Free(fmt); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3300 if (decstring) mpd_free(decstring); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3301 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3302 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3303 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3304 /* Return a PyLongObject from a PyDecObject, using the specified rounding |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3305 * mode. The context precision is not observed. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3306 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3307 dec_as_long(PyObject *dec, PyObject *context, int round) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3308 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3309 PyLongObject *pylong; |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3310 digit *ob_digit; |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3311 size_t n; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3312 Py_ssize_t i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3313 mpd_t *x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3314 mpd_context_t workctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3315 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3316 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3317 if (mpd_isspecial(MPD(dec))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3318 if (mpd_isnan(MPD(dec))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3319 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3320 "cannot convert NaN to integer"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3321 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3322 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3323 PyErr_SetString(PyExc_OverflowError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3324 "cannot convert Infinity to integer"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3325 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3326 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3327 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3328 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3329 x = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3330 if (x == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3331 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3332 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3333 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3334 workctx = *CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3335 workctx.round = round; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3336 mpd_qround_to_int(x, MPD(dec), &workctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3337 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3338 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3339 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3340 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3341 |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3342 status = 0; |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3343 ob_digit = NULL; |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3344 #if PYLONG_BITS_IN_DIGIT == 30 |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3345 n = mpd_qexport_u32(&ob_digit, 0, PyLong_BASE, x, &status); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3346 #elif PYLONG_BITS_IN_DIGIT == 15 |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3347 n = mpd_qexport_u16(&ob_digit, 0, PyLong_BASE, x, &status); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3348 #else |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3349 #error "PYLONG_BITS_IN_DIGIT should be 15 or 30" |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3350 #endif |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3351 |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3352 if (n == SIZE_MAX) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3353 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3354 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3355 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3356 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3357 |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3358 assert(n > 0); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3359 pylong = _PyLong_New(n); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3360 if (pylong == NULL) { |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3361 mpd_free(ob_digit); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3362 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3363 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3364 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3365 |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3366 memcpy(pylong->ob_digit, ob_digit, n * sizeof(digit)); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3367 mpd_free(ob_digit); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3368 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3369 i = n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3370 while ((i > 0) && (pylong->ob_digit[i-1] == 0)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3371 i--; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3372 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3373 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3374 Py_SIZE(pylong) = i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3375 if (mpd_isnegative(x) && !mpd_iszero(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3376 Py_SIZE(pylong) = -i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3377 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3378 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3379 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3380 return (PyObject *) pylong; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3381 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3382 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3383 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3384 PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3385 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3386 static char *kwlist[] = {"rounding", "context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3387 PyObject *result; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3388 PyObject *rounding = Py_None; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3389 PyObject *context = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3390 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3391 mpd_context_t workctx; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3392 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3393 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3394 &rounding, &context)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3395 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3396 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3397 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3398 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3399 workctx = *CTX(context); |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3400 if (rounding != Py_None) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3401 int round = getround(rounding); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3402 if (round < 0) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3403 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3404 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3405 if (!mpd_qsetround(&workctx, round)) { |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
3406 INTERNAL_ERROR_PTR("PyDec_ToIntegralValue"); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3407 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3408 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3409 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3410 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3411 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3412 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3413 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3414 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3415 mpd_qround_to_int(MPD(result), MPD(dec), &workctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3416 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3417 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3418 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3419 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3420 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3421 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3422 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3423 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3424 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3425 PyDec_ToIntegralExact(PyObject *dec, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3426 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3427 static char *kwlist[] = {"rounding", "context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3428 PyObject *result; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3429 PyObject *rounding = Py_None; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3430 PyObject *context = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3431 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3432 mpd_context_t workctx; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3433 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3434 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3435 &rounding, &context)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3436 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3437 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3438 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3439 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3440 workctx = *CTX(context); |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3441 if (rounding != Py_None) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3442 int round = getround(rounding); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3443 if (round < 0) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3444 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3445 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3446 if (!mpd_qsetround(&workctx, round)) { |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
3447 INTERNAL_ERROR_PTR("PyDec_ToIntegralExact"); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3448 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3449 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3450 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3451 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3452 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3453 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3454 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3455 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3456 mpd_qround_to_intx(MPD(result), MPD(dec), &workctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3457 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3458 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3459 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3460 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3461 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3462 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3463 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3464 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3465 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3466 PyDec_AsFloat(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3467 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3468 PyObject *f, *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3469 |
|
78744
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3470 if (mpd_isnan(MPD(dec))) { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3471 if (mpd_issnan(MPD(dec))) { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3472 PyErr_SetString(PyExc_ValueError, |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3473 "cannot convert signaling NaN to float"); |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3474 return NULL; |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3475 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3476 if (mpd_isnegative(MPD(dec))) { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3477 s = PyUnicode_FromString("-nan"); |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3478 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3479 else { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3480 s = PyUnicode_FromString("nan"); |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3481 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3482 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3483 else { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3484 s = dec_str(dec); |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3485 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3486 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3487 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3488 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3489 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3490 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3491 f = PyFloat_FromString(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3492 Py_DECREF(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3493 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3494 return f; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3495 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3496 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3497 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3498 PyDec_Round(PyObject *dec, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3499 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3500 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3501 PyObject *x = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3502 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3503 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3504 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3505 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3506 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3507 if (!PyArg_ParseTuple(args, "|O", &x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3508 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3509 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3510 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3511 if (x) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3512 mpd_uint_t dq[1] = {1}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3513 mpd_t q = {MPD_STATIC|MPD_CONST_DATA,0,1,1,1,dq}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3514 mpd_ssize_t y; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3515 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3516 if (!PyLong_Check(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3517 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3518 "optional arg must be an integer"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3519 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3520 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3521 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3522 y = PyLong_AsSsize_t(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3523 if (y == -1 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3524 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3525 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3526 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3527 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3528 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3529 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3530 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3531 q.exp = (y == MPD_SSIZE_MIN) ? MPD_SSIZE_MAX : -y; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3532 mpd_qquantize(MPD(result), MPD(dec), &q, CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3533 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3534 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3535 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3536 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3537 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3538 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3539 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3540 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3541 return dec_as_long(dec, context, MPD_ROUND_HALF_EVEN); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3542 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3543 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3544 |
|
80972
24f6c6f3b7bf
Issue #16745: Hide a couple of symbols by making them local.
Stefan Krah <skrah@bytereef.org>
parents:
80891
diff
changeset
|
3545 static PyObject *DecimalTuple = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3546 /* Return the DecimalTuple representation of a PyDecObject. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3547 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3548 PyDec_AsTuple(PyObject *dec, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3549 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3550 PyObject *result = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3551 PyObject *sign = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3552 PyObject *coeff = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3553 PyObject *expt = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3554 PyObject *tmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3555 mpd_t *x = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3556 char *intstring = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3557 Py_ssize_t intlen, i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3558 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3559 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3560 x = mpd_qncopy(MPD(dec)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3561 if (x == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3562 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3563 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3564 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3565 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3566 sign = PyLong_FromUnsignedLong(mpd_sign(MPD(dec))); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3567 if (sign == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3568 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3569 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3570 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3571 if (mpd_isinfinite(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3572 expt = PyUnicode_FromString("F"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3573 if (expt == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3574 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3575 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3576 /* decimal.py has non-compliant infinity payloads. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3577 coeff = Py_BuildValue("(i)", 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3578 if (coeff == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3579 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3580 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3581 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3582 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3583 if (mpd_isnan(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3584 expt = PyUnicode_FromString(mpd_isqnan(x)?"n":"N"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3585 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3586 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3587 expt = PyLong_FromSsize_t(MPD(dec)->exp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3588 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3589 if (expt == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3590 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3591 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3592 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3593 /* coefficient is defined */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3594 if (x->len > 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3595 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3596 /* make an integer */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3597 x->exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3598 /* clear NaN and sign */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3599 mpd_clear_flags(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3600 intstring = mpd_to_sci(x, 1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3601 if (intstring == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3602 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3603 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3604 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3605 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3606 intlen = strlen(intstring); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3607 coeff = PyTuple_New(intlen); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3608 if (coeff == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3609 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3610 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3611 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3612 for (i = 0; i < intlen; i++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3613 tmp = PyLong_FromLong(intstring[i]-'0'); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3614 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3615 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3616 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3617 PyTuple_SET_ITEM(coeff, i, tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3618 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3619 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3620 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3621 coeff = PyTuple_New(0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3622 if (coeff == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3623 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3624 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3625 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3626 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3627 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3628 result = PyObject_CallFunctionObjArgs(DecimalTuple, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3629 sign, coeff, expt, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3630 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3631 out: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3632 if (x) mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3633 if (intstring) mpd_free(intstring); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3634 Py_XDECREF(sign); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3635 Py_XDECREF(coeff); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3636 Py_XDECREF(expt); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3637 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3638 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3639 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3640 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3641 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3642 /* Macros for converting mpdecimal functions to Decimal methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3643 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3644 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3645 /* Unary number method that uses the default module context. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3646 #define Dec_UnaryNumberMethod(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3647 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3648 nm_##MPDFUNC(PyObject *self) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3649 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3650 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3651 PyObject *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3652 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3653 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3654 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3655 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3656 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3657 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3658 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3659 MPDFUNC(MPD(result), MPD(self), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3660 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3661 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3662 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3663 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3664 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3665 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3666 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3667 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3668 /* Binary number method that uses default module context. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3669 #define Dec_BinaryNumberMethod(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3670 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3671 nm_##MPDFUNC(PyObject *self, PyObject *other) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3672 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3673 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3674 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3675 PyObject *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3676 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3677 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3678 CURRENT_CONTEXT(context) ; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3679 CONVERT_BINOP(&a, &b, self, other, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3680 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3681 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3682 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3683 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3684 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3685 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3686 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3687 MPDFUNC(MPD(result), MPD(a), MPD(b), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3688 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3689 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3690 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3691 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3692 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3693 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3694 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3695 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3696 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3697 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3698 /* Boolean function without a context arg. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3699 #define Dec_BoolFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3700 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3701 dec_##MPDFUNC(PyObject *self, PyObject *dummy UNUSED) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3702 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3703 return MPDFUNC(MPD(self)) ? incr_true() : incr_false(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3704 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3705 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3706 /* Boolean function with an optional context arg. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3707 #define Dec_BoolFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3708 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3709 dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3710 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3711 static char *kwlist[] = {"context", NULL}; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3712 PyObject *context = Py_None; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3713 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3714 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3715 &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3716 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3717 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3718 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3719 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3720 return MPDFUNC(MPD(self), CTX(context)) ? incr_true() : incr_false(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3721 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3722 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3723 /* Unary function with an optional context arg. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3724 #define Dec_UnaryFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3725 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3726 dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3727 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3728 static char *kwlist[] = {"context", NULL}; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3729 PyObject *result; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3730 PyObject *context = Py_None; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3731 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3732 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3733 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3734 &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3735 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3736 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3737 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3738 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3739 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3740 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3741 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3742 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3743 MPDFUNC(MPD(result), MPD(self), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3744 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3745 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3746 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3747 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3748 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3749 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3750 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3751 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3752 /* Binary function with an optional context arg. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3753 #define Dec_BinaryFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3754 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3755 dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3756 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3757 static char *kwlist[] = {"other", "context", NULL}; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3758 PyObject *other; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3759 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3760 PyObject *result; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3761 PyObject *context = Py_None; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3762 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3763 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3764 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3765 &other, &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3766 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3767 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3768 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3769 CONVERT_BINOP_RAISE(&a, &b, self, other, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3770 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3771 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3772 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3773 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3774 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3775 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3776 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3777 MPDFUNC(MPD(result), MPD(a), MPD(b), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3778 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3779 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3780 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3781 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3782 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3783 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3784 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3785 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3786 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3787 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3788 /* Binary function with an optional context arg. Actual MPDFUNC does |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3789 NOT take a context. The context is used to record InvalidOperation |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3790 if the second operand cannot be converted exactly. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3791 #define Dec_BinaryFuncVA_NO_CTX(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3792 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3793 dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3794 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3795 static char *kwlist[] = {"other", "context", NULL}; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3796 PyObject *context = Py_None; \ |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3797 PyObject *other; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3798 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3799 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3800 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3801 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3802 &other, &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3803 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3804 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3805 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3806 CONVERT_BINOP_RAISE(&a, &b, self, other, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3807 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3808 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3809 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3810 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3811 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3812 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3813 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3814 MPDFUNC(MPD(result), MPD(a), MPD(b)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3815 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3816 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3817 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3818 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3819 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3820 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3821 /* Ternary function with an optional context arg. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3822 #define Dec_TernaryFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3823 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3824 dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3825 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3826 static char *kwlist[] = {"other", "third", "context", NULL}; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3827 PyObject *other, *third; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3828 PyObject *a, *b, *c; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3829 PyObject *result; \ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
3830 PyObject *context = Py_None; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3831 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3832 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3833 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3834 &other, &third, &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3835 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3836 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3837 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3838 CONVERT_TERNOP_RAISE(&a, &b, &c, self, other, third, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3839 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3840 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3841 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3842 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3843 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3844 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3845 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3846 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3847 MPDFUNC(MPD(result), MPD(a), MPD(b), MPD(c), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3848 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3849 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3850 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3851 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3852 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3853 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3854 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3855 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3856 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3857 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3858 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3859 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3860 /**********************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3861 /* Number methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3862 /**********************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3863 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3864 Dec_UnaryNumberMethod(mpd_qminus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3865 Dec_UnaryNumberMethod(mpd_qplus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3866 Dec_UnaryNumberMethod(mpd_qabs) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3867 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3868 Dec_BinaryNumberMethod(mpd_qadd) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3869 Dec_BinaryNumberMethod(mpd_qsub) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3870 Dec_BinaryNumberMethod(mpd_qmul) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3871 Dec_BinaryNumberMethod(mpd_qdiv) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3872 Dec_BinaryNumberMethod(mpd_qrem) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3873 Dec_BinaryNumberMethod(mpd_qdivint) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3874 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3875 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3876 nm_dec_as_long(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3877 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3878 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3879 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3880 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3881 return dec_as_long(dec, context, MPD_ROUND_DOWN); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3882 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3883 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3884 static int |
|
76182
435b21afc6fa
Use the MPD() accessor macro.
Stefan Krah <skrah@bytereef.org>
parents:
76124
diff
changeset
|
3885 nm_nonzero(PyObject *v) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3886 { |
|
76182
435b21afc6fa
Use the MPD() accessor macro.
Stefan Krah <skrah@bytereef.org>
parents:
76124
diff
changeset
|
3887 return !mpd_iszero(MPD(v)); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3888 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3889 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3890 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3891 nm_mpd_qdivmod(PyObject *v, PyObject *w) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3892 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3893 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3894 PyObject *q, *r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3895 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3896 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3897 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3898 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3899 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3900 CONVERT_BINOP(&a, &b, v, w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3901 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3902 q = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3903 if (q == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3904 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3905 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3906 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3907 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3908 r = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3909 if (r == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3910 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3911 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3912 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3913 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3914 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3915 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3916 mpd_qdivmod(MPD(q), MPD(r), MPD(a), MPD(b), CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3917 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3918 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3919 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3920 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3921 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3922 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3923 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3924 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3925 ret = Py_BuildValue("(OO)", q, r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3926 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3927 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3928 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3929 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3930 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3931 static mpd_uint_t data_zero[1] = {0}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3932 static const mpd_t zero = {MPD_STATIC|MPD_CONST_DATA, 0, 1, 1, 1, data_zero}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3933 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3934 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3935 nm_mpd_qpow(PyObject *base, PyObject *exp, PyObject *mod) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3936 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3937 PyObject *a, *b, *c = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3938 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3939 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3940 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3941 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3942 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3943 CONVERT_BINOP(&a, &b, base, exp, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3944 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3945 if (mod != Py_None) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3946 if (!convert_op(NOT_IMPL, &c, mod, context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3947 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3948 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3949 return c; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3950 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3951 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3952 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3953 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3954 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3955 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3956 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3957 Py_XDECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3958 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3959 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3960 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3961 if (c == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3962 mpd_qpow(MPD(result), MPD(a), MPD(b), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3963 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3964 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3965 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3966 mpd_qpowmod(MPD(result), MPD(a), MPD(b), MPD(c), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3967 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3968 Py_DECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3969 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3970 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3971 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3972 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3973 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3974 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3975 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3976 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3977 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3978 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3979 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3980 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3981 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3982 /* Decimal Methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3983 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3984 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3985 /* Unary arithmetic functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3986 Dec_UnaryFuncVA(mpd_qexp) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3987 Dec_UnaryFuncVA(mpd_qln) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3988 Dec_UnaryFuncVA(mpd_qlog10) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3989 Dec_UnaryFuncVA(mpd_qnext_minus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3990 Dec_UnaryFuncVA(mpd_qnext_plus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3991 Dec_UnaryFuncVA(mpd_qreduce) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3992 Dec_UnaryFuncVA(mpd_qsqrt) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3993 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3994 /* Binary arithmetic functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3995 Dec_BinaryFuncVA(mpd_qcompare) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3996 Dec_BinaryFuncVA(mpd_qcompare_signal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3997 Dec_BinaryFuncVA(mpd_qmax) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3998 Dec_BinaryFuncVA(mpd_qmax_mag) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3999 Dec_BinaryFuncVA(mpd_qmin) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4000 Dec_BinaryFuncVA(mpd_qmin_mag) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4001 Dec_BinaryFuncVA(mpd_qnext_toward) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4002 Dec_BinaryFuncVA(mpd_qrem_near) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4003 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4004 /* Ternary arithmetic functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4005 Dec_TernaryFuncVA(mpd_qfma) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4006 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4007 /* Boolean functions, no context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4008 Dec_BoolFunc(mpd_iscanonical) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4009 Dec_BoolFunc(mpd_isfinite) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4010 Dec_BoolFunc(mpd_isinfinite) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4011 Dec_BoolFunc(mpd_isnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4012 Dec_BoolFunc(mpd_isqnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4013 Dec_BoolFunc(mpd_issnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4014 Dec_BoolFunc(mpd_issigned) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4015 Dec_BoolFunc(mpd_iszero) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4016 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4017 /* Boolean functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4018 Dec_BoolFuncVA(mpd_isnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4019 Dec_BoolFuncVA(mpd_issubnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4020 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4021 /* Unary functions, no context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4022 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4023 dec_mpd_adjexp(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4024 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4025 mpd_ssize_t retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4026 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4027 if (mpd_isspecial(MPD(self))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4028 retval = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4029 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4030 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4031 retval = mpd_adjexp(MPD(self)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4032 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4033 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4034 return PyLong_FromSsize_t(retval); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4035 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4036 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4037 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4038 dec_canonical(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4039 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4040 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4041 return self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4042 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4043 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4044 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4045 dec_conjugate(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4046 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4047 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4048 return self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4049 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4050 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4051 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4052 dec_mpd_radix(PyObject *self UNUSED, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4053 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4054 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4055 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4056 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4057 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4058 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4059 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4060 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4061 _dec_settriple(result, MPD_POS, 10, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4062 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4063 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4064 |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4065 static PyObject * |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4066 dec_mpd_qcopy_abs(PyObject *self, PyObject *dummy UNUSED) |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4067 { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4068 PyObject *result; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4069 uint32_t status = 0; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4070 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4071 if ((result = dec_alloc()) == NULL) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4072 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4073 } |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4074 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4075 mpd_qcopy_abs(MPD(result), MPD(self), &status); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4076 if (status & MPD_Malloc_error) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4077 Py_DECREF(result); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4078 PyErr_NoMemory(); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4079 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4080 } |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4081 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4082 return result; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4083 } |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4084 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4085 static PyObject * |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4086 dec_mpd_qcopy_negate(PyObject *self, PyObject *dummy UNUSED) |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4087 { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4088 PyObject *result; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4089 uint32_t status = 0; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4090 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4091 if ((result = dec_alloc()) == NULL) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4092 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4093 } |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4094 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4095 mpd_qcopy_negate(MPD(result), MPD(self), &status); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4096 if (status & MPD_Malloc_error) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4097 Py_DECREF(result); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4098 PyErr_NoMemory(); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4099 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4100 } |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4101 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4102 return result; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4103 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4104 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4105 /* Unary functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4106 Dec_UnaryFuncVA(mpd_qinvert) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4107 Dec_UnaryFuncVA(mpd_qlogb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4108 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4109 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4110 dec_mpd_class(PyObject *self, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4111 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4112 static char *kwlist[] = {"context", NULL}; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4113 PyObject *context = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4114 const char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4115 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4116 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4117 &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4118 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4119 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4120 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4121 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4122 cp = mpd_class(MPD(self), CTX(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4123 return PyUnicode_FromString(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4124 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4125 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4126 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4127 dec_mpd_to_eng(PyObject *self, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4128 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4129 static char *kwlist[] = {"context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4130 PyObject *result; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4131 PyObject *context = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4132 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4133 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4134 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4135 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4136 &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4137 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4138 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4139 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4140 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4141 size = mpd_to_eng_size(&s, MPD(self), CtxCaps(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4142 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4143 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4144 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4145 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4146 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4147 result = unicode_fromascii(s, size); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4148 mpd_free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4149 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4150 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4151 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4152 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4153 /* Binary functions, optional context arg for conversion errors */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4154 Dec_BinaryFuncVA_NO_CTX(mpd_compare_total) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4155 Dec_BinaryFuncVA_NO_CTX(mpd_compare_total_mag) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4156 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4157 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4158 dec_mpd_qcopy_sign(PyObject *self, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4159 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4160 static char *kwlist[] = {"other", "context", NULL}; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4161 PyObject *other; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4162 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4163 PyObject *result; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4164 PyObject *context = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4165 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4166 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4167 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4168 &other, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4169 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4170 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4171 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4172 CONVERT_BINOP_RAISE(&a, &b, self, other, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4173 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4174 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4175 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4176 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4177 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4178 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4179 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4180 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4181 mpd_qcopy_sign(MPD(result), MPD(a), MPD(b), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4182 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4183 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4184 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4185 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4186 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4187 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4188 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4189 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4190 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4191 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4192 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4193 dec_mpd_same_quantum(PyObject *self, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4194 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4195 static char *kwlist[] = {"other", "context", NULL}; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4196 PyObject *other; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4197 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4198 PyObject *result; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4199 PyObject *context = Py_None; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4200 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4201 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4202 &other, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4203 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4204 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4205 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4206 CONVERT_BINOP_RAISE(&a, &b, self, other, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4207 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4208 result = mpd_same_quantum(MPD(a), MPD(b)) ? incr_true() : incr_false(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4209 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4210 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4211 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4212 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4213 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4214 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4215 /* Binary functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4216 Dec_BinaryFuncVA(mpd_qand) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4217 Dec_BinaryFuncVA(mpd_qor) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4218 Dec_BinaryFuncVA(mpd_qxor) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4219 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4220 Dec_BinaryFuncVA(mpd_qrotate) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4221 Dec_BinaryFuncVA(mpd_qscaleb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4222 Dec_BinaryFuncVA(mpd_qshift) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4223 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4224 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4225 dec_mpd_qquantize(PyObject *v, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4226 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4227 static char *kwlist[] = {"exp", "rounding", "context", NULL}; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4228 PyObject *rounding = Py_None; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4229 PyObject *context = Py_None; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4230 PyObject *w, *a, *b; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4231 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4232 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4233 mpd_context_t workctx; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4234 |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4235 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4236 &w, &rounding, &context)) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4237 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4238 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4239 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4240 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4241 workctx = *CTX(context); |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4242 if (rounding != Py_None) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4243 int round = getround(rounding); |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4244 if (round < 0) { |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4245 return NULL; |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4246 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4247 if (!mpd_qsetround(&workctx, round)) { |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
4248 INTERNAL_ERROR_PTR("dec_mpd_qquantize"); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4249 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4250 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4251 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4252 CONVERT_BINOP_RAISE(&a, &b, v, w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4253 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4254 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4255 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4256 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4257 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4258 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4259 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4260 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4261 mpd_qquantize(MPD(result), MPD(a), MPD(b), &workctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4262 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4263 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4264 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4265 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4266 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4267 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4268 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4269 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4270 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4271 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4272 /* Special methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4273 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4274 dec_richcompare(PyObject *v, PyObject *w, int op) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4275 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4276 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4277 PyObject *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4278 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4279 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4280 int a_issnan, b_issnan; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4281 int r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4282 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4283 assert(PyDec_Check(v)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4284 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4285 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4286 CONVERT_BINOP_CMP(&a, &b, v, w, op, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4287 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4288 a_issnan = mpd_issnan(MPD(a)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4289 b_issnan = mpd_issnan(MPD(b)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4290 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4291 r = mpd_qcmp(MPD(a), MPD(b), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4292 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4293 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4294 if (r == INT_MAX) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4295 /* sNaNs or op={le,ge,lt,gt} always signal. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4296 if (a_issnan || b_issnan || (op != Py_EQ && op != Py_NE)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4297 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4298 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4299 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4300 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4301 /* qNaN comparison with op={eq,ne} or comparison |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4302 * with InvalidOperation disabled. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4303 return (op == Py_NE) ? incr_true() : incr_false(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4304 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4305 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4306 switch (op) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4307 case Py_EQ: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4308 r = (r == 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4309 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4310 case Py_NE: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4311 r = (r != 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4312 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4313 case Py_LE: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4314 r = (r <= 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4315 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4316 case Py_GE: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4317 r = (r >= 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4318 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4319 case Py_LT: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4320 r = (r == -1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4321 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4322 case Py_GT: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4323 r = (r == 1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4324 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4325 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4326 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4327 return PyBool_FromLong(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4328 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4329 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4330 /* __ceil__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4331 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4332 dec_ceil(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4333 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4334 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4335 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4336 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4337 return dec_as_long(self, context, MPD_ROUND_CEILING); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4338 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4339 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4340 /* __complex__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4341 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4342 dec_complex(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4343 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4344 PyObject *f; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4345 double x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4346 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4347 f = PyDec_AsFloat(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4348 if (f == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4349 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4350 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4351 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4352 x = PyFloat_AsDouble(f); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4353 Py_DECREF(f); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4354 if (x == -1.0 && PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4355 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4356 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4357 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4358 return PyComplex_FromDoubles(x, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4359 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4360 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4361 /* __copy__ and __deepcopy__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4362 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4363 dec_copy(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4364 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4365 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4366 return self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4367 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4368 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4369 /* __floor__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4370 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4371 dec_floor(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4372 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4373 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4374 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4375 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4376 return dec_as_long(self, context, MPD_ROUND_FLOOR); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4377 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4378 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4379 /* Always uses the module context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4380 static Py_hash_t |
|
76206
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4381 _dec_hash(PyDecObject *v) |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4382 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4383 #if defined(CONFIG_64) && _PyHASH_BITS == 61 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4384 /* 2**61 - 1 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4385 mpd_uint_t p_data[1] = {2305843009213693951ULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4386 mpd_t p = {MPD_POS|MPD_STATIC|MPD_CONST_DATA, 0, 19, 1, 1, p_data}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4387 /* Inverse of 10 modulo p */ |
| 76123 | 4388 mpd_uint_t inv10_p_data[1] = {2075258708292324556ULL}; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4389 mpd_t inv10_p = {MPD_POS|MPD_STATIC|MPD_CONST_DATA, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4390 0, 19, 1, 1, inv10_p_data}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4391 #elif defined(CONFIG_32) && _PyHASH_BITS == 31 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4392 /* 2**31 - 1 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4393 mpd_uint_t p_data[2] = {147483647UL, 2}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4394 mpd_t p = {MPD_POS|MPD_STATIC|MPD_CONST_DATA, 0, 10, 2, 2, p_data}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4395 /* Inverse of 10 modulo p */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4396 mpd_uint_t inv10_p_data[2] = {503238553UL, 1}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4397 mpd_t inv10_p = {MPD_POS|MPD_STATIC|MPD_CONST_DATA, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4398 0, 10, 2, 2, inv10_p_data}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4399 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4400 #error "No valid combination of CONFIG_64, CONFIG_32 and _PyHASH_BITS" |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4401 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4402 const Py_hash_t py_hash_inf = 314159; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4403 const Py_hash_t py_hash_nan = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4404 mpd_uint_t ten_data[1] = {10}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4405 mpd_t ten = {MPD_POS|MPD_STATIC|MPD_CONST_DATA, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4406 0, 2, 1, 1, ten_data}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4407 Py_hash_t result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4408 mpd_t *exp_hash = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4409 mpd_t *tmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4410 mpd_ssize_t exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4411 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4412 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4413 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4414 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4415 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4416 context = current_context(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4417 if (context == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4418 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4419 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4420 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4421 if (mpd_isspecial(MPD(v))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4422 if (mpd_issnan(MPD(v))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4423 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4424 "Cannot hash a signaling NaN value"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4425 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4426 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4427 else if (mpd_isnan(MPD(v))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4428 return py_hash_nan; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4429 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4430 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4431 return py_hash_inf * mpd_arith_sign(MPD(v)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4432 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4433 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4434 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4435 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4436 exp_hash = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4437 if (exp_hash == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4438 goto malloc_error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4439 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4440 tmp = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4441 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4442 goto malloc_error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4443 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4444 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4445 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4446 * exp(v): exponent of v |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4447 * int(v): coefficient of v |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4448 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4449 exp = MPD(v)->exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4450 if (exp >= 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4451 /* 10**exp(v) % p */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4452 mpd_qsset_ssize(tmp, exp, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4453 mpd_qpowmod(exp_hash, &ten, tmp, &p, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4454 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4455 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4456 /* inv10_p**(-exp(v)) % p */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4457 mpd_qsset_ssize(tmp, -exp, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4458 mpd_qpowmod(exp_hash, &inv10_p, tmp, &p, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4459 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4460 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4461 /* hash = (int(v) * exp_hash) % p */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4462 if (!mpd_qcopy(tmp, MPD(v), &status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4463 goto malloc_error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4464 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4465 tmp->exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4466 mpd_set_positive(tmp); |
|
78707
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4467 |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4468 maxctx.prec = MPD_MAX_PREC + 21; |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4469 maxctx.emax = MPD_MAX_EMAX + 21; |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4470 maxctx.emin = MPD_MIN_EMIN - 21; |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4471 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4472 mpd_qmul(tmp, tmp, exp_hash, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4473 mpd_qrem(tmp, tmp, &p, &maxctx, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4474 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4475 result = mpd_qget_ssize(tmp, &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4476 result = mpd_ispositive(MPD(v)) ? result : -result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4477 result = (result == -1) ? -2 : result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4478 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4479 if (status != 0) { |
|
78707
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4480 if (status & MPD_Malloc_error) { |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4481 goto malloc_error; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4482 } |
|
78707
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4483 else { |
|
83979
8a77d7019559
Backport bff16086f03b and bcaaaa00425b.
Stefan Krah <skrah@bytereef.org>
parents:
83974
diff
changeset
|
4484 PyErr_SetString(PyExc_RuntimeError, /* GCOV_NOT_REACHED */ |
|
8a77d7019559
Backport bff16086f03b and bcaaaa00425b.
Stefan Krah <skrah@bytereef.org>
parents:
83974
diff
changeset
|
4485 "dec_hash: internal error: please report"); /* GCOV_NOT_REACHED */ |
|
78707
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4486 } |
|
83979
8a77d7019559
Backport bff16086f03b and bcaaaa00425b.
Stefan Krah <skrah@bytereef.org>
parents:
83974
diff
changeset
|
4487 result = -1; /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4488 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4489 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4490 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4491 finish: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4492 if (exp_hash) mpd_del(exp_hash); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4493 if (tmp) mpd_del(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4494 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4495 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4496 malloc_error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4497 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4498 result = -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4499 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4500 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4501 |
|
76206
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4502 static Py_hash_t |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4503 dec_hash(PyDecObject *self) |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4504 { |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4505 if (self->hash == -1) { |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4506 self->hash = _dec_hash(self); |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4507 } |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4508 |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4509 return self->hash; |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4510 } |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4511 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4512 /* __reduce__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4513 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4514 dec_reduce(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4515 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4516 PyObject *result, *str; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4517 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4518 str = dec_str(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4519 if (str == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4520 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4521 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4522 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4523 result = Py_BuildValue("O(O)", Py_TYPE(self), str); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4524 Py_DECREF(str); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4525 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4526 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4527 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4528 |
|
76198
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4529 /* __sizeof__ */ |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4530 static PyObject * |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4531 dec_sizeof(PyObject *v, PyObject *dummy UNUSED) |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4532 { |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4533 Py_ssize_t res; |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4534 |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4535 res = sizeof(PyDecObject); |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4536 if (mpd_isdynamic_data(MPD(v))) { |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4537 res += MPD(v)->alloc * sizeof(mpd_uint_t); |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4538 } |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4539 return PyLong_FromSsize_t(res); |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4540 } |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4541 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4542 /* __trunc__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4543 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4544 dec_trunc(PyObject *self, PyObject *dummy UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4545 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4546 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4547 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4548 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4549 return dec_as_long(self, context, MPD_ROUND_DOWN); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4550 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4551 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4552 /* real and imag */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4553 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4554 dec_real(PyObject *self, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4555 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4556 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4557 return self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4558 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4559 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4560 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4561 dec_imag(PyObject *self UNUSED, void *closure UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4562 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4563 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4564 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4565 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4566 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4567 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4568 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4569 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4570 _dec_settriple(result, MPD_POS, 0, 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4571 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4572 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4573 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4574 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4575 static PyGetSetDef dec_getsets [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4576 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4577 { "real", (getter)dec_real, NULL, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4578 { "imag", (getter)dec_imag, NULL, NULL, NULL}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4579 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4580 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4581 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4582 static PyNumberMethods dec_number_methods = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4583 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4584 (binaryfunc) nm_mpd_qadd, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4585 (binaryfunc) nm_mpd_qsub, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4586 (binaryfunc) nm_mpd_qmul, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4587 (binaryfunc) nm_mpd_qrem, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4588 (binaryfunc) nm_mpd_qdivmod, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4589 (ternaryfunc) nm_mpd_qpow, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4590 (unaryfunc) nm_mpd_qminus, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4591 (unaryfunc) nm_mpd_qplus, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4592 (unaryfunc) nm_mpd_qabs, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4593 (inquiry) nm_nonzero, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4594 (unaryfunc) 0, /* no bit-complement */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4595 (binaryfunc) 0, /* no shiftl */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4596 (binaryfunc) 0, /* no shiftr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4597 (binaryfunc) 0, /* no bit-and */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4598 (binaryfunc) 0, /* no bit-xor */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4599 (binaryfunc) 0, /* no bit-ior */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4600 (unaryfunc) nm_dec_as_long, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4601 0, /* nb_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4602 (unaryfunc) PyDec_AsFloat, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4603 0, /* binaryfunc nb_inplace_add; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4604 0, /* binaryfunc nb_inplace_subtract; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4605 0, /* binaryfunc nb_inplace_multiply; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4606 0, /* binaryfunc nb_inplace_remainder; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4607 0, /* ternaryfunc nb_inplace_power; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4608 0, /* binaryfunc nb_inplace_lshift; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4609 0, /* binaryfunc nb_inplace_rshift; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4610 0, /* binaryfunc nb_inplace_and; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4611 0, /* binaryfunc nb_inplace_xor; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4612 0, /* binaryfunc nb_inplace_or; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4613 (binaryfunc) nm_mpd_qdivint, /* binaryfunc nb_floor_divide; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4614 (binaryfunc) nm_mpd_qdiv, /* binaryfunc nb_true_divide; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4615 0, /* binaryfunc nb_inplace_floor_divide; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4616 0, /* binaryfunc nb_inplace_true_divide; */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4617 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4618 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4619 static PyMethodDef dec_methods [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4620 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4621 /* Unary arithmetic functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4622 { "exp", (PyCFunction)dec_mpd_qexp, METH_VARARGS|METH_KEYWORDS, doc_exp }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4623 { "ln", (PyCFunction)dec_mpd_qln, METH_VARARGS|METH_KEYWORDS, doc_ln }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4624 { "log10", (PyCFunction)dec_mpd_qlog10, METH_VARARGS|METH_KEYWORDS, doc_log10 }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4625 { "next_minus", (PyCFunction)dec_mpd_qnext_minus, METH_VARARGS|METH_KEYWORDS, doc_next_minus }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4626 { "next_plus", (PyCFunction)dec_mpd_qnext_plus, METH_VARARGS|METH_KEYWORDS, doc_next_plus }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4627 { "normalize", (PyCFunction)dec_mpd_qreduce, METH_VARARGS|METH_KEYWORDS, doc_normalize }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4628 { "to_integral", (PyCFunction)PyDec_ToIntegralValue, METH_VARARGS|METH_KEYWORDS, doc_to_integral }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4629 { "to_integral_exact", (PyCFunction)PyDec_ToIntegralExact, METH_VARARGS|METH_KEYWORDS, doc_to_integral_exact }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4630 { "to_integral_value", (PyCFunction)PyDec_ToIntegralValue, METH_VARARGS|METH_KEYWORDS, doc_to_integral_value }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4631 { "sqrt", (PyCFunction)dec_mpd_qsqrt, METH_VARARGS|METH_KEYWORDS, doc_sqrt }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4632 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4633 /* Binary arithmetic functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4634 { "compare", (PyCFunction)dec_mpd_qcompare, METH_VARARGS|METH_KEYWORDS, doc_compare }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4635 { "compare_signal", (PyCFunction)dec_mpd_qcompare_signal, METH_VARARGS|METH_KEYWORDS, doc_compare_signal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4636 { "max", (PyCFunction)dec_mpd_qmax, METH_VARARGS|METH_KEYWORDS, doc_max }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4637 { "max_mag", (PyCFunction)dec_mpd_qmax_mag, METH_VARARGS|METH_KEYWORDS, doc_max_mag }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4638 { "min", (PyCFunction)dec_mpd_qmin, METH_VARARGS|METH_KEYWORDS, doc_min }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4639 { "min_mag", (PyCFunction)dec_mpd_qmin_mag, METH_VARARGS|METH_KEYWORDS, doc_min_mag }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4640 { "next_toward", (PyCFunction)dec_mpd_qnext_toward, METH_VARARGS|METH_KEYWORDS, doc_next_toward }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4641 { "quantize", (PyCFunction)dec_mpd_qquantize, METH_VARARGS|METH_KEYWORDS, doc_quantize }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4642 { "remainder_near", (PyCFunction)dec_mpd_qrem_near, METH_VARARGS|METH_KEYWORDS, doc_remainder_near }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4643 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4644 /* Ternary arithmetic functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4645 { "fma", (PyCFunction)dec_mpd_qfma, METH_VARARGS|METH_KEYWORDS, doc_fma }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4646 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4647 /* Boolean functions, no context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4648 { "is_canonical", dec_mpd_iscanonical, METH_NOARGS, doc_is_canonical }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4649 { "is_finite", dec_mpd_isfinite, METH_NOARGS, doc_is_finite }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4650 { "is_infinite", dec_mpd_isinfinite, METH_NOARGS, doc_is_infinite }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4651 { "is_nan", dec_mpd_isnan, METH_NOARGS, doc_is_nan }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4652 { "is_qnan", dec_mpd_isqnan, METH_NOARGS, doc_is_qnan }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4653 { "is_snan", dec_mpd_issnan, METH_NOARGS, doc_is_snan }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4654 { "is_signed", dec_mpd_issigned, METH_NOARGS, doc_is_signed }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4655 { "is_zero", dec_mpd_iszero, METH_NOARGS, doc_is_zero }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4656 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4657 /* Boolean functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4658 { "is_normal", (PyCFunction)dec_mpd_isnormal, METH_VARARGS|METH_KEYWORDS, doc_is_normal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4659 { "is_subnormal", (PyCFunction)dec_mpd_issubnormal, METH_VARARGS|METH_KEYWORDS, doc_is_subnormal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4660 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4661 /* Unary functions, no context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4662 { "adjusted", dec_mpd_adjexp, METH_NOARGS, doc_adjusted }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4663 { "canonical", dec_canonical, METH_NOARGS, doc_canonical }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4664 { "conjugate", dec_conjugate, METH_NOARGS, doc_conjugate }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4665 { "radix", dec_mpd_radix, METH_NOARGS, doc_radix }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4666 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4667 /* Unary functions, optional context arg for conversion errors */ |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4668 { "copy_abs", dec_mpd_qcopy_abs, METH_NOARGS, doc_copy_abs }, |
|
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4669 { "copy_negate", dec_mpd_qcopy_negate, METH_NOARGS, doc_copy_negate }, |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4670 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4671 /* Unary functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4672 { "logb", (PyCFunction)dec_mpd_qlogb, METH_VARARGS|METH_KEYWORDS, doc_logb }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4673 { "logical_invert", (PyCFunction)dec_mpd_qinvert, METH_VARARGS|METH_KEYWORDS, doc_logical_invert }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4674 { "number_class", (PyCFunction)dec_mpd_class, METH_VARARGS|METH_KEYWORDS, doc_number_class }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4675 { "to_eng_string", (PyCFunction)dec_mpd_to_eng, METH_VARARGS|METH_KEYWORDS, doc_to_eng_string }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4676 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4677 /* Binary functions, optional context arg for conversion errors */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4678 { "compare_total", (PyCFunction)dec_mpd_compare_total, METH_VARARGS|METH_KEYWORDS, doc_compare_total }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4679 { "compare_total_mag", (PyCFunction)dec_mpd_compare_total_mag, METH_VARARGS|METH_KEYWORDS, doc_compare_total_mag }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4680 { "copy_sign", (PyCFunction)dec_mpd_qcopy_sign, METH_VARARGS|METH_KEYWORDS, doc_copy_sign }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4681 { "same_quantum", (PyCFunction)dec_mpd_same_quantum, METH_VARARGS|METH_KEYWORDS, doc_same_quantum }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4682 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4683 /* Binary functions, optional context arg */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4684 { "logical_and", (PyCFunction)dec_mpd_qand, METH_VARARGS|METH_KEYWORDS, doc_logical_and }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4685 { "logical_or", (PyCFunction)dec_mpd_qor, METH_VARARGS|METH_KEYWORDS, doc_logical_or }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4686 { "logical_xor", (PyCFunction)dec_mpd_qxor, METH_VARARGS|METH_KEYWORDS, doc_logical_xor }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4687 { "rotate", (PyCFunction)dec_mpd_qrotate, METH_VARARGS|METH_KEYWORDS, doc_rotate }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4688 { "scaleb", (PyCFunction)dec_mpd_qscaleb, METH_VARARGS|METH_KEYWORDS, doc_scaleb }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4689 { "shift", (PyCFunction)dec_mpd_qshift, METH_VARARGS|METH_KEYWORDS, doc_shift }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4690 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4691 /* Miscellaneous */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4692 { "from_float", dec_from_float, METH_O|METH_CLASS, doc_from_float }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4693 { "as_tuple", PyDec_AsTuple, METH_NOARGS, doc_as_tuple }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4694 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4695 /* Special methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4696 { "__copy__", dec_copy, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4697 { "__deepcopy__", dec_copy, METH_O, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4698 { "__format__", dec_format, METH_VARARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4699 { "__reduce__", dec_reduce, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4700 { "__round__", PyDec_Round, METH_VARARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4701 { "__ceil__", dec_ceil, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4702 { "__floor__", dec_floor, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4703 { "__trunc__", dec_trunc, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4704 { "__complex__", dec_complex, METH_NOARGS, NULL }, |
|
76198
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4705 { "__sizeof__", dec_sizeof, METH_NOARGS, NULL }, |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4706 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4707 { NULL, NULL, 1 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4708 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4709 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4710 static PyTypeObject PyDec_Type = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4711 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4712 PyVarObject_HEAD_INIT(NULL, 0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4713 "decimal.Decimal", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4714 sizeof(PyDecObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4715 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4716 (destructor) dec_dealloc, /* tp_dealloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4717 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4718 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4719 (setattrfunc) 0, /* tp_setattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4720 0, /* tp_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4721 (reprfunc) dec_repr, /* tp_repr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4722 &dec_number_methods, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4723 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4724 0, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4725 (hashfunc) dec_hash, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4726 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4727 (reprfunc) dec_str, /* tp_str */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4728 (getattrofunc) PyObject_GenericGetAttr, /* tp_getattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4729 (setattrofunc) 0, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4730 (PyBufferProcs *) 0, /* tp_as_buffer */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4731 (Py_TPFLAGS_DEFAULT| |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4732 Py_TPFLAGS_BASETYPE), /* tp_flags */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4733 doc_decimal, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4734 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4735 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4736 dec_richcompare, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4737 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4738 0, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4739 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4740 dec_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4741 0, /* tp_members */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4742 dec_getsets, /* tp_getset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4743 0, /* tp_base */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4744 0, /* tp_dict */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4745 0, /* tp_descr_get */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4746 0, /* tp_descr_set */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4747 0, /* tp_dictoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4748 0, /* tp_init */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4749 0, /* tp_alloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4750 dec_new, /* tp_new */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4751 PyObject_Del, /* tp_free */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4752 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4753 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4754 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4755 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4756 /* Context Object, Part 2 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4757 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4758 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4759 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4760 /************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4761 /* Macros for converting mpdecimal functions to Context methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4762 /************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4763 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4764 /* Boolean context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4765 #define DecCtx_BoolFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4766 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4767 ctx_##MPDFUNC(PyObject *context, PyObject *v) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4768 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4769 PyObject *ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4770 PyObject *a; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4771 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4772 CONVERT_OP_RAISE(&a, v, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4773 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4774 ret = MPDFUNC(MPD(a), CTX(context)) ? incr_true() : incr_false(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4775 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4776 return ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4777 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4778 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4779 /* Boolean context method. MPDFUNC does NOT use a context. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4780 #define DecCtx_BoolFunc_NO_CTX(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4781 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4782 ctx_##MPDFUNC(PyObject *context, PyObject *v) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4783 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4784 PyObject *ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4785 PyObject *a; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4786 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4787 CONVERT_OP_RAISE(&a, v, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4788 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4789 ret = MPDFUNC(MPD(a)) ? incr_true() : incr_false(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4790 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4791 return ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4792 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4793 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4794 /* Unary context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4795 #define DecCtx_UnaryFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4796 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4797 ctx_##MPDFUNC(PyObject *context, PyObject *v) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4798 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4799 PyObject *result, *a; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4800 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4801 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4802 CONVERT_OP_RAISE(&a, v, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4803 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4804 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4805 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4806 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4807 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4808 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4809 MPDFUNC(MPD(result), MPD(a), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4810 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4811 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4812 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4813 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4814 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4815 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4816 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4817 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4818 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4819 /* Binary context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4820 #define DecCtx_BinaryFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4821 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4822 ctx_##MPDFUNC(PyObject *context, PyObject *args) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4823 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4824 PyObject *v, *w; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4825 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4826 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4827 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4828 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4829 if (!PyArg_ParseTuple(args, "OO", &v, &w)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4830 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4831 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4832 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4833 CONVERT_BINOP_RAISE(&a, &b, v, w, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4834 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4835 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4836 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4837 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4838 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4839 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4840 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4841 MPDFUNC(MPD(result), MPD(a), MPD(b), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4842 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4843 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4844 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4845 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4846 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4847 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4848 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4849 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4850 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4851 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4852 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4853 * Binary context method. The context is only used for conversion. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4854 * The actual MPDFUNC does NOT take a context arg. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4855 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4856 #define DecCtx_BinaryFunc_NO_CTX(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4857 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4858 ctx_##MPDFUNC(PyObject *context, PyObject *args) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4859 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4860 PyObject *v, *w; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4861 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4862 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4863 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4864 if (!PyArg_ParseTuple(args, "OO", &v, &w)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4865 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4866 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4867 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4868 CONVERT_BINOP_RAISE(&a, &b, v, w, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4869 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4870 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4871 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4872 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4873 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4874 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4875 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4876 MPDFUNC(MPD(result), MPD(a), MPD(b)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4877 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4878 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4879 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4880 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4881 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4882 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4883 /* Ternary context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4884 #define DecCtx_TernaryFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4885 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4886 ctx_##MPDFUNC(PyObject *context, PyObject *args) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4887 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4888 PyObject *v, *w, *x; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4889 PyObject *a, *b, *c; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4890 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4891 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4892 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4893 if (!PyArg_ParseTuple(args, "OOO", &v, &w, &x)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4894 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4895 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4896 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4897 CONVERT_TERNOP_RAISE(&a, &b, &c, v, w, x, context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4898 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4899 if ((result = dec_alloc()) == NULL) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4900 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4901 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4902 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4903 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4904 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4905 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4906 MPDFUNC(MPD(result), MPD(a), MPD(b), MPD(c), CTX(context), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4907 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4908 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4909 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4910 if (dec_addstatus(context, status)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4911 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4912 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4913 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4914 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4915 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4916 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4917 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4918 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4919 /* Unary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4920 DecCtx_UnaryFunc(mpd_qabs) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4921 DecCtx_UnaryFunc(mpd_qexp) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4922 DecCtx_UnaryFunc(mpd_qln) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4923 DecCtx_UnaryFunc(mpd_qlog10) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4924 DecCtx_UnaryFunc(mpd_qminus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4925 DecCtx_UnaryFunc(mpd_qnext_minus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4926 DecCtx_UnaryFunc(mpd_qnext_plus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4927 DecCtx_UnaryFunc(mpd_qplus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4928 DecCtx_UnaryFunc(mpd_qreduce) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4929 DecCtx_UnaryFunc(mpd_qround_to_int) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4930 DecCtx_UnaryFunc(mpd_qround_to_intx) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4931 DecCtx_UnaryFunc(mpd_qsqrt) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4932 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4933 /* Binary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4934 DecCtx_BinaryFunc(mpd_qadd) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4935 DecCtx_BinaryFunc(mpd_qcompare) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4936 DecCtx_BinaryFunc(mpd_qcompare_signal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4937 DecCtx_BinaryFunc(mpd_qdiv) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4938 DecCtx_BinaryFunc(mpd_qdivint) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4939 DecCtx_BinaryFunc(mpd_qmax) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4940 DecCtx_BinaryFunc(mpd_qmax_mag) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4941 DecCtx_BinaryFunc(mpd_qmin) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4942 DecCtx_BinaryFunc(mpd_qmin_mag) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4943 DecCtx_BinaryFunc(mpd_qmul) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4944 DecCtx_BinaryFunc(mpd_qnext_toward) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4945 DecCtx_BinaryFunc(mpd_qquantize) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4946 DecCtx_BinaryFunc(mpd_qrem) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4947 DecCtx_BinaryFunc(mpd_qrem_near) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4948 DecCtx_BinaryFunc(mpd_qsub) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4949 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4950 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4951 ctx_mpd_qdivmod(PyObject *context, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4952 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4953 PyObject *v, *w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4954 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4955 PyObject *q, *r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4956 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4957 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4958 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4959 if (!PyArg_ParseTuple(args, "OO", &v, &w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4960 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4961 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4962 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4963 CONVERT_BINOP_RAISE(&a, &b, v, w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4964 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4965 q = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4966 if (q == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4967 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4968 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4969 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4970 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4971 r = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4972 if (r == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4973 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4974 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4975 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4976 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4977 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4978 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4979 mpd_qdivmod(MPD(q), MPD(r), MPD(a), MPD(b), CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4980 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4981 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4982 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4983 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4984 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4985 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4986 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4987 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4988 ret = Py_BuildValue("(OO)", q, r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4989 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4990 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4991 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4992 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4993 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4994 /* Binary or ternary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4995 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4996 ctx_mpd_qpow(PyObject *context, PyObject *args, PyObject *kwds) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4997 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4998 static char *kwlist[] = {"a", "b", "modulo", NULL}; |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
4999 PyObject *base, *exp, *mod = Py_None; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5000 PyObject *a, *b, *c = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5001 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5002 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5003 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5004 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5005 &base, &exp, &mod)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5006 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5007 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5008 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5009 CONVERT_BINOP_RAISE(&a, &b, base, exp, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5010 |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
5011 if (mod != Py_None) { |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5012 if (!convert_op(TYPE_ERR, &c, mod, context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5013 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5014 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5015 return c; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5016 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5017 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5018 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5019 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5020 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5021 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5022 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5023 Py_XDECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5024 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5025 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5026 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5027 if (c == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5028 mpd_qpow(MPD(result), MPD(a), MPD(b), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5029 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5030 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5031 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5032 mpd_qpowmod(MPD(result), MPD(a), MPD(b), MPD(c), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5033 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5034 Py_DECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5035 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5036 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5037 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5038 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5039 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5040 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5041 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5042 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5043 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5044 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5045 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5046 /* Ternary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5047 DecCtx_TernaryFunc(mpd_qfma) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5048 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5049 /* No argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5050 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5051 ctx_mpd_radix(PyObject *context, PyObject *dummy) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5052 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5053 return dec_mpd_radix(context, dummy); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5054 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5055 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5056 /* Boolean functions: single decimal argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5057 DecCtx_BoolFunc(mpd_isnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5058 DecCtx_BoolFunc(mpd_issubnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5059 DecCtx_BoolFunc_NO_CTX(mpd_isfinite) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5060 DecCtx_BoolFunc_NO_CTX(mpd_isinfinite) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5061 DecCtx_BoolFunc_NO_CTX(mpd_isnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5062 DecCtx_BoolFunc_NO_CTX(mpd_isqnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5063 DecCtx_BoolFunc_NO_CTX(mpd_issigned) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5064 DecCtx_BoolFunc_NO_CTX(mpd_issnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5065 DecCtx_BoolFunc_NO_CTX(mpd_iszero) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5066 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5067 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5068 ctx_iscanonical(PyObject *context UNUSED, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5069 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5070 if (!PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5071 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5072 "argument must be a Decimal"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5073 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5074 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5075 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5076 return mpd_iscanonical(MPD(v)) ? incr_true() : incr_false(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5077 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5078 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5079 /* Functions with a single decimal argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5080 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5081 PyDecContext_Apply(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5082 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5083 PyObject *result, *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5084 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5085 CONVERT_OP_RAISE(&a, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5086 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5087 result = dec_apply(a, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5088 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5089 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5090 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5091 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5092 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5093 ctx_canonical(PyObject *context UNUSED, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5094 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5095 if (!PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5096 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5097 "argument must be a Decimal"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5098 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5099 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5100 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5101 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5102 return v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5103 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5104 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5105 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5106 ctx_mpd_qcopy_abs(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5107 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5108 PyObject *result, *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5109 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5110 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5111 CONVERT_OP_RAISE(&a, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5112 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5113 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5114 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5115 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5116 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5117 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5118 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5119 mpd_qcopy_abs(MPD(result), MPD(a), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5120 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5121 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5122 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5123 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5124 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5125 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5126 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5127 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5128 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5129 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5130 ctx_copy_decimal(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5131 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5132 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5133 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5134 CONVERT_OP_RAISE(&result, v, context); |
| 76124 | 5135 return result; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5136 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5137 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5138 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5139 ctx_mpd_qcopy_negate(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5140 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5141 PyObject *result, *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5142 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5143 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5144 CONVERT_OP_RAISE(&a, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5145 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5146 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5147 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5148 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5149 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5150 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5151 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5152 mpd_qcopy_negate(MPD(result), MPD(a), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5153 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5154 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5155 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5156 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5157 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5158 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5159 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5160 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5161 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5162 DecCtx_UnaryFunc(mpd_qlogb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5163 DecCtx_UnaryFunc(mpd_qinvert) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5164 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5165 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5166 ctx_mpd_class(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5167 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5168 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5169 const char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5170 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5171 CONVERT_OP_RAISE(&a, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5172 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5173 cp = mpd_class(MPD(a), CTX(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5174 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5175 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5176 return PyUnicode_FromString(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5177 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5178 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5179 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5180 ctx_mpd_to_sci(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5181 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5182 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5183 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5184 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5185 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5186 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5187 CONVERT_OP_RAISE(&a, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5188 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5189 size = mpd_to_sci_size(&s, MPD(a), CtxCaps(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5190 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5191 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5192 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5193 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5194 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5195 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5196 result = unicode_fromascii(s, size); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5197 mpd_free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5198 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5199 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5200 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5201 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5202 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5203 ctx_mpd_to_eng(PyObject *context, PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5204 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5205 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5206 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5207 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5208 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5209 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5210 CONVERT_OP_RAISE(&a, v, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5211 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5212 size = mpd_to_eng_size(&s, MPD(a), CtxCaps(context)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5213 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5214 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5215 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5216 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5217 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5218 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5219 result = unicode_fromascii(s, size); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5220 mpd_free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5221 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5222 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5223 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5224 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5225 /* Functions with two decimal arguments */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5226 DecCtx_BinaryFunc_NO_CTX(mpd_compare_total) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5227 DecCtx_BinaryFunc_NO_CTX(mpd_compare_total_mag) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5228 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5229 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5230 ctx_mpd_qcopy_sign(PyObject *context, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5231 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5232 PyObject *v, *w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5233 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5234 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5235 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5236 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5237 if (!PyArg_ParseTuple(args, "OO", &v, &w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5238 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5239 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5240 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5241 CONVERT_BINOP_RAISE(&a, &b, v, w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5242 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5243 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5244 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5245 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5246 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5247 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5248 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5249 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5250 mpd_qcopy_sign(MPD(result), MPD(a), MPD(b), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5251 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5252 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5253 if (dec_addstatus(context, status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5254 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5255 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5256 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5257 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5258 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5259 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5260 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5261 DecCtx_BinaryFunc(mpd_qand) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5262 DecCtx_BinaryFunc(mpd_qor) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5263 DecCtx_BinaryFunc(mpd_qxor) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5264 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5265 DecCtx_BinaryFunc(mpd_qrotate) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5266 DecCtx_BinaryFunc(mpd_qscaleb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5267 DecCtx_BinaryFunc(mpd_qshift) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5268 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5269 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5270 ctx_mpd_same_quantum(PyObject *context, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5271 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5272 PyObject *v, *w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5273 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5274 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5275 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5276 if (!PyArg_ParseTuple(args, "OO", &v, &w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5277 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5278 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5279 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5280 CONVERT_BINOP_RAISE(&a, &b, v, w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5281 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5282 result = mpd_same_quantum(MPD(a), MPD(b)) ? incr_true() : incr_false(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5283 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5284 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5285 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5286 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5287 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5288 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5289 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5290 static PyMethodDef context_methods [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5291 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5292 /* Unary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5293 { "abs", ctx_mpd_qabs, METH_O, doc_ctx_abs }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5294 { "exp", ctx_mpd_qexp, METH_O, doc_ctx_exp }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5295 { "ln", ctx_mpd_qln, METH_O, doc_ctx_ln }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5296 { "log10", ctx_mpd_qlog10, METH_O, doc_ctx_log10 }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5297 { "minus", ctx_mpd_qminus, METH_O, doc_ctx_minus }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5298 { "next_minus", ctx_mpd_qnext_minus, METH_O, doc_ctx_next_minus }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5299 { "next_plus", ctx_mpd_qnext_plus, METH_O, doc_ctx_next_plus }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5300 { "normalize", ctx_mpd_qreduce, METH_O, doc_ctx_normalize }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5301 { "plus", ctx_mpd_qplus, METH_O, doc_ctx_plus }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5302 { "to_integral", ctx_mpd_qround_to_int, METH_O, doc_ctx_to_integral }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5303 { "to_integral_exact", ctx_mpd_qround_to_intx, METH_O, doc_ctx_to_integral_exact }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5304 { "to_integral_value", ctx_mpd_qround_to_int, METH_O, doc_ctx_to_integral_value }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5305 { "sqrt", ctx_mpd_qsqrt, METH_O, doc_ctx_sqrt }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5306 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5307 /* Binary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5308 { "add", ctx_mpd_qadd, METH_VARARGS, doc_ctx_add }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5309 { "compare", ctx_mpd_qcompare, METH_VARARGS, doc_ctx_compare }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5310 { "compare_signal", ctx_mpd_qcompare_signal, METH_VARARGS, doc_ctx_compare_signal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5311 { "divide", ctx_mpd_qdiv, METH_VARARGS, doc_ctx_divide }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5312 { "divide_int", ctx_mpd_qdivint, METH_VARARGS, doc_ctx_divide_int }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5313 { "divmod", ctx_mpd_qdivmod, METH_VARARGS, doc_ctx_divmod }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5314 { "max", ctx_mpd_qmax, METH_VARARGS, doc_ctx_max }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5315 { "max_mag", ctx_mpd_qmax_mag, METH_VARARGS, doc_ctx_max_mag }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5316 { "min", ctx_mpd_qmin, METH_VARARGS, doc_ctx_min }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5317 { "min_mag", ctx_mpd_qmin_mag, METH_VARARGS, doc_ctx_min_mag }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5318 { "multiply", ctx_mpd_qmul, METH_VARARGS, doc_ctx_multiply }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5319 { "next_toward", ctx_mpd_qnext_toward, METH_VARARGS, doc_ctx_next_toward }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5320 { "quantize", ctx_mpd_qquantize, METH_VARARGS, doc_ctx_quantize }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5321 { "remainder", ctx_mpd_qrem, METH_VARARGS, doc_ctx_remainder }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5322 { "remainder_near", ctx_mpd_qrem_near, METH_VARARGS, doc_ctx_remainder_near }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5323 { "subtract", ctx_mpd_qsub, METH_VARARGS, doc_ctx_subtract }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5324 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5325 /* Binary or ternary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5326 { "power", (PyCFunction)ctx_mpd_qpow, METH_VARARGS|METH_KEYWORDS, doc_ctx_power }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5327 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5328 /* Ternary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5329 { "fma", ctx_mpd_qfma, METH_VARARGS, doc_ctx_fma }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5330 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5331 /* No argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5332 { "Etiny", context_getetiny, METH_NOARGS, doc_ctx_Etiny }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5333 { "Etop", context_getetop, METH_NOARGS, doc_ctx_Etop }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5334 { "radix", ctx_mpd_radix, METH_NOARGS, doc_ctx_radix }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5335 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5336 /* Boolean functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5337 { "is_canonical", ctx_iscanonical, METH_O, doc_ctx_is_canonical }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5338 { "is_finite", ctx_mpd_isfinite, METH_O, doc_ctx_is_finite }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5339 { "is_infinite", ctx_mpd_isinfinite, METH_O, doc_ctx_is_infinite }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5340 { "is_nan", ctx_mpd_isnan, METH_O, doc_ctx_is_nan }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5341 { "is_normal", ctx_mpd_isnormal, METH_O, doc_ctx_is_normal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5342 { "is_qnan", ctx_mpd_isqnan, METH_O, doc_ctx_is_qnan }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5343 { "is_signed", ctx_mpd_issigned, METH_O, doc_ctx_is_signed }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5344 { "is_snan", ctx_mpd_issnan, METH_O, doc_ctx_is_snan }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5345 { "is_subnormal", ctx_mpd_issubnormal, METH_O, doc_ctx_is_subnormal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5346 { "is_zero", ctx_mpd_iszero, METH_O, doc_ctx_is_zero }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5347 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5348 /* Functions with a single decimal argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5349 { "_apply", PyDecContext_Apply, METH_O, NULL }, /* alias for apply */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5350 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5351 { "apply", PyDecContext_Apply, METH_O, doc_ctx_apply }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5352 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5353 { "canonical", ctx_canonical, METH_O, doc_ctx_canonical }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5354 { "copy_abs", ctx_mpd_qcopy_abs, METH_O, doc_ctx_copy_abs }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5355 { "copy_decimal", ctx_copy_decimal, METH_O, doc_ctx_copy_decimal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5356 { "copy_negate", ctx_mpd_qcopy_negate, METH_O, doc_ctx_copy_negate }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5357 { "logb", ctx_mpd_qlogb, METH_O, doc_ctx_logb }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5358 { "logical_invert", ctx_mpd_qinvert, METH_O, doc_ctx_logical_invert }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5359 { "number_class", ctx_mpd_class, METH_O, doc_ctx_number_class }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5360 { "to_sci_string", ctx_mpd_to_sci, METH_O, doc_ctx_to_sci_string }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5361 { "to_eng_string", ctx_mpd_to_eng, METH_O, doc_ctx_to_eng_string }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5362 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5363 /* Functions with two decimal arguments */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5364 { "compare_total", ctx_mpd_compare_total, METH_VARARGS, doc_ctx_compare_total }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5365 { "compare_total_mag", ctx_mpd_compare_total_mag, METH_VARARGS, doc_ctx_compare_total_mag }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5366 { "copy_sign", ctx_mpd_qcopy_sign, METH_VARARGS, doc_ctx_copy_sign }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5367 { "logical_and", ctx_mpd_qand, METH_VARARGS, doc_ctx_logical_and }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5368 { "logical_or", ctx_mpd_qor, METH_VARARGS, doc_ctx_logical_or }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5369 { "logical_xor", ctx_mpd_qxor, METH_VARARGS, doc_ctx_logical_xor }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5370 { "rotate", ctx_mpd_qrotate, METH_VARARGS, doc_ctx_rotate }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5371 { "same_quantum", ctx_mpd_same_quantum, METH_VARARGS, doc_ctx_same_quantum }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5372 { "scaleb", ctx_mpd_qscaleb, METH_VARARGS, doc_ctx_scaleb }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5373 { "shift", ctx_mpd_qshift, METH_VARARGS, doc_ctx_shift }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5374 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5375 /* Set context values */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5376 { "clear_flags", context_clear_flags, METH_NOARGS, doc_ctx_clear_flags }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5377 { "clear_traps", context_clear_traps, METH_NOARGS, doc_ctx_clear_traps }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5378 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5379 #ifdef CONFIG_32 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5380 /* Unsafe set functions with relaxed range checks */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5381 { "_unsafe_setprec", context_unsafe_setprec, METH_O, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5382 { "_unsafe_setemin", context_unsafe_setemin, METH_O, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5383 { "_unsafe_setemax", context_unsafe_setemax, METH_O, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5384 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5385 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5386 /* Miscellaneous */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5387 { "__copy__", (PyCFunction)context_copy, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5388 { "__reduce__", context_reduce, METH_NOARGS, NULL }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5389 { "copy", (PyCFunction)context_copy, METH_NOARGS, doc_ctx_copy }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5390 { "create_decimal", ctx_create_decimal, METH_VARARGS, doc_ctx_create_decimal }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5391 { "create_decimal_from_float", ctx_from_float, METH_O, doc_ctx_create_decimal_from_float }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5392 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5393 { NULL, NULL, 1 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5394 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5395 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5396 static PyTypeObject PyDecContext_Type = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5397 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5398 PyVarObject_HEAD_INIT(NULL, 0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5399 "decimal.Context", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5400 sizeof(PyDecContextObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5401 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5402 (destructor) context_dealloc, /* tp_dealloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5403 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5404 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5405 (setattrfunc) 0, /* tp_setattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5406 0, /* tp_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5407 (reprfunc) context_repr, /* tp_repr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5408 0, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5409 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5410 0, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5411 (hashfunc) 0, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5412 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5413 (reprfunc) context_repr, /* tp_str */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5414 (getattrofunc) context_getattr, /* tp_getattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5415 (setattrofunc) context_setattr, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5416 (PyBufferProcs *) 0, /* tp_as_buffer */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5417 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5418 doc_context, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5419 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5420 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5421 0, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5422 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5423 0, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5424 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5425 context_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5426 0, /* tp_members */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5427 context_getsets, /* tp_getset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5428 0, /* tp_base */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5429 0, /* tp_dict */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5430 0, /* tp_descr_get */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5431 0, /* tp_descr_set */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5432 0, /* tp_dictoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5433 context_init, /* tp_init */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5434 0, /* tp_alloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5435 context_new, /* tp_new */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5436 PyObject_Del, /* tp_free */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5437 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5438 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5439 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5440 static PyMethodDef _decimal_methods [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5441 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5442 { "getcontext", (PyCFunction)PyDec_GetCurrentContext, METH_NOARGS, doc_getcontext}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5443 { "setcontext", (PyCFunction)PyDec_SetCurrentContext, METH_O, doc_setcontext}, |
|
80872
29becac5dd9b
Issue #15783: Except for the number methods, the C version of decimal now
Stefan Krah <skrah@bytereef.org>
parents:
80342
diff
changeset
|
5444 { "localcontext", (PyCFunction)ctxmanager_new, METH_VARARGS|METH_KEYWORDS, doc_localcontext}, |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5445 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5446 { "IEEEContext", (PyCFunction)ieee_context, METH_O, doc_ieee_context}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5447 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5448 { NULL, NULL, 1, NULL } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5449 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5450 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5451 static struct PyModuleDef _decimal_module = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5452 PyModuleDef_HEAD_INIT, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5453 "decimal", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5454 doc__decimal, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5455 -1, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5456 _decimal_methods, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5457 NULL, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5458 NULL, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5459 NULL, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5460 NULL |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5461 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5462 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5463 struct ssize_constmap { const char *name; mpd_ssize_t val; }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5464 static struct ssize_constmap ssize_constants [] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5465 {"MAX_PREC", MPD_MAX_PREC}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5466 {"MAX_EMAX", MPD_MAX_EMAX}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5467 {"MIN_EMIN", MPD_MIN_EMIN}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5468 {"MIN_ETINY", MPD_MIN_ETINY}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5469 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5470 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5471 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5472 struct int_constmap { const char *name; int val; }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5473 static struct int_constmap int_constants [] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5474 /* int constants */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5475 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5476 {"DECIMAL32", MPD_DECIMAL32}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5477 {"DECIMAL64", MPD_DECIMAL64}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5478 {"DECIMAL128", MPD_DECIMAL128}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5479 {"IEEE_CONTEXT_MAX_BITS", MPD_IEEE_CONTEXT_MAX_BITS}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5480 /* int condition flags */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5481 {"DecClamped", MPD_Clamped}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5482 {"DecConversionSyntax", MPD_Conversion_syntax}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5483 {"DecDivisionByZero", MPD_Division_by_zero}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5484 {"DecDivisionImpossible", MPD_Division_impossible}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5485 {"DecDivisionUndefined", MPD_Division_undefined}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5486 {"DecFpuError", MPD_Fpu_error}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5487 {"DecInexact", MPD_Inexact}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5488 {"DecInvalidContext", MPD_Invalid_context}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5489 {"DecInvalidOperation", MPD_Invalid_operation}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5490 {"DecIEEEInvalidOperation", MPD_IEEE_Invalid_operation}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5491 {"DecMallocError", MPD_Malloc_error}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5492 {"DecFloatOperation", MPD_Float_operation}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5493 {"DecOverflow", MPD_Overflow}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5494 {"DecRounded", MPD_Rounded}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5495 {"DecSubnormal", MPD_Subnormal}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5496 {"DecUnderflow", MPD_Underflow}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5497 {"DecErrors", MPD_Errors}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5498 {"DecTraps", MPD_Traps}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5499 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5500 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5501 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5502 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5503 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5504 #define CHECK_INT(expr) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5505 do { if ((expr) < 0) goto error; } while (0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5506 #define ASSIGN_PTR(result, expr) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5507 do { result = (expr); if (result == NULL) goto error; } while (0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5508 #define CHECK_PTR(expr) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5509 do { if ((expr) == NULL) goto error; } while (0) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5510 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5511 PyMODINIT_FUNC |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5512 PyInit__decimal(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5513 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5514 PyObject *m = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5515 PyObject *numbers = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5516 PyObject *Number = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5517 PyObject *collections = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5518 PyObject *MutableMapping = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5519 PyObject *obj = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5520 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5521 struct ssize_constmap *ssize_cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5522 struct int_constmap *int_cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5523 int i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5524 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5525 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5526 /* Init libmpdec */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5527 mpd_traphandler = dec_traphandler; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5528 mpd_mallocfunc = PyMem_Malloc; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5529 mpd_reallocfunc = PyMem_Realloc; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5530 mpd_callocfunc = mpd_callocfunc_em; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5531 mpd_free = PyMem_Free; |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
5532 mpd_setminalloc(_Py_DEC_MINALLOC); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5533 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5534 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5535 /* Init types */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5536 PyDec_Type.tp_base = &PyBaseObject_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5537 PyDecContext_Type.tp_base = &PyBaseObject_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5538 PyDecContextManager_Type.tp_base = &PyBaseObject_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5539 PyDecSignalDictMixin_Type.tp_base = &PyBaseObject_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5540 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5541 CHECK_INT(PyType_Ready(&PyDec_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5542 CHECK_INT(PyType_Ready(&PyDecContext_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5543 CHECK_INT(PyType_Ready(&PyDecSignalDictMixin_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5544 CHECK_INT(PyType_Ready(&PyDecContextManager_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5545 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5546 ASSIGN_PTR(obj, PyUnicode_FromString("decimal")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5547 CHECK_INT(PyDict_SetItemString(PyDec_Type.tp_dict, "__module__", obj)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5548 CHECK_INT(PyDict_SetItemString(PyDecContext_Type.tp_dict, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5549 "__module__", obj)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5550 Py_CLEAR(obj); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5551 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5552 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5553 /* Numeric abstract base classes */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5554 ASSIGN_PTR(numbers, PyImport_ImportModule("numbers")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5555 ASSIGN_PTR(Number, PyObject_GetAttrString(numbers, "Number")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5556 /* Register Decimal with the Number abstract base class */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5557 ASSIGN_PTR(obj, PyObject_CallMethod(Number, "register", "(O)", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5558 (PyObject *)&PyDec_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5559 Py_CLEAR(obj); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5560 /* Rational is a global variable used for fraction comparisons. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5561 ASSIGN_PTR(Rational, PyObject_GetAttrString(numbers, "Rational")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5562 /* Done with numbers, Number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5563 Py_CLEAR(numbers); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5564 Py_CLEAR(Number); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5565 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5566 /* DecimalTuple */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5567 ASSIGN_PTR(collections, PyImport_ImportModule("collections")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5568 ASSIGN_PTR(DecimalTuple, PyObject_CallMethod(collections, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5569 "namedtuple", "(ss)", "DecimalTuple", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5570 "sign digits exponent")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5571 /* MutableMapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5572 ASSIGN_PTR(MutableMapping, PyObject_GetAttrString(collections, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5573 "MutableMapping")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5574 /* Create SignalDict type */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5575 ASSIGN_PTR(PyDecSignalDict_Type, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5576 (PyTypeObject *)PyObject_CallFunction( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5577 (PyObject *)&PyType_Type, "s(OO){}", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5578 "SignalDict", &PyDecSignalDictMixin_Type, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5579 MutableMapping)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5580 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5581 /* Done with collections, MutableMapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5582 Py_CLEAR(collections); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5583 Py_CLEAR(MutableMapping); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5584 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5585 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5586 /* Create the module */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5587 ASSIGN_PTR(m, PyModule_Create(&_decimal_module)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5588 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5589 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5590 /* Add types to the module */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5591 Py_INCREF(&PyDec_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5592 CHECK_INT(PyModule_AddObject(m, "Decimal", (PyObject *)&PyDec_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5593 Py_INCREF(&PyDecContext_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5594 CHECK_INT(PyModule_AddObject(m, "Context", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5595 (PyObject *)&PyDecContext_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5596 Py_INCREF(DecimalTuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5597 CHECK_INT(PyModule_AddObject(m, "DecimalTuple", DecimalTuple)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5598 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5599 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5600 /* Create top level exception */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5601 ASSIGN_PTR(DecimalException, PyErr_NewException( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5602 "decimal.DecimalException", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5603 PyExc_ArithmeticError, NULL)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5604 Py_INCREF(DecimalException); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5605 CHECK_INT(PyModule_AddObject(m, "DecimalException", DecimalException)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5606 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5607 /* Create signal tuple */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5608 ASSIGN_PTR(SignalTuple, PyTuple_New(SIGNAL_MAP_LEN)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5609 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5610 /* Add exceptions that correspond to IEEE signals */ |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5611 for (i = SIGNAL_MAP_LEN-1; i >= 0; i--) { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5612 PyObject *base; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5613 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5614 cm = signal_map + i; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5615 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5616 switch (cm->flag) { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5617 case MPD_Float_operation: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5618 base = PyTuple_Pack(2, DecimalException, PyExc_TypeError); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5619 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5620 case MPD_Division_by_zero: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5621 base = PyTuple_Pack(2, DecimalException, PyExc_ZeroDivisionError); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5622 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5623 case MPD_Overflow: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5624 base = PyTuple_Pack(2, signal_map[INEXACT].ex, |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5625 signal_map[ROUNDED].ex); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5626 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5627 case MPD_Underflow: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5628 base = PyTuple_Pack(3, signal_map[INEXACT].ex, |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5629 signal_map[ROUNDED].ex, |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5630 signal_map[SUBNORMAL].ex); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5631 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5632 default: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5633 base = PyTuple_Pack(1, DecimalException); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5634 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5635 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5636 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5637 if (base == NULL) { |
|
83979
8a77d7019559
Backport bff16086f03b and bcaaaa00425b.
Stefan Krah <skrah@bytereef.org>
parents:
83974
diff
changeset
|
5638 goto error; /* GCOV_NOT_REACHED */ |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5639 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5640 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5641 ASSIGN_PTR(cm->ex, PyErr_NewException((char *)cm->fqname, base, NULL)); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5642 Py_DECREF(base); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5643 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5644 /* add to module */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5645 Py_INCREF(cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5646 CHECK_INT(PyModule_AddObject(m, cm->name, cm->ex)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5647 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5648 /* add to signal tuple */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5649 Py_INCREF(cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5650 PyTuple_SET_ITEM(SignalTuple, i, cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5651 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5652 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5653 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5654 * Unfortunately, InvalidOperation is a signal that comprises |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5655 * several conditions, including InvalidOperation! Naming the |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5656 * signal IEEEInvalidOperation would prevent the confusion. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5657 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5658 cond_map[0].ex = signal_map[0].ex; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5659 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5660 /* Add remaining exceptions, inherit from InvalidOperation */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5661 for (cm = cond_map+1; cm->name != NULL; cm++) { |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5662 PyObject *base; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5663 if (cm->flag == MPD_Division_undefined) { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5664 base = PyTuple_Pack(2, signal_map[0].ex, PyExc_ZeroDivisionError); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5665 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5666 else { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5667 base = PyTuple_Pack(1, signal_map[0].ex); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5668 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5669 if (base == NULL) { |
|
83979
8a77d7019559
Backport bff16086f03b and bcaaaa00425b.
Stefan Krah <skrah@bytereef.org>
parents:
83974
diff
changeset
|
5670 goto error; /* GCOV_NOT_REACHED */ |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5671 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5672 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5673 ASSIGN_PTR(cm->ex, PyErr_NewException((char *)cm->fqname, base, NULL)); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5674 Py_DECREF(base); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5675 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5676 Py_INCREF(cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5677 CHECK_INT(PyModule_AddObject(m, cm->name, cm->ex)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5678 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5679 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5680 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5681 /* Init default context template first */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5682 ASSIGN_PTR(default_context_template, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5683 PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5684 Py_INCREF(default_context_template); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5685 CHECK_INT(PyModule_AddObject(m, "DefaultContext", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5686 default_context_template)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5687 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5688 #ifdef WITHOUT_THREADS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5689 /* Init module context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5690 ASSIGN_PTR(module_context, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5691 PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5692 Py_INCREF(Py_False); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5693 CHECK_INT(PyModule_AddObject(m, "HAVE_THREADS", Py_False)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5694 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5695 ASSIGN_PTR(tls_context_key, PyUnicode_FromString("___DECIMAL_CTX__")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5696 Py_INCREF(Py_True); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5697 CHECK_INT(PyModule_AddObject(m, "HAVE_THREADS", Py_True)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5698 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5699 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5700 /* Init basic context template */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5701 ASSIGN_PTR(basic_context_template, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5702 PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5703 init_basic_context(basic_context_template); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5704 Py_INCREF(basic_context_template); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5705 CHECK_INT(PyModule_AddObject(m, "BasicContext", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5706 basic_context_template)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5707 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5708 /* Init extended context template */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5709 ASSIGN_PTR(extended_context_template, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5710 PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5711 init_extended_context(extended_context_template); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5712 Py_INCREF(extended_context_template); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5713 CHECK_INT(PyModule_AddObject(m, "ExtendedContext", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5714 extended_context_template)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5715 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5716 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5717 /* Init mpd_ssize_t constants */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5718 for (ssize_cm = ssize_constants; ssize_cm->name != NULL; ssize_cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5719 ASSIGN_PTR(obj, PyLong_FromSsize_t(ssize_cm->val)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5720 CHECK_INT(PyModule_AddObject(m, ssize_cm->name, obj)); |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5721 obj = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5722 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5723 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5724 /* Init int constants */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5725 for (int_cm = int_constants; int_cm->name != NULL; int_cm++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5726 CHECK_INT(PyModule_AddIntConstant(m, int_cm->name, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5727 int_cm->val)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5728 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5729 |
|
81538
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5730 /* Init string constants */ |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5731 for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) { |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5732 ASSIGN_PTR(round_map[i], PyUnicode_InternFromString(mpd_round_string[i])); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5733 Py_INCREF(round_map[i]); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5734 CHECK_INT(PyModule_AddObject(m, mpd_round_string[i], round_map[i])); |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5735 } |
|
733bb4fd9888
Issue #16422: Use strings for rounding mode constants for better readability
Stefan Krah <skrah@bytereef.org>
parents:
80972
diff
changeset
|
5736 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5737 /* Add specification version number */ |
|
87517
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
5738 CHECK_INT(PyModule_AddStringConstant(m, "__version__", "1.70")); |
|
cbd78679080b
1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
Stefan Krah <skrah@bytereef.org>
parents:
87018
diff
changeset
|
5739 CHECK_INT(PyModule_AddStringConstant(m, "__libmpdec_version__", mpd_version())); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5740 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5741 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5742 return m; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5743 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5744 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5745 error: |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5746 Py_CLEAR(obj); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5747 Py_CLEAR(numbers); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5748 Py_CLEAR(Number); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5749 Py_CLEAR(Rational); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5750 Py_CLEAR(collections); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5751 Py_CLEAR(MutableMapping); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5752 Py_CLEAR(SignalTuple); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5753 Py_CLEAR(DecimalTuple); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5754 #ifdef WITHOUT_THREADS |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5755 Py_CLEAR(module_context); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5756 #else |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5757 Py_CLEAR(default_context_template); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5758 Py_CLEAR(tls_context_key); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5759 #endif |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5760 Py_CLEAR(basic_context_template); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5761 Py_CLEAR(extended_context_template); /* GCOV_NOT_REACHED */ |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5762 Py_CLEAR(m); /* GCOV_NOT_REACHED */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5763 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5764 return NULL; /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5765 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5766 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5767 |
