Mercurial > cpython-lru_cache-weakref
annotate Modules/_decimal/_decimal.c @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | 97e53273f423 |
| children | 1b6c972457e6 |
| 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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
42 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
43 * 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
|
44 * 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
|
45 * 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
|
46 */ |
|
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 #ifdef TEST_COVERAGE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
49 #undef Py_LOCAL_INLINE |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
50 #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
|
51 #endif |
|
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 #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
|
54 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
55 #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
|
56 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
57 |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
58 /* _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
|
59 #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
|
60 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
61 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 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
|
66 } PyDecObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
67 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
68 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
69 PyObject_HEAD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
70 uint32_t *flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
71 } PyDecSignalDictObject; |
|
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 mpd_context_t ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
76 PyObject *traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
77 PyObject *flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
78 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
|
79 #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
|
80 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
|
81 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
82 } PyDecContextObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
83 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
84 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
85 PyObject_HEAD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
86 PyObject *local; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
87 PyObject *global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
88 } PyDecContextManagerObject; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
89 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
90 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
91 #undef MPD |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
92 #undef CTX |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
93 static PyTypeObject PyDec_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
94 static PyTypeObject *PyDecSignalDict_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
95 static PyTypeObject PyDecContext_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
96 static PyTypeObject PyDecContextManager_Type; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
97 #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
|
98 #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
|
99 #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
|
100 #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
|
101 #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
|
102 #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
|
103 #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
|
104 #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
|
105 #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
|
106 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
107 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
108 Py_LOCAL_INLINE(PyObject *) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
109 incr_true(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
110 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
111 Py_INCREF(Py_True); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
112 return Py_True; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
113 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
114 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
115 Py_LOCAL_INLINE(PyObject *) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
116 incr_false(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
117 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
118 Py_INCREF(Py_False); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
119 return Py_False; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
120 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
121 |
|
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 #ifdef WITHOUT_THREADS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
124 /* Default module context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
125 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
|
126 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
127 /* 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
|
128 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
|
129 /* 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
|
130 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
|
131 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
132 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
133 /* 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
|
134 * 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
|
135 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
|
136 /* 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
|
137 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
|
138 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
|
139 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
140 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
141 /* 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
|
142 #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
|
143 #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
|
144 #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
|
145 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
146 typedef struct { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 PyObject *ex; /* corresponding exception */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
151 } DecCondMap; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
152 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
153 /* 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
|
154 static PyObject *DecimalException = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
155 |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
156 /* 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
|
157 #define SUBNORMAL 5 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
158 #define INEXACT 6 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
159 #define ROUNDED 7 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
160 #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
|
161 static DecCondMap signal_map[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
162 {"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
|
163 {"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
|
164 {"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
|
165 {"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
|
166 {"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
|
167 {"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
|
168 {"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
|
169 {"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
|
170 {"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
|
171 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
172 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
173 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
174 /* 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
|
175 static DecCondMap cond_map[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
176 {"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
|
177 {"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
|
178 {"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
|
179 {"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
|
180 {"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
|
181 #ifdef EXTRA_FUNCTIONALITY |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
182 {"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
|
183 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
184 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
185 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
186 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
187 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
|
188 "Clamped", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
189 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
190 "DivisionByZero", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
191 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
192 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
193 "InvalidOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
194 "Inexact", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
195 "InvalidOperation", |
|
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 "FloatOperation", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
199 "Overflow", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
200 "Rounded", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
201 "Subnormal", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
202 "Underflow", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
203 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
204 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
205 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
|
206 "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
|
207 [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
|
208 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
|
209 ROUND_05UP]"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
210 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
211 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
|
212 "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
|
213 [InvalidOperation, FloatOperation, DivisionByZero,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
214 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
|
215 Clamped]"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
216 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
217 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
218 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
|
219 "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
|
220 signals:\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
221 [DecIEEEInvalidOperation, DecFloatOperation, DecDivisionByZero,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
222 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
|
223 DecClamped]\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
224 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
|
225 [DecInvalidOperation, DecConversionSyntax, DecDivisionImpossible,\n\ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
226 DecDivisionUndefined, DecFpuError, DecInvalidContext, DecMallocError]"; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
227 #endif |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
230 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
|
231 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
232 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
|
233 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
234 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
235 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
236 #ifdef CONFIG_32 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
237 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
238 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
|
239 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
240 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
|
241 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
242 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
243 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
244 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
245 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
246 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
|
247 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
248 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
|
249 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
250 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
253 type_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
|
254 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
255 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
|
256 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
257 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
258 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
259 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
260 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
|
261 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
262 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
|
263 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
264 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
265 #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
|
266 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
|
267 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
268 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
269 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
|
270 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
271 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
|
272 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
273 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
274 #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
|
275 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
|
276 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
277 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
278 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
|
279 { /* GCOV_NOT_REACHED */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
280 return; /* GCOV_NOT_REACHED */ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
283 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
284 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
|
285 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
286 DecCondMap *cm; |
|
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 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
|
289 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
290 return cm->ex; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
291 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
294 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
|
295 } |
|
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 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
|
298 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
|
299 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
300 DecCondMap *cm; |
|
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 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
|
303 if (cm->ex == ex) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
304 return cm->flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
305 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
308 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
|
309 return DEC_INVALID_SIGNALS; |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
313 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
|
314 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
315 PyObject *list; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
316 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
317 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
318 list = PyList_New(0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
319 if (list == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
320 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
321 } |
|
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 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
|
324 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
325 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
|
326 goto error; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
329 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
330 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
|
331 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
332 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
|
333 goto error; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
336 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
337 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
338 return list; |
|
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 error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
341 Py_DECREF(list); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
342 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
343 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
346 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
|
347 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
348 PyObject *list; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
349 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
350 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
351 list = PyList_New(0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
352 if (list == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
353 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
354 } |
|
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 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
|
357 if (flags&cm->flag) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
358 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
|
359 Py_DECREF(list); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
360 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
361 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
362 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
363 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
364 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
365 return list; |
|
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 static uint32_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
369 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
|
370 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
371 PyObject *item; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
372 uint32_t flags, x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
373 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
|
374 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
375 assert(PyList_Check(list)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
376 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
377 n = PyList_Size(list); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
378 flags = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 if (x & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
383 return x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
384 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
385 flags |= x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
386 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
387 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
388 return flags; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
391 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
392 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
|
393 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
394 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
395 PyObject *dict; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
396 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
397 dict = PyDict_New(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
398 if (dict == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
399 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
400 } |
|
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 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
|
403 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
|
404 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
|
405 Py_DECREF(dict); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
406 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
407 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
408 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
409 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
410 return dict; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
411 } |
|
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 static uint32_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
414 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
|
415 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
416 PyObject *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
417 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
418 uint32_t flags = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
419 int x; |
|
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 if (!PyDict_Check(val)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
422 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
423 "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
|
424 return DEC_INVALID_SIGNALS; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
427 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
|
428 PyErr_SetString(PyExc_KeyError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
429 "invalid signal dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
430 return DEC_INVALID_SIGNALS; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
433 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
|
434 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
|
435 if (b == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
436 if (PyErr_Occurred()) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
437 return DEC_ERR_OCCURRED; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
438 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
439 PyErr_SetString(PyExc_KeyError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
440 "invalid signal dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
441 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
442 } |
|
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 x = PyObject_IsTrue(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
445 if (x < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
446 return DEC_ERR_OCCURRED; |
|
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 if (x == 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
449 flags |= cm->flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
450 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
451 } |
|
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 return flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
454 } |
|
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 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
457 static uint32_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
458 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
|
459 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
460 long x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
461 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
462 x = PyLong_AsLong(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
463 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
|
464 return DEC_ERR_OCCURRED; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
465 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
466 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
|
467 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
|
468 return DEC_INVALID_SIGNALS; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
469 } |
|
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 return x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
472 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
473 #endif |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
476 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
|
477 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
478 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
|
479 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
480 ctx->status |= status; |
|
75923
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
481 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
|
482 PyObject *ex, *siglist; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
483 |
|
75923
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
484 if (status & MPD_Malloc_error) { |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
485 PyErr_NoMemory(); |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
486 return 1; |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
487 } |
|
0ed7da703a33
Raise MemoryError instead of InvalidOperation/MallocError for compatibility
Stefan Krah <skrah@bytereef.org>
parents:
75899
diff
changeset
|
488 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
489 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
|
490 if (ex == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
491 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
|
492 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
493 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
|
494 if (siglist == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
495 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
496 } |
|
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 PyErr_SetObject(ex, siglist); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
499 Py_DECREF(siglist); |
|
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 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
503 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
504 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
505 |
|
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 /* SignalDict Object */ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
510 /* 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
516 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
517 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
|
518 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
519 SdFlagAddr(self) = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
520 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
521 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
522 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
523 static Py_ssize_t |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
524 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
|
525 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
526 return SIGNAL_MAP_LEN; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
527 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
528 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
529 static PyObject *SignalTuple; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
530 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
531 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
|
532 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
533 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
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
537 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
|
538 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
539 uint32_t flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
540 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
541 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
|
542 if (flag & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
543 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
546 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
|
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 int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
550 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
|
551 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
552 uint32_t flag; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
553 int x; |
|
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 if (value == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
556 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
|
557 } |
|
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 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
|
560 if (flag & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
561 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
562 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
563 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
564 x = PyObject_IsTrue(value); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
565 if (x < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
566 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
567 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
568 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
569 if (x == 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
570 SdFlags(self) |= flag; |
|
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 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
573 SdFlags(self) &= ~flag; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
576 return 0; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
579 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
580 signaldict_repr(PyObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
581 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
582 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
583 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
|
584 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
|
585 int i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
586 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
587 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
|
588 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
589 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
|
590 n[i] = cm->fqname; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
591 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
|
592 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
593 return PyUnicode_FromFormat( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
594 "{<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
|
595 "<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
|
596 "<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
|
597 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
|
598 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
|
599 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
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
603 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
|
604 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
605 PyObject *res = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
606 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
607 assert(PyDecSignalDict_Check(v)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
608 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
609 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
|
610 if (PyDecSignalDict_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
611 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
|
612 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
613 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
|
614 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
|
615 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
616 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
|
617 /* non-comparable: Py_NotImplemented */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
618 PyErr_Clear(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
619 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
620 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
621 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
622 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
623 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
624 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
625 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
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
629 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
630 Py_INCREF(res); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
631 return res; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
634 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
|
635 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
|
636 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
637 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
|
638 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
639 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
640 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
641 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
|
642 (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
|
643 (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
|
644 (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
|
645 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
646 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
647 static PyMethodDef signaldict_methods[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
648 { "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
|
649 {NULL, NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
650 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
651 |
|
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 static PyTypeObject PyDecSignalDictMixin_Type = |
|
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 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
|
656 "decimal.SignalDictMixin", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
657 sizeof(PyDecSignalDictObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
658 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
659 0, /* tp_dealloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
660 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
661 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
662 (setattrfunc) 0, /* tp_setattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
663 0, /* tp_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
664 (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
|
665 0, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
666 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
667 &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
|
668 PyObject_HashNotImplemented, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
669 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
670 (reprfunc) 0, /* tp_str */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
671 PyObject_GenericGetAttr, /* tp_getattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
672 (setattrofunc) 0, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
673 (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
|
674 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
|
675 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
|
676 0, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
677 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
678 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
679 signaldict_richcompare, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
680 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
681 (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
|
682 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
683 signaldict_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
684 0, /* tp_members */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
685 0, /* tp_getset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
686 0, /* tp_base */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
687 0, /* tp_dict */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
688 0, /* tp_descr_get */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
689 0, /* tp_descr_set */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
690 0, /* tp_dictoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
691 (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
|
692 0, /* tp_alloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
693 PyType_GenericNew, /* tp_new */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
694 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
695 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
696 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
697 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
698 /* Context Object, Part 1 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
699 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
700 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
701 #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
|
702 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
703 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
|
704 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
705 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
|
706 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
707 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
708 #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
|
709 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
710 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
|
711 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
712 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
|
713 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
714 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
715 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
|
716 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
|
717 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
|
718 Dec_CONTEXT_GET_SSIZE(round) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
719 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
|
720 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
721 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
722 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
|
723 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
|
724 #endif |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
727 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
|
728 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
729 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
|
730 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
731 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
732 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
733 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
734 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
|
735 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
736 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
|
737 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
738 #endif |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
741 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
|
742 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
743 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
|
744 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
747 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
|
748 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
749 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
|
750 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
751 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
752 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
753 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
|
754 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
755 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
756 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
757 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
758 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
|
759 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
|
760 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
761 } |
|
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 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
764 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
|
765 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
766 "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
|
767 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
768 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
769 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
770 } |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
773 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
|
774 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
775 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
776 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
777 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
778 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
|
779 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
|
780 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
781 } |
|
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 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
784 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
|
785 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
786 "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
|
787 } |
|
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 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
790 } |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
793 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
|
794 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
795 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
796 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
797 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
798 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
|
799 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
|
800 return -1; |
|
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 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
804 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
|
805 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
806 "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
|
807 } |
|
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 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
810 } |
|
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 #ifdef CONFIG_32 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
813 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
814 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
|
815 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
816 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
|
817 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
818 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
819 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
|
820 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
|
821 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
824 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
|
825 return value_error_ptr( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
826 "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
|
827 } |
|
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 ctx->prec = x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
830 Py_RETURN_NONE; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
833 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
834 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
|
835 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
836 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
|
837 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
838 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
839 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
|
840 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
|
841 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
844 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
|
845 return value_error_ptr( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
846 "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
|
847 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
848 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
849 ctx->emin = x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
850 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
851 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
854 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
|
855 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
856 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
|
857 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
858 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
859 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
|
860 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
|
861 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
864 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
|
865 return value_error_ptr( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
866 "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
|
867 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
868 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
869 ctx->emax = x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
870 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
871 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
872 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
873 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
874 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
875 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
|
876 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
877 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
878 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
879 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
880 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
|
881 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
|
882 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
883 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
884 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
|
885 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
886 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
887 if (!mpd_qsetround(ctx, (int)x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
888 return type_error_int(invalid_rounding_err); |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
891 return 0; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
894 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
895 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
|
896 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
897 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
898 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
899 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
|
900 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
|
901 return -1; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
904 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
|
905 return value_error_int( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
906 "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
|
907 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
908 CtxCaps(self) = (int)x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
909 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
910 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
911 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
912 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
913 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
914 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
915 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
|
916 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
917 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
918 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
919 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
920 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
|
921 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
922 return -1; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
925 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
926 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
|
927 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
|
928 } |
|
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 return 0; |
|
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 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
933 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
934 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
935 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
|
936 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
937 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
938 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
939 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
940 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
|
941 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
942 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
943 } |
|
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 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
946 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
|
947 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
|
948 } |
|
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 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
951 } |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
954 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
|
955 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
956 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
957 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
958 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
959 if (PyDecSignalDict_Check(value)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
960 flags = SdFlags(value); |
|
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 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
963 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
|
964 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
965 return -1; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
968 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
969 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
970 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
|
971 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
|
972 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
973 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
974 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
975 } |
|
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 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
978 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
979 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
|
980 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
981 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
982 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
983 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
984 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
|
985 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
986 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
987 } |
|
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 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
990 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
|
991 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
|
992 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
993 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
994 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
995 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
996 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
997 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
998 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
999 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
|
1000 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1001 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1002 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1003 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1004 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
|
1005 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1006 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1007 } |
|
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 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1010 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
|
1011 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
|
1012 } |
|
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 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1015 } |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1018 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
|
1019 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1020 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1021 uint32_t flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1022 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1023 if (PyDecSignalDict_Check(value)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1024 flags = SdFlags(value); |
|
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 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1027 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
|
1028 if (flags & DEC_ERRORS) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1029 return -1; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1032 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1033 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1034 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
|
1035 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
|
1036 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1037 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1038 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1039 } |
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1042 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
|
1043 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1044 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1045 mpd_ssize_t x; |
|
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 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
|
1048 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
|
1049 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1050 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1051 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
|
1052 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1053 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1054 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
|
1055 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
|
1056 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1057 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1058 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1059 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1060 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1061 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1062 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1063 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
|
1064 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1065 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1066 mpd_ssize_t x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1067 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1068 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
|
1069 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
|
1070 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1071 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1072 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
|
1073 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1074 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1075 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
|
1076 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
|
1077 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1078 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1079 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1080 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1081 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1082 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1083 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1084 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
|
1085 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1086 PyObject *retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1087 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1088 if (PyUnicode_Check(name)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1089 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
|
1090 retval = ((PyDecContextObject *)self)->traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1091 Py_INCREF(retval); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1092 return retval; |
|
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 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
|
1095 retval = ((PyDecContextObject *)self)->flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1096 Py_INCREF(retval); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1097 return retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1098 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1099 } |
|
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 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
|
1102 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1103 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1104 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1105 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
|
1106 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1107 if (value == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1108 PyErr_SetString(PyExc_AttributeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1109 "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
|
1110 return -1; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1113 if (PyUnicode_Check(name)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1114 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
|
1115 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
|
1116 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1117 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
|
1118 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
|
1119 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1122 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
|
1123 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1124 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1125 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1126 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
|
1127 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1128 CTX(self)->traps = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1129 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1130 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1133 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
|
1134 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1135 CTX(self)->status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1136 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1137 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1138 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1139 #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
|
1140 #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
|
1141 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1142 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
|
1143 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
|
1144 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
|
1145 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
|
1146 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1147 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1148 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1149 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
|
1150 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1151 PyDecContextObject *self = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1152 mpd_context_t *ctx; |
|
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 if (type == &PyDecContext_Type) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1155 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
|
1156 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1157 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1158 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
|
1159 } |
|
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 if (self == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1162 return NULL; |
|
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 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
|
1166 if (self->traps == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1167 self->flags = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1168 Py_DECREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1169 return NULL; |
|
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 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
|
1172 if (self->flags == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1173 Py_DECREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1174 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1175 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1176 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1177 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1178 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1179 if (default_context_template) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1180 *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
|
1181 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1182 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1183 *ctx = dflt_ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1184 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1185 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1186 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
|
1187 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
|
1188 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1189 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
|
1190 #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
|
1191 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
|
1192 #endif |
|
75850
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 return (PyObject *)self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1195 } |
|
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 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1198 context_dealloc(PyDecContextObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1199 { |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1200 #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
|
1201 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
|
1202 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
|
1203 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1204 #endif |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1205 Py_XDECREF(self->traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1206 Py_XDECREF(self->flags); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1207 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
|
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 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1211 getround(PyObject *v) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1212 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1213 const char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1214 long x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1215 int i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1216 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1217 if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1218 x = PyLong_AsLong(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1219 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
|
1220 return -1; |
|
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 BOUNDS_CHECK(x, 0, INT_MAX); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1223 return (int)x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1224 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1225 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
|
1226 for (i = 0; i < MPD_ROUND_GUARD; i++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1227 s = mpd_round_string[i]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1228 if (PyUnicode_CompareWithASCIIString(v, s) == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1229 return i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1230 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1231 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1232 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1233 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1234 return type_error_int("invalid rounding mode"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1235 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1236 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1237 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1238 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
|
1239 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1240 static char *kwlist[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1241 "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
|
1242 "flags", "traps", NULL |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1243 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1244 PyObject *rounding = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1245 PyObject *traps = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1246 PyObject *status = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1247 mpd_context_t *ctx, t; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1248 int capitals = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1249 int ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1250 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1251 assert(PyTuple_Check(args)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1252 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1253 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1254 t = *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1255 if (!PyArg_ParseTupleAndKeywords( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1256 args, kwds, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1257 "|nOnniiOO", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1258 &t.prec, &rounding, &t.emin, &t.emax, &capitals, &t.clamp, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1259 &status, &traps |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1260 )) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1261 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1262 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1263 if (rounding != NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1264 t.round = getround(rounding); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1265 if (t.round < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1266 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1267 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1268 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1269 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1270 if (!mpd_qsetprec(ctx, t.prec) || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1271 !mpd_qsetemin(ctx, t.emin) || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1272 !mpd_qsetemax(ctx, t.emax) || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1273 !mpd_qsetclamp(ctx, t.clamp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1274 return value_error_int("invalid context"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1275 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1276 if (!mpd_qsetround(ctx, t.round) || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1277 !mpd_qsettraps(ctx, t.traps) || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1278 !mpd_qsetstatus(ctx, t.status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1279 return type_error_int("invalid context"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1280 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1281 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1282 if (capitals != 0 && capitals != 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1283 return value_error_int("invalid context"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1284 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1285 CtxCaps(self) = capitals; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1286 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1287 if (traps != NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1288 if (PyList_Check(traps)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1289 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
|
1290 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1291 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1292 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
|
1293 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
|
1294 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1295 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1296 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1297 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
|
1298 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1299 if (ret < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1300 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1301 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1302 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1303 if (status != NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1304 if (PyList_Check(status)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1305 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
|
1306 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1307 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1308 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
|
1309 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
|
1310 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1311 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1312 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1313 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
|
1314 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1315 if (ret < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1316 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1317 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1318 } |
|
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 return 0; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1323 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1324 context_repr(PyDecContextObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1325 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1326 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1327 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
|
1328 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
|
1329 int n, mem; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1330 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1331 assert(PyDecContext_Check(self)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1332 ctx = CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1333 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1334 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
|
1335 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
|
1336 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
|
1337 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
|
1338 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1339 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1340 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
|
1341 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
|
1342 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
|
1343 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1344 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1345 return PyUnicode_FromFormat( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1346 "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
|
1347 "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
|
1348 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
|
1349 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
|
1350 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1351 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1352 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1353 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
|
1354 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1355 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
|
1356 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1357 ctx.prec = 9; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1358 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
|
1359 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
|
1360 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1361 *CTX(v) = ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1362 CtxCaps(v) = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1363 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1364 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1365 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1366 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
|
1367 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1368 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
|
1369 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1370 ctx.prec = 9; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1371 ctx.traps = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1372 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1373 *CTX(v) = ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1374 CtxCaps(v) = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1375 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1376 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1377 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1378 /* 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
|
1379 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1380 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
|
1381 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1382 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1383 mpd_ssize_t bits; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1384 mpd_context_t ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1385 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1386 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
|
1387 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
|
1388 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1389 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1390 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
|
1391 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1392 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1393 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
|
1394 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1395 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1396 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1397 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
|
1398 if (context == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1399 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1400 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1401 *CTX(context) = ctx; |
|
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 return context; |
|
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 error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1406 PyErr_Format(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1407 "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
|
1408 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
|
1409 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1410 return NULL; |
|
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 #endif |
|
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 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
|
1415 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
|
1416 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1417 PyObject *copy; |
|
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 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
|
1420 if (copy == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1421 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1422 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1423 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1424 *CTX(copy) = *CTX(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1425 CTX(copy)->newtrap = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1426 CtxCaps(copy) = CtxCaps(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1427 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1428 return copy; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1431 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1432 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
|
1433 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1434 PyObject *flags; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1435 PyObject *traps; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1436 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1437 mpd_context_t *ctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1438 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1439 ctx = CTX(self); |
|
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 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
|
1442 if (flags == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1443 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1444 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1445 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
|
1446 if (traps == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1447 Py_DECREF(flags); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1448 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1449 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1450 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1451 ret = Py_BuildValue( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1452 "O(nsnniiOO)", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1453 Py_TYPE(self), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1454 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
|
1455 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
|
1456 ); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1457 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1458 Py_DECREF(flags); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1459 Py_DECREF(traps); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1460 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1461 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1462 |
|
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 static PyGetSetDef context_getsets [] = |
|
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 { "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
|
1467 { "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
|
1468 { "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
|
1469 { "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
|
1470 { "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
|
1471 { "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
|
1472 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1473 { "_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
|
1474 { "_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
|
1475 { "_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
|
1476 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1477 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1478 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1479 |
|
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 #define CONTEXT_CHECK(obj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1482 if (!PyDecContext_Check(obj)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1483 PyErr_SetString(PyExc_TypeError, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1484 "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
|
1485 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1486 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1487 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1488 #define CONTEXT_CHECK_VA(obj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1489 if (!PyDecContext_Check(obj)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1490 PyErr_SetString(PyExc_TypeError, \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1491 "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
|
1492 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1493 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1494 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1495 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1496 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1497 /* 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
|
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 #ifdef WITHOUT_THREADS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1501 /* 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
|
1502 * 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
|
1503 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
|
1504 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1505 current_context(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1506 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1507 /* 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
|
1508 * 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
|
1509 * 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
|
1510 if (module_context_set) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1511 return module_context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1512 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1513 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1514 *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
|
1515 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
|
1516 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
|
1517 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
|
1518 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1519 module_context_set = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1520 return module_context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1521 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1522 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1523 /* 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
|
1524 #define CURRENT_CONTEXT(ctxobj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1525 ctxobj = current_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 /* 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
|
1528 #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
|
1529 ctx = CTX(current_context()) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1530 |
| 76077 | 1531 /* 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
|
1532 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
|
1533 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
|
1534 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1535 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1536 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1537 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1538 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1539 Py_INCREF(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1540 return 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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1543 /* 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
|
1544 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1545 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
|
1546 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1547 CONTEXT_CHECK(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1548 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1549 /* 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
|
1550 * 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
|
1551 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
|
1552 v == basic_context_template || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1553 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
|
1554 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
|
1555 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1556 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1557 } |
|
76063
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1558 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
|
1559 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1560 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1561 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1562 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1563 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1564 Py_XDECREF(module_context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1565 module_context = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1566 module_context_set = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1567 Py_RETURN_NONE; |
|
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 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1570 /* |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1571 * 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
|
1572 * 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
|
1573 * 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
|
1574 * operation. |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1575 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1576 |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1577 /* 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
|
1578 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
|
1579 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
|
1580 { |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1581 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
|
1582 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
|
1583 PyThreadState *tstate; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1584 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1585 dict = PyThreadState_GetDict(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1586 if (dict == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1587 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1588 "cannot get thread state"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1589 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1590 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1591 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1592 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
|
1593 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
|
1594 /* 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
|
1595 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
|
1596 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1597 else { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1598 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
|
1599 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
|
1600 } |
|
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 /* 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
|
1603 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
|
1604 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
|
1605 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
|
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 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
|
1608 |
|
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 (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
|
1610 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
|
1611 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
|
1612 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1613 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
|
1614 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1615 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1616 /* 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
|
1617 * 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
|
1618 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
|
1619 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
|
1620 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
|
1621 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
|
1622 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1623 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1624 /* 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
|
1625 return tl_context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1626 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1627 |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1628 /* 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
|
1629 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
|
1630 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
|
1631 { |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1632 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
|
1633 |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1634 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
|
1635 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
|
1636 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
|
1637 } |
|
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 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
|
1640 } |
|
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1641 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1642 /* 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
|
1643 #define CURRENT_CONTEXT(ctxobj) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1644 ctxobj = current_context(); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1645 if (ctxobj == NULL) { \ |
| 75862 | 1646 return NULL; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1647 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1648 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1649 /* 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
|
1650 #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
|
1651 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
|
1652 if (_c_t_x_o_b_j == NULL) { \ |
| 75862 | 1653 return NULL; \ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1654 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1655 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
|
1656 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1657 |
| 76077 | 1658 /* 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
|
1659 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
|
1660 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
|
1661 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1662 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1663 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1664 context = current_context(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1665 if (context == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1666 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1667 } |
|
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 Py_INCREF(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1670 return context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1671 } |
|
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 /* 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
|
1674 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1675 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
|
1676 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1677 PyObject *dict; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1678 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1679 CONTEXT_CHECK(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1680 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1681 dict = PyThreadState_GetDict(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1682 if (dict == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1683 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1684 "cannot get thread state"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1685 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1686 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1687 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1688 /* 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
|
1689 * 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
|
1690 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
|
1691 v == basic_context_template || |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1692 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
|
1693 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
|
1694 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1695 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1696 } |
|
76063
2345a042c08a
Clear the context flags if a context is initialized from the DefaultContext.
Stefan Krah <skrah@bytereef.org>
parents:
75923
diff
changeset
|
1697 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
|
1698 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1699 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1700 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1701 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1702 |
|
77689
8993160609f5
Speed up _decimal by another 10-15% by caching the thread local context
Stefan Krah <skrah@bytereef.org>
parents:
76206
diff
changeset
|
1703 cached_context = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1704 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
|
1705 Py_DECREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1706 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1707 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1708 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1709 Py_DECREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1710 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1711 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1712 #endif |
|
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 /* 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
|
1715 * 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
|
1716 * 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
|
1717 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1718 ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1719 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1720 PyDecContextManagerObject *self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1721 PyObject *local; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1722 PyObject *global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1723 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1724 CURRENT_CONTEXT(global); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1725 local = global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1726 if (!PyArg_ParseTuple(args, "|O", &local)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1727 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1728 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1729 CONTEXT_CHECK_VA(local); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1730 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1731 self = PyObject_New(PyDecContextManagerObject, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1732 &PyDecContextManager_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1733 if (self == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1734 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1735 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1736 |
|
78302
bd6f9315a0f0
Add unused parameter to a couple of METH_NOARGS functions. The previous
Stefan Krah <skrah@bytereef.org>
parents:
77876
diff
changeset
|
1737 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
|
1738 if (self->local == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1739 self->global = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1740 Py_DECREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1741 return NULL; |
|
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->global = global; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1744 Py_INCREF(self->global); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1745 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1746 return (PyObject *)self; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1749 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1750 ctxmanager_dealloc(PyDecContextManagerObject *self) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1751 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1752 Py_XDECREF(self->local); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1753 Py_XDECREF(self->global); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1754 PyObject_Del(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1755 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1756 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1757 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1758 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
|
1759 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1760 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1761 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1762 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
|
1763 if (ret == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1764 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1765 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1766 Py_DECREF(ret); |
|
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 Py_INCREF(self->local); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1769 return self->local; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1770 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1773 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
|
1774 PyObject *args UNUSED) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1775 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1776 PyObject *ret; |
|
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 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
|
1779 if (ret == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1780 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1781 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1782 Py_DECREF(ret); |
|
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 Py_RETURN_NONE; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1785 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1786 |
|
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 static PyMethodDef ctxmanager_methods[] = { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1789 {"__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
|
1790 {"__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
|
1791 {NULL, NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1792 }; |
|
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 static PyTypeObject PyDecContextManager_Type = |
|
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 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
|
1797 "decimal.ContextManager", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1798 sizeof(PyDecContextManagerObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1799 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1800 (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
|
1801 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1802 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1803 (setattrfunc) 0, /* tp_setattr */ |
| 76077 | 1804 0, /* tp_reserved */ |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1805 (reprfunc) 0, /* tp_repr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1806 0, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1807 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1808 0, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1809 0, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1810 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1811 0, /* tp_str */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1812 (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
|
1813 (setattrofunc) 0, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1814 (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
|
1815 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
|
1816 0, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1817 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1818 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1819 0, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1820 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1821 0, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1822 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1823 ctxmanager_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1824 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1825 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1826 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1827 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1828 /* New Decimal Object */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1829 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1830 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1831 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1832 PyDecType_New(PyTypeObject *type) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1833 { |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1834 PyDecObject *dec; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1835 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1836 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
|
1837 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
|
1838 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1839 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
|
1840 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
|
1841 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1842 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1843 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1844 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1845 |
|
76206
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
1846 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
|
1847 |
|
76183
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1848 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
|
1849 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
|
1850 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
|
1851 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
|
1852 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
|
1853 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
|
1854 |
|
02c70dcb29dc
Speed up _decimal by 30-40% for numerical workloads by improving the cache
Stefan Krah <skrah@bytereef.org>
parents:
76182
diff
changeset
|
1855 return (PyObject *)dec; |
|
75850
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 #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
|
1858 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1859 static void |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1860 dec_dealloc(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1861 { |
|
76183
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_del(MPD(dec)); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1863 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
|
1864 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1865 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1866 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1867 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1868 /* Conversions to Decimal */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1869 /******************************************************************************/ |
|
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 Py_LOCAL_INLINE(int) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1872 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
|
1873 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1874 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
|
1875 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
|
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 /* 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
|
1879 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
|
1880 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
|
1881 whitespace is stripped. |
|
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 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
|
1884 are found. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1885 static char * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1886 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
|
1887 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1888 enum PyUnicode_Kind kind; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1889 void *data; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1890 Py_UCS4 ch; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1891 char *res, *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1892 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
|
1893 int d; |
|
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 assert(PyUnicode_IS_READY(u)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1896 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1897 kind = PyUnicode_KIND(u); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1898 data = PyUnicode_DATA(u); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1899 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
|
1900 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1901 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
|
1902 if (res == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1903 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1904 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1905 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1906 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1907 j = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1908 if (strip_ws) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1909 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
|
1910 len--; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1911 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1912 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
|
1913 j++; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1916 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1917 for (; j < len; j++) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1918 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
|
1919 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
|
1920 *cp++ = ch; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1921 continue; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1922 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1923 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
|
1924 *cp++ = ' '; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1925 continue; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1926 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1927 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
|
1928 if (d < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1929 /* empty string triggers ConversionSyntax */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1930 *res = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1931 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1932 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1933 *cp++ = '0' + d; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1934 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1935 *cp = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1936 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1937 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1938 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1939 /* 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
|
1940 during conversion. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1941 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1942 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
|
1943 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1944 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1945 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1946 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1947 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1948 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1949 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1950 return NULL; |
|
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 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
|
1954 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
|
1955 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1956 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1957 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1958 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1959 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1960 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1961 /* 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
|
1962 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
|
1963 InvalidOperation. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1964 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1965 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
|
1966 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1967 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1968 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1969 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1970 mpd_context_t maxctx; |
|
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 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1973 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1974 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1975 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1976 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1977 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1978 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1979 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
|
1980 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
|
1981 /* we want exact results */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1982 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
|
1983 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1984 status &= MPD_Errors; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1985 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
|
1986 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1987 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1988 } |
|
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 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1991 } |
|
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 /* 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
|
1994 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1995 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
|
1996 PyObject *context) |
|
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 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1999 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2000 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2001 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
|
2002 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2003 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2004 } |
|
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 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
|
2007 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2008 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2009 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2010 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2011 /* 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
|
2012 * 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
|
2013 * 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
|
2014 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2015 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
|
2016 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2017 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2018 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2019 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2020 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2021 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
|
2022 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2023 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2026 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
|
2027 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2028 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2029 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2030 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2031 /* 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
|
2032 Py_LOCAL_INLINE(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2033 _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
|
2034 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2035 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2036 #ifdef CONFIG_64 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2037 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
|
2038 MPD(dec)->len = 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2039 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2040 uint32_t q, r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2041 q = v / MPD_RADIX; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2042 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
|
2043 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
|
2044 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
|
2045 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
|
2046 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2047 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
|
2048 MPD(dec)->exp = exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2049 mpd_setdigits(MPD(dec)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2050 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2051 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2052 /* 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
|
2053 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2054 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
|
2055 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2056 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2057 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2058 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2059 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2060 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2061 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2062 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2063 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2064 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
|
2065 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
|
2066 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2067 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2068 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2069 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2070 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2071 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2072 /* 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
|
2073 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2074 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
|
2075 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2076 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2077 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2078 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2079 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2080 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2081 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2082 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2083 } |
|
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 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2086 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2087 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
|
2088 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
|
2089 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2090 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2091 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2092 return dec; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2095 /* 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
|
2096 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
|
2097 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2098 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
|
2099 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
|
2100 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2101 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2102 PyLongObject *l = (PyLongObject *)v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2103 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
|
2104 size_t len; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2105 uint8_t sign; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2106 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2107 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2108 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2109 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2110 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2111 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2112 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
|
2113 if (ob_size == 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2114 _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
|
2115 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2116 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2117 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2118 if (ob_size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2119 len = -ob_size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2120 sign = MPD_NEG; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2121 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2122 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2123 len = ob_size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2124 sign = MPD_POS; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2127 if (len == 1) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2128 _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
|
2129 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
|
2130 return dec; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2133 #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
|
2134 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
|
2135 ctx, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2136 #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
|
2137 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
|
2138 ctx, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2139 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2140 #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
|
2141 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2142 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2143 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2144 } |
|
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 /* 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
|
2147 conversion. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2148 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2149 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
|
2150 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2151 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2152 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2153 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2154 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2155 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
|
2156 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2157 return NULL; |
|
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 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
|
2161 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2162 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2163 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2164 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2165 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2166 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2167 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2168 /* 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
|
2169 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
|
2170 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2171 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
|
2172 PyObject *context) |
|
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 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2175 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2176 mpd_context_t maxctx; |
|
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 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2179 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
|
2180 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2181 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2182 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2183 |
|
76120
0f9d79998c79
Raise InvalidOperation if exponents of zeros are clamped during exact
Stefan Krah <skrah@bytereef.org>
parents:
76077
diff
changeset
|
2184 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
|
2185 /* we want exact results */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2186 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
|
2187 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2188 status &= MPD_Errors; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2189 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
|
2190 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2191 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2192 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2193 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2194 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2195 } |
|
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 /* 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
|
2198 Conversion is exact. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2199 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2200 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
|
2201 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2202 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2203 PyObject *dec, *tmp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2204 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
|
2205 mpd_ssize_t k; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2206 double x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2207 int sign; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2208 mpd_t *d1, *d2; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2209 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2210 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2211 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2212 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2213 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
|
2214 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2215 if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2216 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
|
2217 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2218 if (!PyFloat_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2219 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2220 "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
|
2221 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2222 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2223 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2224 x = PyFloat_AsDouble(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2225 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
|
2226 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2227 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2228 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
|
2229 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2230 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
|
2231 dec = PyDecType_New(type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2232 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2233 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2234 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2235 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
|
2236 /* 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
|
2237 * 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
|
2238 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
|
2239 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2240 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2241 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
|
2242 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2243 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2244 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2245 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2246 /* 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
|
2247 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
|
2248 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2249 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2250 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2251 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2252 /* 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
|
2253 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
|
2254 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2255 if (n_d == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2256 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2257 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2258 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
|
2259 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
|
2260 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2261 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
|
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 Py_DECREF(n_d); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2264 return NULL; |
|
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 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
|
2267 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2268 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
|
2269 Py_DECREF(n_d); |
|
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 k--; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2273 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2274 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
|
2275 Py_DECREF(n_d); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2276 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2277 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2278 } |
|
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 d1 = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2281 if (d1 == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2282 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2283 PyErr_NoMemory(); |
|
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 d2 = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2287 if (d2 == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2288 mpd_del(d1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2289 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2290 PyErr_NoMemory(); |
|
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 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2295 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
|
2296 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
|
2297 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
|
2298 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
|
2299 mpd_del(d1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2300 mpd_del(d2); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2301 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2302 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2303 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2304 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2305 /* result = n * 5**k */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2306 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
|
2307 mpd_del(d1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2308 mpd_del(d2); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2309 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
|
2310 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2311 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2312 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2313 /* 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
|
2314 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
|
2315 MPD(dec)->exp = -k; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2316 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2317 return dec; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2320 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2321 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
|
2322 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2323 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2324 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2325 uint32_t status = 0; |
|
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 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
|
2328 if (dec == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2329 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2332 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
|
2333 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
|
2334 Py_DECREF(dec); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2335 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2336 } |
|
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 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2339 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2342 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
|
2343 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2344 if (PyTuple_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2345 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2346 return v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2347 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2348 if (PyList_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2349 return PyList_AsTuple(v); |
|
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 PyErr_SetString(ex, mesg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2353 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2354 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2355 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2356 /* 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
|
2357 static char * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2358 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
|
2359 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2360 PyObject *digits = NULL, *tmp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2361 char *decstring = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2362 char sign_special[6]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2363 char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2364 long sign, l; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2365 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
|
2366 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
|
2367 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
|
2368 int n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2369 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2370 assert(PyTuple_Check(dectuple)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2371 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2372 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
|
2373 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2374 "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
|
2375 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2376 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2377 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2378 /* sign */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2379 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
|
2380 if (!PyLong_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2381 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2382 "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
|
2383 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2384 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2385 sign = PyLong_AsLong(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2386 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
|
2387 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2388 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2389 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
|
2390 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2391 "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
|
2392 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2393 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2394 sign_special[0] = sign ? '-' : '+'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2395 sign_special[1] = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2396 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2397 /* 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
|
2398 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
|
2399 if (PyUnicode_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2400 /* special */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2401 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
|
2402 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
|
2403 is_infinite = 1; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2404 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2405 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
|
2406 strcat(sign_special, "NaN"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2407 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2408 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
|
2409 strcat(sign_special, "sNaN"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2410 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2411 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2412 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2413 "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
|
2414 "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
|
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 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2419 /* exponent */ |
|
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 "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
|
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 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
|
2426 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
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2430 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2431 /* coefficient */ |
| 76122 | 2432 digits = sequence_as_tuple(PyTuple_GET_ITEM(dectuple, 1), PyExc_ValueError, |
| 2433 "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
|
2434 if (digits == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2435 goto error; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2438 tsize = PyTuple_Size(digits); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2439 /* [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
|
2440 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
|
2441 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
|
2442 if (decstring == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2443 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2444 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2445 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2446 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2447 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
|
2448 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
|
2449 PyErr_SetString(PyExc_RuntimeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2450 "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
|
2451 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2452 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2453 cp += n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2454 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2455 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
|
2456 /* 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
|
2457 *cp++ = '0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2458 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2459 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
|
2460 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
|
2461 if (!PyLong_Check(tmp)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2462 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2463 "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
|
2464 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2465 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2466 l = PyLong_AsLong(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2467 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
|
2468 goto error; |
|
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 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
|
2471 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2472 "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
|
2473 goto error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2474 } |
|
78970
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2475 if (is_infinite) { |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2476 /* 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
|
2477 with decimal.py */ |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2478 continue; |
|
97e53273f423
Issue #15882: Change _decimal to accept any coefficient tuple when
Stefan Krah <skrah@bytereef.org>
parents:
78744
diff
changeset
|
2479 } |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2480 *cp++ = (char)l + '0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2481 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2482 *cp = '\0'; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2483 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2484 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
|
2485 /* not a special number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2486 *cp++ = 'E'; |
|
76121
a99cd3b98425
Allow printing a leading '-' and the maximum number of exponent digits
Stefan Krah <skrah@bytereef.org>
parents:
76120
diff
changeset
|
2487 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
|
2488 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
|
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 } |
|
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 Py_XDECREF(digits); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2496 return decstring; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2497 |
|
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 error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2500 Py_XDECREF(digits); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2501 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
|
2502 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2503 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2504 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2505 /* 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
|
2506 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2507 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
|
2508 PyObject *context) |
|
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 PyObject *dectuple; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2511 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2512 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2513 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2514 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
|
2515 "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
|
2516 if (dectuple == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2517 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2518 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2519 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2520 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
|
2521 Py_DECREF(dectuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2522 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2523 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2524 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2525 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2526 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
|
2527 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2528 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2529 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2530 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2531 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2532 /* 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
|
2533 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2534 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
|
2535 PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2536 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2537 PyObject *dectuple; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2538 PyObject *dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2539 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2540 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2541 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
|
2542 "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
|
2543 if (dectuple == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2544 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2545 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2546 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2547 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
|
2548 Py_DECREF(dectuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2549 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2550 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2551 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2552 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2553 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
|
2554 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2555 PyMem_Free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2556 return dec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2557 } |
|
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 #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
|
2560 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
|
2561 #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
|
2562 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
|
2563 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2564 #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
|
2565 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
|
2566 #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
|
2567 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
|
2568 #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
|
2569 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
|
2570 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2571 #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
|
2572 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
|
2573 #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
|
2574 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
|
2575 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2576 #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
|
2577 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
|
2578 #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
|
2579 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
|
2580 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2581 #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
|
2582 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
|
2583 #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
|
2584 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
|
2585 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2586 #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
|
2587 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
|
2588 #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
|
2589 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
|
2590 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2591 /* class method */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2592 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2593 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
|
2594 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2595 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2596 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2597 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2598 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
|
2599 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2600 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2601 /* create_decimal_from_float */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2602 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2603 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
|
2604 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2605 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
|
2606 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2607 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2608 /* 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
|
2609 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2610 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
|
2611 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2612 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2613 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2614 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2615 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2616 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2617 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2618 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2619 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2620 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
|
2621 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
|
2622 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2623 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2624 } |
|
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 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
|
2627 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
|
2628 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2629 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2632 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2633 } |
|
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 /* '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
|
2636 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
|
2637 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
|
2638 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2639 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
|
2640 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2641 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2642 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
|
2643 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2644 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
|
2645 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2646 return v; |
|
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 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
|
2649 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
|
2650 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2651 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
|
2652 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
|
2653 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2654 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
|
2655 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
|
2656 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2657 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
|
2658 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
|
2659 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2660 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2661 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
|
2662 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2663 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2664 PyErr_Format(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2665 "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
|
2666 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
|
2667 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2668 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2669 } |
|
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 /* 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
|
2672 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
|
2673 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2674 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
|
2675 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2676 if (v == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2677 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
|
2678 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2679 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
|
2680 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
|
2681 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
|
2682 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
|
2683 /* 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
|
2684 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2685 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
|
2686 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2687 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2688 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2689 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2690 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2691 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2692 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
|
2693 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2694 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2695 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
|
2696 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2697 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
|
2698 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
|
2699 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2700 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
|
2701 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
|
2702 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2703 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
|
2704 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
|
2705 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2706 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
|
2707 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
|
2708 return NULL; |
|
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 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
|
2711 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2712 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2713 PyErr_Format(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2714 "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
|
2715 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
|
2716 return NULL; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2719 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2720 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2721 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
|
2722 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2723 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
|
2724 PyObject *v = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2725 PyObject *context; |
|
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 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2728 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
|
2729 &v, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2730 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2731 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2732 CONTEXT_CHECK_VA(context); |
|
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 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
|
2735 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2736 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2737 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2738 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
|
2739 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2740 PyObject *v = NULL; |
|
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 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
|
2743 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2746 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
|
2747 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2750 /******************************************************************************/ |
| 76077 | 2751 /* 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
|
2752 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2753 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2754 /* 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
|
2755 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
|
2756 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
|
2757 #define NOT_IMPL 0 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2758 #define TYPE_ERR 1 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2759 Py_LOCAL_INLINE(int) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2760 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
|
2761 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2762 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2763 if (PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2764 *conv = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2765 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2766 return 1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2767 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2768 if (PyLong_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2769 *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
|
2770 if (*conv == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2771 return 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2772 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2773 return 1; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2776 if (type_err) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2777 PyErr_Format(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2778 "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
|
2779 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
|
2780 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2781 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2782 Py_INCREF(Py_NotImplemented); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2783 *conv = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2784 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2785 return 0; |
|
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 /* 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
|
2789 #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
|
2790 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
|
2791 return *(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2792 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2793 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2794 #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
|
2795 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
|
2796 return *(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2797 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2798 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
|
2799 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2800 return *(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2801 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2802 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2803 #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
|
2804 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
|
2805 return *(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2806 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2807 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
|
2808 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2809 return *(b); \ |
|
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 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
|
2812 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2813 Py_DECREF(*(b)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2814 return *(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2815 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2816 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2817 /* 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
|
2818 #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
|
2819 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
|
2820 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2821 } |
|
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 #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
|
2824 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
|
2825 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2826 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2827 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
|
2828 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2829 return NULL; \ |
|
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_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
|
2833 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
|
2834 return NULL; \ |
|
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(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
|
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 NULL; \ |
|
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 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
|
2841 Py_DECREF(*(a)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2842 Py_DECREF(*(b)); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2843 return NULL; \ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2846 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2847 /******************************************************************************/ |
| 76077 | 2848 /* 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
|
2849 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2850 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2851 /* Convert rationals for comparison */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2852 static PyObject *Rational = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2853 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2854 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
|
2855 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2856 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2857 PyObject *tmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2858 PyObject *denom = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2859 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2860 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2861 mpd_ssize_t exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2862 mpd_t *vv; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2863 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2864 /* 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
|
2865 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
|
2866 if (tmp == NULL) { |
|
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 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
|
2870 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2871 if (denom == NULL) { |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2875 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
|
2876 if (vv == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2877 Py_DECREF(denom); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2878 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2879 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2880 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2881 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2882 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2883 Py_DECREF(denom); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2884 mpd_del(vv); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2885 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2886 } |
|
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 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2889 /* 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
|
2890 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
|
2891 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
|
2892 99999999999999999999...99999999e+425000000. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2893 exp = vv->exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2894 vv->exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2895 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
|
2896 MPD(result)->exp = exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2897 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2898 Py_DECREF(denom); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2899 mpd_del(vv); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2900 /* 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
|
2901 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
|
2902 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
|
2903 if (status) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2904 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2905 "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
|
2906 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2907 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2908 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2909 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2910 return result; |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2914 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
|
2915 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2916 PyObject *tmp, *num; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2917 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2918 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
|
2919 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2920 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2921 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2922 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2923 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
|
2924 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2925 return num; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2926 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2927 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2928 /* 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
|
2929 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
|
2930 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
|
2931 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
|
2932 is undefined. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2933 static int |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2934 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
|
2935 int op, PyObject *context) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2936 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2937 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
|
2938 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2939 *vcmp = v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2940 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2941 if (PyDec_Check(w)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2942 Py_INCREF(w); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2943 *wcmp = w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2944 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2945 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
|
2946 *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
|
2947 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2948 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
|
2949 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
|
2950 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
|
2951 *wcmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2952 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2953 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2954 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
|
2955 *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
|
2956 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2957 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2958 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
|
2959 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
|
2960 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
|
2961 *wcmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2962 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2963 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
|
2964 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
|
2965 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2966 *wcmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2967 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2968 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2969 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
|
2970 *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
|
2971 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2972 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2973 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2974 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2975 Py_INCREF(Py_NotImplemented); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2976 *wcmp = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2977 } |
|
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 else if (PyObject_IsInstance(w, Rational)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2980 *wcmp = numerator_as_decimal(w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2981 if (*wcmp && !mpd_isspecial(MPD(v))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2982 *vcmp = multiply_by_denominator(v, w, context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2983 if (*vcmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2984 Py_CLEAR(*wcmp); |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2987 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2988 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2989 Py_INCREF(Py_NotImplemented); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2990 *wcmp = Py_NotImplemented; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2991 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2992 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2993 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
|
2994 return 0; |
|
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 if (*vcmp == v) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2997 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2998 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2999 return 1; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3002 #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
|
3003 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
|
3004 return *(wcmp); \ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3007 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3008 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3009 /* Conversions from decimal */ |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3013 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
|
3014 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3015 PyObject *res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3016 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3017 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
|
3018 if (res == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3019 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3020 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3021 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3022 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
|
3023 return res; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3024 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3025 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3026 /* 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
|
3027 the value of 'capitals'. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3028 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3029 dec_str(PyObject *dec) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3030 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3031 PyObject *res, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3032 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3033 char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3034 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3035 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3036 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
|
3037 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3038 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3039 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3040 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3041 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3042 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
|
3043 mpd_free(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3044 return res; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3047 /* Representation of a PyDecObject. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3048 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3049 dec_repr(PyObject *dec) |
|
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 PyObject *res, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3052 char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3053 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3054 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3055 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
|
3056 if (cp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3057 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3058 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3059 } |
|
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_FromFormat("Decimal('%s')", cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3062 mpd_free(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3063 return res; |
|
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 /* 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
|
3067 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
|
3068 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3069 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
|
3070 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3071 PyObject *utf8; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3072 PyObject *tmp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3073 wchar_t buf[2]; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3074 size_t n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3075 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3076 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
|
3077 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
|
3078 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3079 "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
|
3080 "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
|
3081 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3082 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3083 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
|
3084 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3085 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3086 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3087 utf8 = PyUnicode_AsUTF8String(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3088 Py_DECREF(tmp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3089 return utf8; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3092 /* 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
|
3093 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3094 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
|
3095 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3096 PyObject *result = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3097 PyObject *override = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3098 PyObject *dot = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3099 PyObject *sep = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3100 PyObject *grouping = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3101 PyObject *fmt = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3102 PyObject *fmtarg; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3103 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3104 mpd_spec_t spec; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3105 char *decstring= NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3106 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3107 size_t n; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3110 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3111 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
|
3112 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3113 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3114 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3115 if (PyUnicode_Check(fmtarg)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3116 fmt = PyUnicode_AsUTF8String(fmtarg); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3117 if (fmt == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3118 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3119 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3120 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3121 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3122 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3123 "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
|
3124 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3125 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3126 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3127 if (!mpd_parse_fmt_str(&spec, PyBytes_AS_STRING(fmt), |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3128 CtxCaps(context))) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3129 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3130 "invalid format string"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3131 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3132 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3133 if (override) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3134 /* 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
|
3135 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
|
3136 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
|
3137 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
|
3138 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
|
3139 if (!PyDict_Check(override)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3140 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3141 "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
|
3142 goto finish; |
|
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 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
|
3145 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
|
3146 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3147 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3148 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
|
3149 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3150 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
|
3151 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
|
3152 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3153 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3154 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
|
3155 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3156 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
|
3157 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
|
3158 goto finish; |
|
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 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
|
3161 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3162 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
|
3163 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3164 "invalid override dict"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3165 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3166 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3167 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3168 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3169 n = strlen(spec.dot); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3170 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
|
3171 /* 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
|
3172 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
|
3173 if (dot == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3174 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3175 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3176 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
|
3177 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3178 n = strlen(spec.sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3179 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
|
3180 /* 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
|
3181 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
|
3182 if (sep == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3183 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3184 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3185 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
|
3186 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3187 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3188 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3189 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3190 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
|
3191 if (decstring == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3192 dec_addstatus(context, status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3193 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3194 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3195 result = PyUnicode_DecodeUTF8(decstring, strlen(decstring), NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3196 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3197 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3198 finish: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3199 Py_XDECREF(grouping); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3200 Py_XDECREF(sep); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3201 Py_XDECREF(dot); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3202 Py_XDECREF(fmt); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3203 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
|
3204 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3205 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3206 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3207 /* 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
|
3208 * 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
|
3209 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3210 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
|
3211 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3212 PyLongObject *pylong; |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3213 digit *ob_digit; |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3214 size_t n; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3215 Py_ssize_t i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3216 mpd_t *x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3217 mpd_context_t workctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3218 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3219 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3220 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
|
3221 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
|
3222 PyErr_SetString(PyExc_ValueError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3223 "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
|
3224 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3225 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3226 PyErr_SetString(PyExc_OverflowError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3227 "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
|
3228 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3229 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3230 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3231 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3232 x = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3233 if (x == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3234 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3235 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3236 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3237 workctx = *CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3238 workctx.round = round; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3239 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
|
3240 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
|
3241 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3242 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3243 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3244 |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3245 status = 0; |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3246 ob_digit = NULL; |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3247 #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
|
3248 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
|
3249 #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
|
3250 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
|
3251 #else |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3252 #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
|
3253 #endif |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3254 |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3255 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
|
3256 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3257 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3258 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3259 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3260 |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3261 assert(n > 0); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3262 pylong = _PyLong_New(n); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3263 if (pylong == NULL) { |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3264 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
|
3265 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3266 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3267 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3268 |
|
77876
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3269 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
|
3270 mpd_free(ob_digit); |
|
79d2eb29c755
Proactive reliability fix for broken FPUs: The base conversion functions
Stefan Krah <skrah@bytereef.org>
parents:
77689
diff
changeset
|
3271 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3272 i = n; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3273 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
|
3274 i--; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3277 Py_SIZE(pylong) = i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3278 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
|
3279 Py_SIZE(pylong) = -i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3280 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3281 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3282 mpd_del(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3283 return (PyObject *) pylong; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3284 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3285 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3286 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3287 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
|
3288 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3289 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
|
3290 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3291 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3292 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3293 mpd_context_t workctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3294 int round = -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3295 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3296 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3297 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3298 &round, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3299 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3300 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3301 CONTEXT_CHECK_VA(context); |
|
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 workctx = *CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3304 if (round >= 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3305 if (!mpd_qsetround(&workctx, round)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3306 return type_error_ptr(invalid_rounding_err); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3307 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3310 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3311 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3312 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3313 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3314 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3315 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
|
3316 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
|
3317 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3318 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3319 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3320 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3321 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3322 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3323 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3324 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3325 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
|
3326 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3327 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
|
3328 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3329 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3330 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3331 mpd_context_t workctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3332 int round = -1; |
|
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 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3335 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3336 &round, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3337 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3338 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3339 CONTEXT_CHECK_VA(context); |
|
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 workctx = *CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3342 if (round >= 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3343 if (!mpd_qsetround(&workctx, round)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3344 return type_error_ptr(invalid_rounding_err); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3345 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3346 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3347 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3348 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3349 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3350 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3351 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3352 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3353 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
|
3354 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
|
3355 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3356 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3357 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3358 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3359 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3360 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3361 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3362 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3363 PyDec_AsFloat(PyObject *dec) |
|
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 PyObject *f, *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3366 |
|
78744
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3367 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
|
3368 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
|
3369 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
|
3370 "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
|
3371 return NULL; |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3372 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3373 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
|
3374 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
|
3375 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3376 else { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3377 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
|
3378 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3379 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3380 else { |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3381 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
|
3382 } |
|
49014c59b31f
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Mark Dickinson <mdickinson@enthought.com>
parents:
78719
diff
changeset
|
3383 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3384 if (s == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3385 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3386 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3387 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3388 f = PyFloat_FromString(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3389 Py_DECREF(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3390 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3391 return f; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3392 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3393 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3394 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3395 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
|
3396 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3397 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3398 PyObject *x = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3399 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3400 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3401 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3402 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3403 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3404 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
|
3405 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3406 } |
|
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 if (x) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3409 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
|
3410 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
|
3411 mpd_ssize_t y; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3412 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3413 if (!PyLong_Check(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3414 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3415 "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
|
3416 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3417 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3418 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3419 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
|
3420 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
|
3421 return NULL; |
|
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 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3424 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3425 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3428 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
|
3429 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
|
3430 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
|
3431 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3432 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3433 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3434 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3435 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3436 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3437 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3438 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
|
3439 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3440 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3441 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3442 PyObject *DecimalTuple = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3443 /* 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
|
3444 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3445 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
|
3446 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3447 PyObject *result = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3448 PyObject *sign = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3449 PyObject *coeff = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3450 PyObject *expt = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3451 PyObject *tmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3452 mpd_t *x = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3453 char *intstring = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3454 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
|
3455 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3456 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3457 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
|
3458 if (x == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3459 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3460 goto out; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3463 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
|
3464 if (sign == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3465 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3466 } |
|
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 if (mpd_isinfinite(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3469 expt = PyUnicode_FromString("F"); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3470 if (expt == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3471 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3472 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3473 /* 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
|
3474 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
|
3475 if (coeff == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3476 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3477 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3478 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3479 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3480 if (mpd_isnan(x)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3481 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
|
3482 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3483 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3484 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
|
3485 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3486 if (expt == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3487 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3488 } |
|
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 /* coefficient is defined */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3491 if (x->len > 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3492 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3493 /* make an integer */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3494 x->exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3495 /* clear NaN and sign */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3496 mpd_clear_flags(x); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3497 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
|
3498 if (intstring == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3499 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3500 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3501 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3502 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3503 intlen = strlen(intstring); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3504 coeff = PyTuple_New(intlen); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3505 if (coeff == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3506 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3507 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3508 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3509 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
|
3510 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
|
3511 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3512 goto out; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3513 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3514 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
|
3515 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3516 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3517 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3518 coeff = PyTuple_New(0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3519 if (coeff == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3520 goto out; |
|
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 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3523 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3524 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3525 result = PyObject_CallFunctionObjArgs(DecimalTuple, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3526 sign, coeff, expt, NULL); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3527 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3528 out: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3529 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
|
3530 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
|
3531 Py_XDECREF(sign); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3532 Py_XDECREF(coeff); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3533 Py_XDECREF(expt); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3534 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3535 } |
|
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 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3539 /* 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
|
3540 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3541 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3542 /* 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
|
3543 #define Dec_UnaryNumberMethod(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3544 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3545 nm_##MPDFUNC(PyObject *self) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3546 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3547 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3548 PyObject *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3549 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3550 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3551 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3552 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
|
3553 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3554 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3555 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3556 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
|
3557 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
|
3558 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3559 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3560 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3561 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3562 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3563 } |
|
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 /* 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
|
3566 #define Dec_BinaryNumberMethod(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3567 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3568 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
|
3569 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3570 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3571 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3572 PyObject *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3573 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3574 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3575 CURRENT_CONTEXT(context) ; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3576 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
|
3577 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3578 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
|
3579 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3580 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3581 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3582 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3583 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3584 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
|
3585 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3586 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3587 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
|
3588 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3589 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3590 } \ |
|
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 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3593 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3594 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3595 /* 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
|
3596 #define Dec_BoolFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3597 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3598 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
|
3599 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3600 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
|
3601 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3602 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3603 /* 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
|
3604 #define Dec_BoolFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3605 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3606 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
|
3607 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3608 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
|
3609 PyObject *context; \ |
|
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 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3612 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
|
3613 &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3614 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3615 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3616 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3617 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3618 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
|
3619 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3620 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3621 /* 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
|
3622 #define Dec_UnaryFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3623 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3624 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
|
3625 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3626 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
|
3627 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3628 PyObject *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3629 uint32_t status = 0; \ |
|
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 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3632 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
|
3633 &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3634 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3635 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3636 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3637 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3638 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
|
3639 return NULL; \ |
|
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 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
|
3643 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
|
3644 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3645 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3646 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3647 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3648 return result; \ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3651 /* Unary function with an optional context arg. The actual MPDFUNC |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3652 only takes a status parameter. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3653 #define Dec_UnaryFuncVA_NO_CTX(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3654 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3655 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
|
3656 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3657 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
|
3658 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3659 PyObject *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3660 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3661 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3662 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3663 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
|
3664 &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3665 return NULL; \ |
|
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 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3668 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3669 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
|
3670 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3671 } \ |
|
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 MPDFUNC(MPD(result), MPD(self), &status); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3674 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
|
3675 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3676 return NULL; \ |
|
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 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3679 return result; \ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3682 /* 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
|
3683 #define Dec_BinaryFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3684 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3685 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
|
3686 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3687 static char *kwlist[] = {"other", "context", NULL}; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3688 PyObject *other, *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3689 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3690 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3691 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3692 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3693 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3694 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
|
3695 &other, &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3696 return NULL; \ |
|
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 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3699 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
|
3700 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3701 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
|
3702 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3703 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3704 return NULL; \ |
|
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 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3707 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
|
3708 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3709 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3710 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
|
3711 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3712 return NULL; \ |
|
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 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3715 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3716 } |
|
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 /* 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
|
3719 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
|
3720 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
|
3721 #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
|
3722 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3723 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
|
3724 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3725 static char *kwlist[] = {"other", "context", NULL}; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3726 PyObject *other, *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3727 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3728 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3729 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3730 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3731 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
|
3732 &other, &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3733 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3734 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3735 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3736 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
|
3737 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3738 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
|
3739 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3740 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3741 return NULL; \ |
|
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 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3744 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
|
3745 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3746 Py_DECREF(b); \ |
|
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 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3749 } |
|
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 /* 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
|
3752 #define Dec_TernaryFuncVA(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3753 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3754 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
|
3755 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3756 static char *kwlist[] = {"other", "third", "context", NULL}; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3757 PyObject *other, *third, *context; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3758 PyObject *a, *b, *c; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3759 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3760 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3761 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3762 CURRENT_CONTEXT(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3763 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
|
3764 &other, &third, &context)) { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3765 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3766 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3767 CONTEXT_CHECK_VA(context); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3768 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
|
3769 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3770 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
|
3771 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3772 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3773 Py_DECREF(c); \ |
|
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), 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
|
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 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3781 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
|
3782 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3783 return NULL; \ |
|
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 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3786 return result; \ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3789 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3790 /**********************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3791 /* Number methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3792 /**********************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3793 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3794 Dec_UnaryNumberMethod(mpd_qminus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3795 Dec_UnaryNumberMethod(mpd_qplus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3796 Dec_UnaryNumberMethod(mpd_qabs) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3797 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3798 Dec_BinaryNumberMethod(mpd_qadd) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3799 Dec_BinaryNumberMethod(mpd_qsub) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3800 Dec_BinaryNumberMethod(mpd_qmul) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3801 Dec_BinaryNumberMethod(mpd_qdiv) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3802 Dec_BinaryNumberMethod(mpd_qrem) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3803 Dec_BinaryNumberMethod(mpd_qdivint) |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3806 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
|
3807 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3808 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3809 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3810 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3811 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
|
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 static int |
|
76182
435b21afc6fa
Use the MPD() accessor macro.
Stefan Krah <skrah@bytereef.org>
parents:
76124
diff
changeset
|
3815 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
|
3816 { |
|
76182
435b21afc6fa
Use the MPD() accessor macro.
Stefan Krah <skrah@bytereef.org>
parents:
76124
diff
changeset
|
3817 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
|
3818 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3821 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
|
3822 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3823 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3824 PyObject *q, *r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3825 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3826 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3827 PyObject *ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3828 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3829 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3830 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
|
3831 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3832 q = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3833 if (q == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3834 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3835 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3836 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3837 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3838 r = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3839 if (r == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3840 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3841 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3842 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3843 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3844 } |
|
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 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
|
3847 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3848 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3849 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
|
3850 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3851 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3852 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3853 } |
|
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 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
|
3856 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3857 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3858 return ret; |
|
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 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
|
3862 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
|
3863 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3864 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3865 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
|
3866 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3867 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
|
3868 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3869 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3870 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3871 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3872 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3873 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
|
3874 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3875 if (mod != Py_None) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3876 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
|
3877 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3878 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3879 return c; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3880 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3881 } |
|
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 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3884 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3885 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3886 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3887 Py_XDECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3888 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3891 if (c == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3892 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
|
3893 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3894 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3895 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3896 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
|
3897 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3898 Py_DECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3899 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3900 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3901 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3902 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
|
3903 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3904 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3905 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3906 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3907 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3908 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3909 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3910 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3911 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3912 /* Decimal Methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3913 /******************************************************************************/ |
|
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 /* 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
|
3916 Dec_UnaryFuncVA(mpd_qexp) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3917 Dec_UnaryFuncVA(mpd_qln) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3918 Dec_UnaryFuncVA(mpd_qlog10) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3919 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
|
3920 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
|
3921 Dec_UnaryFuncVA(mpd_qreduce) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3922 Dec_UnaryFuncVA(mpd_qsqrt) |
|
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 /* 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
|
3925 Dec_BinaryFuncVA(mpd_qcompare) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3926 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
|
3927 Dec_BinaryFuncVA(mpd_qmax) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3928 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
|
3929 Dec_BinaryFuncVA(mpd_qmin) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3930 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
|
3931 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
|
3932 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
|
3933 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3934 /* 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
|
3935 Dec_TernaryFuncVA(mpd_qfma) |
|
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 /* 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
|
3938 Dec_BoolFunc(mpd_iscanonical) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3939 Dec_BoolFunc(mpd_isfinite) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3940 Dec_BoolFunc(mpd_isinfinite) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3941 Dec_BoolFunc(mpd_isnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3942 Dec_BoolFunc(mpd_isqnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3943 Dec_BoolFunc(mpd_issnan) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3944 Dec_BoolFunc(mpd_issigned) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3945 Dec_BoolFunc(mpd_iszero) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3946 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3947 /* 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
|
3948 Dec_BoolFuncVA(mpd_isnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3949 Dec_BoolFuncVA(mpd_issubnormal) |
|
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 /* 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
|
3952 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3953 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
|
3954 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3955 mpd_ssize_t retval; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3956 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3957 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
|
3958 retval = 0; |
|
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 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3961 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
|
3962 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3963 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3964 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
|
3965 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3966 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3967 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3968 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
|
3969 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3970 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3971 return self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3972 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3973 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3974 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3975 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
|
3976 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3977 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3978 return self; |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3982 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
|
3983 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3984 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3985 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3986 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3987 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3988 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3989 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3990 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3991 _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
|
3992 return result; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3995 /* Unary 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
|
3996 Dec_UnaryFuncVA_NO_CTX(mpd_qcopy_abs) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3997 Dec_UnaryFuncVA_NO_CTX(mpd_qcopy_negate) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3998 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3999 /* 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
|
4000 Dec_UnaryFuncVA(mpd_qinvert) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4001 Dec_UnaryFuncVA(mpd_qlogb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4002 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4003 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4004 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
|
4005 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4006 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
|
4007 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4008 const char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4009 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4010 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4011 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
|
4012 &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4013 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4014 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4015 CONTEXT_CHECK_VA(context); |
|
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 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
|
4018 return PyUnicode_FromString(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4019 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4022 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
|
4023 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4024 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
|
4025 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4026 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4027 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4028 char *s; |
|
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 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4031 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
|
4032 &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4033 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4034 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4035 CONTEXT_CHECK_VA(context); |
|
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 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
|
4038 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4039 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4040 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4041 } |
|
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 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
|
4044 mpd_free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4045 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4046 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4047 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4048 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4049 /* 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
|
4050 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
|
4051 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
|
4052 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4053 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4054 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
|
4055 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4056 static char *kwlist[] = {"other", "context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4057 PyObject *other, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4058 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4059 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4060 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4061 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4062 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4063 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
|
4064 &other, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4065 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4066 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4067 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4068 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
|
4069 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4070 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4071 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4072 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4073 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4074 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4075 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4076 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4077 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
|
4078 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4079 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4080 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
|
4081 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4082 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4083 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4084 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4085 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4086 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4087 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4088 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4089 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
|
4090 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4091 static char *kwlist[] = {"other", "context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4092 PyObject *other, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4093 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4094 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4095 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4096 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4097 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
|
4098 &other, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4099 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4100 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4101 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4102 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
|
4103 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4104 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
|
4105 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4106 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4107 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4108 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4109 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4110 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4111 /* 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
|
4112 Dec_BinaryFuncVA(mpd_qand) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4113 Dec_BinaryFuncVA(mpd_qor) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4114 Dec_BinaryFuncVA(mpd_qxor) |
|
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 Dec_BinaryFuncVA(mpd_qrotate) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4117 Dec_BinaryFuncVA(mpd_qscaleb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4118 Dec_BinaryFuncVA(mpd_qshift) |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4121 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
|
4122 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4123 static char *kwlist[] = {"exp", "rounding", "context", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4124 PyObject *w, *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4125 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4126 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4127 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4128 mpd_context_t workctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4129 int round = -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4130 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4131 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4132 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO", kwlist, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4133 &w, &round, &context)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4134 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4135 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4136 CONTEXT_CHECK_VA(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4137 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4138 workctx = *CTX(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4139 if (round >= 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4140 if (!mpd_qsetround(&workctx, round)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4141 return type_error_ptr(invalid_rounding_err); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4142 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4143 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4144 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4145 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
|
4146 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4147 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4148 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4149 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4150 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4151 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4154 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
|
4155 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4156 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4157 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
|
4158 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4159 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4160 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4161 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4162 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4163 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4164 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4165 /* Special methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4166 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4167 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
|
4168 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4169 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4170 PyObject *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4171 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4172 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4173 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
|
4174 int r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4175 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4176 assert(PyDec_Check(v)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4177 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4178 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4179 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
|
4180 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4181 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
|
4182 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
|
4183 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4184 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
|
4185 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4186 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4187 if (r == INT_MAX) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4188 /* 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
|
4189 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
|
4190 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
|
4191 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4192 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4193 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4194 /* 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
|
4195 * with InvalidOperation disabled. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4196 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
|
4197 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4198 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4199 switch (op) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4200 case Py_EQ: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4201 r = (r == 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4202 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4203 case Py_NE: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4204 r = (r != 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4205 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4206 case Py_LE: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4207 r = (r <= 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4208 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4209 case Py_GE: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4210 r = (r >= 0); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4211 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4212 case Py_LT: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4213 r = (r == -1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4214 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4215 case Py_GT: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4216 r = (r == 1); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4217 break; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4218 } |
|
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 return PyBool_FromLong(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4221 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4222 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4223 /* __ceil__ */ |
|
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_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
|
4226 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4227 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4228 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4229 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4230 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
|
4231 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4232 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4233 /* __complex__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4234 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4235 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
|
4236 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4237 PyObject *f; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4238 double x; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4239 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4240 f = PyDec_AsFloat(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4241 if (f == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4242 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4243 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4244 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4245 x = PyFloat_AsDouble(f); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4246 Py_DECREF(f); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4247 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
|
4248 return NULL; |
|
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 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
|
4252 } |
|
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 /* __copy__ and __deepcopy__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4255 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4256 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
|
4257 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4258 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4259 return self; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4262 /* __floor__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4263 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4264 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
|
4265 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4266 PyObject *context; |
|
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 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4269 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
|
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 /* 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
|
4273 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
|
4274 _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
|
4275 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4276 #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
|
4277 /* 2**61 - 1 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4278 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
|
4279 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
|
4280 /* Inverse of 10 modulo p */ |
| 76123 | 4281 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
|
4282 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
|
4283 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
|
4284 #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
|
4285 /* 2**31 - 1 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4286 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
|
4287 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
|
4288 /* 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
|
4289 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
|
4290 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
|
4291 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
|
4292 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4293 #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
|
4294 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4295 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
|
4296 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
|
4297 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
|
4298 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
|
4299 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
|
4300 Py_hash_t result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4301 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
|
4302 mpd_t *tmp = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4303 mpd_ssize_t exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4304 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4305 mpd_context_t maxctx; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4306 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4307 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4308 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4309 context = current_context(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4310 if (context == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4311 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4312 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4313 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4314 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
|
4315 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
|
4316 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4317 "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
|
4318 return -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4319 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4320 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
|
4321 return py_hash_nan; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4322 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4323 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4324 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
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4328 mpd_maxcontext(&maxctx); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4329 exp_hash = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4330 if (exp_hash == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4331 goto malloc_error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4332 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4333 tmp = mpd_qnew(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4334 if (tmp == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4335 goto malloc_error; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4336 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4337 |
|
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 * 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
|
4340 * 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
|
4341 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4342 exp = MPD(v)->exp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4343 if (exp >= 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4344 /* 10**exp(v) % p */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4345 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
|
4346 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
|
4347 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4348 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4349 /* 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
|
4350 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
|
4351 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
|
4352 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4353 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4354 /* 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
|
4355 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
|
4356 goto malloc_error; |
|
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 tmp->exp = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4359 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
|
4360 |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4361 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
|
4362 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
|
4363 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
|
4364 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4365 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
|
4366 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
|
4367 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4368 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
|
4369 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
|
4370 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
|
4371 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4372 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
|
4373 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
|
4374 goto malloc_error; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4375 } |
|
78707
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4376 else { |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4377 PyErr_SetString(PyExc_RuntimeError, |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4378 "dec_hash: internal error: please report"); |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4379 } |
|
1a7abcdff030
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
Stefan Krah <skrah@bytereef.org>
parents:
78302
diff
changeset
|
4380 result = -1; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4381 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4384 finish: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4385 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
|
4386 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
|
4387 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4388 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4389 malloc_error: |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4390 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4391 result = -1; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4392 goto finish; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4393 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4394 |
|
76206
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4395 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
|
4396 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
|
4397 { |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4398 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
|
4399 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
|
4400 } |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4401 |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4402 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
|
4403 } |
|
a012d5df2c73
Issue #14478: Cache the hash of a Decimal in the C version.
Stefan Krah <skrah@bytereef.org>
parents:
76198
diff
changeset
|
4404 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4405 /* __reduce__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4406 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4407 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
|
4408 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4409 PyObject *result, *str; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4410 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4411 str = dec_str(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4412 if (str == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4413 return NULL; |
|
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 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
|
4417 Py_DECREF(str); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4418 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4419 return result; |
|
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 |
|
76198
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4422 /* __sizeof__ */ |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4423 static PyObject * |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4424 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
|
4425 { |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4426 Py_ssize_t res; |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4427 |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4428 res = sizeof(PyDecObject); |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4429 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
|
4430 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
|
4431 } |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4432 return PyLong_FromSsize_t(res); |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4433 } |
|
010aa5d955ac
Issue #14520: Add __sizeof__() method to the Decimal object.
Stefan Krah <skrah@bytereef.org>
parents:
76183
diff
changeset
|
4434 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4435 /* __trunc__ */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4436 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4437 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
|
4438 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4439 PyObject *context; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4440 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4441 CURRENT_CONTEXT(context); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4442 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
|
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 /* real and imag */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4446 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4447 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
|
4448 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4449 Py_INCREF(self); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4450 return self; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4451 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4452 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4453 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4454 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
|
4455 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4456 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4457 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4458 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4459 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4460 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4461 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4462 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4463 _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
|
4464 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4465 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4466 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4467 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4468 static PyGetSetDef dec_getsets [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4469 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4470 { "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
|
4471 { "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
|
4472 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4473 }; |
|
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 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
|
4476 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4477 (binaryfunc) nm_mpd_qadd, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4478 (binaryfunc) nm_mpd_qsub, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4479 (binaryfunc) nm_mpd_qmul, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4480 (binaryfunc) nm_mpd_qrem, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4481 (binaryfunc) nm_mpd_qdivmod, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4482 (ternaryfunc) nm_mpd_qpow, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4483 (unaryfunc) nm_mpd_qminus, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4484 (unaryfunc) nm_mpd_qplus, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4485 (unaryfunc) nm_mpd_qabs, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4486 (inquiry) nm_nonzero, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4487 (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
|
4488 (binaryfunc) 0, /* no shiftl */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4489 (binaryfunc) 0, /* no shiftr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4490 (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
|
4491 (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
|
4492 (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
|
4493 (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
|
4494 0, /* nb_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4495 (unaryfunc) PyDec_AsFloat, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4496 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
|
4497 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
|
4498 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
|
4499 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
|
4500 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
|
4501 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
|
4502 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
|
4503 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
|
4504 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
|
4505 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
|
4506 (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
|
4507 (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
|
4508 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
|
4509 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
|
4510 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4511 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4512 static PyMethodDef dec_methods [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4513 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4514 /* 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
|
4515 { "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
|
4516 { "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
|
4517 { "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
|
4518 { "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
|
4519 { "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
|
4520 { "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
|
4521 { "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
|
4522 { "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
|
4523 { "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
|
4524 { "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
|
4525 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4526 /* 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
|
4527 { "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
|
4528 { "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
|
4529 { "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
|
4530 { "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
|
4531 { "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
|
4532 { "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
|
4533 { "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
|
4534 { "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
|
4535 { "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
|
4536 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4537 /* 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
|
4538 { "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
|
4539 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4540 /* 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
|
4541 { "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
|
4542 { "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
|
4543 { "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
|
4544 { "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
|
4545 { "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
|
4546 { "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
|
4547 { "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
|
4548 { "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
|
4549 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4550 /* 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
|
4551 { "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
|
4552 { "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
|
4553 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4554 /* 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
|
4555 { "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
|
4556 { "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
|
4557 { "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
|
4558 { "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
|
4559 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4560 /* Unary 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
|
4561 { "copy_abs", (PyCFunction)dec_mpd_qcopy_abs, METH_VARARGS|METH_KEYWORDS, doc_copy_abs }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4562 { "copy_negate", (PyCFunction)dec_mpd_qcopy_negate, METH_VARARGS|METH_KEYWORDS, doc_copy_negate }, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4563 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4564 /* 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
|
4565 { "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
|
4566 { "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
|
4567 { "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
|
4568 { "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
|
4569 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4570 /* 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
|
4571 { "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
|
4572 { "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
|
4573 { "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
|
4574 { "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
|
4575 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4576 /* 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
|
4577 { "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
|
4578 { "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
|
4579 { "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
|
4580 { "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
|
4581 { "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
|
4582 { "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
|
4583 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4584 /* Miscellaneous */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4585 { "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
|
4586 { "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
|
4587 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4588 /* Special methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4589 { "__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
|
4590 { "__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
|
4591 { "__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
|
4592 { "__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
|
4593 { "__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
|
4594 { "__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
|
4595 { "__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
|
4596 { "__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
|
4597 { "__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
|
4598 { "__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
|
4599 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4600 { NULL, NULL, 1 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4601 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4602 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4603 static PyTypeObject PyDec_Type = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4604 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4605 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
|
4606 "decimal.Decimal", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4607 sizeof(PyDecObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4608 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4609 (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
|
4610 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4611 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4612 (setattrfunc) 0, /* tp_setattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4613 0, /* tp_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4614 (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
|
4615 &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
|
4616 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4617 0, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4618 (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
|
4619 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4620 (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
|
4621 (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
|
4622 (setattrofunc) 0, /* tp_setattro */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4623 (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
|
4624 (Py_TPFLAGS_DEFAULT| |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4625 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
|
4626 doc_decimal, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4627 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4628 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4629 dec_richcompare, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4630 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4631 0, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4632 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4633 dec_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4634 0, /* tp_members */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4635 dec_getsets, /* tp_getset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4636 0, /* tp_base */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4637 0, /* tp_dict */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4638 0, /* tp_descr_get */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4639 0, /* tp_descr_set */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4640 0, /* tp_dictoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4641 0, /* tp_init */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4642 0, /* tp_alloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4643 dec_new, /* tp_new */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4644 PyObject_Del, /* tp_free */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4645 }; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4648 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4649 /* Context Object, Part 2 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4650 /******************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4651 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4652 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4653 /************************************************************************/ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4654 /* 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
|
4655 /************************************************************************/ |
|
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 context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4658 #define DecCtx_BoolFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4659 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4660 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
|
4661 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4662 PyObject *ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4663 PyObject *a; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4664 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4665 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
|
4666 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4667 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
|
4668 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4669 return ret; \ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4672 /* 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
|
4673 #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
|
4674 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4675 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
|
4676 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4677 PyObject *ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4678 PyObject *a; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4679 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4680 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
|
4681 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4682 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
|
4683 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4684 return ret; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4685 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4686 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4687 /* Unary context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4688 #define DecCtx_UnaryFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4689 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4690 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
|
4691 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4692 PyObject *result, *a; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4693 uint32_t status = 0; \ |
|
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 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
|
4696 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4697 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
|
4698 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4699 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4700 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4701 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4702 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
|
4703 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4704 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
|
4705 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4706 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4707 } \ |
|
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 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4710 } |
|
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 /* Binary context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4713 #define DecCtx_BinaryFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4714 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4715 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
|
4716 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4717 PyObject *v, *w; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4718 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4719 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4720 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4721 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4722 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
|
4723 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4724 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4725 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4726 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
|
4727 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4728 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
|
4729 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4730 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4731 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4732 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4733 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4734 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
|
4735 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4736 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4737 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
|
4738 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4739 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4740 } \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4741 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4742 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4743 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4744 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4745 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4746 * 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
|
4747 * 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
|
4748 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4749 #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
|
4750 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4751 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
|
4752 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4753 PyObject *v, *w; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4754 PyObject *a, *b; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4755 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4756 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4757 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
|
4758 return NULL; \ |
|
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 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
|
4762 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4763 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
|
4764 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4765 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4766 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4767 } \ |
|
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 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
|
4770 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4771 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4772 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4773 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4774 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4775 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4776 /* Ternary context method. */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4777 #define DecCtx_TernaryFunc(MPDFUNC) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4778 static PyObject * \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4779 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
|
4780 { \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4781 PyObject *v, *w, *x; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4782 PyObject *a, *b, *c; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4783 PyObject *result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4784 uint32_t status = 0; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4785 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4786 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
|
4787 return NULL; \ |
|
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 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4790 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
|
4791 \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4792 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
|
4793 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4794 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4795 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4796 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4797 } \ |
|
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 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
|
4800 Py_DECREF(a); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4801 Py_DECREF(b); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4802 Py_DECREF(c); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4803 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
|
4804 Py_DECREF(result); \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4805 return NULL; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4806 } \ |
|
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 return result; \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4809 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4810 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4811 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4812 /* Unary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4813 DecCtx_UnaryFunc(mpd_qabs) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4814 DecCtx_UnaryFunc(mpd_qexp) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4815 DecCtx_UnaryFunc(mpd_qln) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4816 DecCtx_UnaryFunc(mpd_qlog10) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4817 DecCtx_UnaryFunc(mpd_qminus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4818 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
|
4819 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
|
4820 DecCtx_UnaryFunc(mpd_qplus) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4821 DecCtx_UnaryFunc(mpd_qreduce) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4822 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
|
4823 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
|
4824 DecCtx_UnaryFunc(mpd_qsqrt) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4825 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4826 /* Binary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4827 DecCtx_BinaryFunc(mpd_qadd) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4828 DecCtx_BinaryFunc(mpd_qcompare) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4829 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
|
4830 DecCtx_BinaryFunc(mpd_qdiv) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4831 DecCtx_BinaryFunc(mpd_qdivint) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4832 DecCtx_BinaryFunc(mpd_qmax) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4833 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
|
4834 DecCtx_BinaryFunc(mpd_qmin) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4835 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
|
4836 DecCtx_BinaryFunc(mpd_qmul) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4837 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
|
4838 DecCtx_BinaryFunc(mpd_qquantize) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4839 DecCtx_BinaryFunc(mpd_qrem) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4840 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
|
4841 DecCtx_BinaryFunc(mpd_qsub) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4842 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4843 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4844 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
|
4845 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4846 PyObject *v, *w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4847 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4848 PyObject *q, *r; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4849 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4850 PyObject *ret; |
|
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 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
|
4853 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4854 } |
|
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 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
|
4857 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4858 q = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4859 if (q == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4860 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4861 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4862 return NULL; |
|
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 r = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4865 if (r == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4866 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4867 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4868 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4869 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4870 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4871 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4872 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
|
4873 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4874 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4875 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
|
4876 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4877 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4878 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4881 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
|
4882 Py_DECREF(r); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4883 Py_DECREF(q); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4884 return ret; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4885 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4886 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4887 /* 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
|
4888 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4889 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
|
4890 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4891 static char *kwlist[] = {"a", "b", "modulo", NULL}; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4892 PyObject *base, *exp, *mod = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4893 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
|
4894 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4895 uint32_t status = 0; |
|
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 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
|
4898 &base, &exp, &mod)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4899 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4900 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4901 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4902 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
|
4903 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4904 if (mod != NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4905 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
|
4906 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4907 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4908 return c; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4909 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4910 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4911 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4912 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4913 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4914 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4915 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4916 Py_XDECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4917 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4920 if (c == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4921 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
|
4922 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4923 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4924 else { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4925 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
|
4926 CTX(context), &status); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4927 Py_DECREF(c); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4928 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4929 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4930 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4931 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
|
4932 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4933 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4934 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4935 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4936 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4937 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4938 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4939 /* Ternary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4940 DecCtx_TernaryFunc(mpd_qfma) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4941 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4942 /* No argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4943 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4944 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
|
4945 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4946 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
|
4947 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4948 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4949 /* 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
|
4950 DecCtx_BoolFunc(mpd_isnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4951 DecCtx_BoolFunc(mpd_issubnormal) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4952 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
|
4953 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
|
4954 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
|
4955 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
|
4956 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
|
4957 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
|
4958 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
|
4959 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4960 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4961 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
|
4962 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4963 if (!PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4964 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4965 "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
|
4966 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4967 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4968 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4969 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
|
4970 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4971 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4972 /* 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
|
4973 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4974 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
|
4975 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4976 PyObject *result, *a; |
|
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 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
|
4979 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4980 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
|
4981 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4982 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4983 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4984 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4985 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4986 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
|
4987 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4988 if (!PyDec_Check(v)) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4989 PyErr_SetString(PyExc_TypeError, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4990 "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
|
4991 return NULL; |
|
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 Py_INCREF(v); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4995 return v; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4996 } |
|
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 PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4999 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
|
5000 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5001 PyObject *result, *a; |
|
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 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
|
5005 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5006 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5007 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5008 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5009 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5010 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5011 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5012 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
|
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 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
|
5015 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5016 return NULL; |
|
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 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5020 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5021 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5022 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5023 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
|
5024 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5025 PyObject *result; |
|
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 CONVERT_OP_RAISE(&result, v, context); |
| 76124 | 5028 return result; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5029 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5032 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
|
5033 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5034 PyObject *result, *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5035 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5036 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5037 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
|
5038 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5039 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5040 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5041 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5042 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5043 } |
|
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 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
|
5046 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5047 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
|
5048 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5049 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5050 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5051 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5052 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5053 } |
|
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 DecCtx_UnaryFunc(mpd_qlogb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5056 DecCtx_UnaryFunc(mpd_qinvert) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5057 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5058 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5059 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
|
5060 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5061 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5062 const char *cp; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5063 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5064 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
|
5065 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5066 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
|
5067 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5068 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5069 return PyUnicode_FromString(cp); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5070 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5071 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5072 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5073 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
|
5074 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5075 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5076 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5077 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5078 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5079 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5080 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
|
5081 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5082 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
|
5083 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5084 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5085 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5086 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5087 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5088 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5089 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
|
5090 mpd_free(s); |
|
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 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5093 } |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5096 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
|
5097 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5098 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5099 PyObject *a; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5100 mpd_ssize_t size; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5101 char *s; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5102 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5103 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
|
5104 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5105 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
|
5106 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5107 if (size < 0) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5108 PyErr_NoMemory(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5109 return NULL; |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5112 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
|
5113 mpd_free(s); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5114 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5115 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5116 } |
|
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 /* 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
|
5119 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
|
5120 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
|
5121 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5122 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5123 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
|
5124 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5125 PyObject *v, *w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5126 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5127 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5128 uint32_t status = 0; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5129 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5130 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
|
5131 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5132 } |
|
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_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
|
5135 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5136 result = dec_alloc(); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5137 if (result == NULL) { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5138 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5139 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5140 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5141 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5142 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5143 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
|
5144 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5145 Py_DECREF(b); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5146 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
|
5147 Py_DECREF(result); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5148 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5149 } |
|
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 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5152 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5153 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5154 DecCtx_BinaryFunc(mpd_qand) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5155 DecCtx_BinaryFunc(mpd_qor) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5156 DecCtx_BinaryFunc(mpd_qxor) |
|
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 DecCtx_BinaryFunc(mpd_qrotate) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5159 DecCtx_BinaryFunc(mpd_qscaleb) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5160 DecCtx_BinaryFunc(mpd_qshift) |
|
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 static PyObject * |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5163 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
|
5164 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5165 PyObject *v, *w; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5166 PyObject *a, *b; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5167 PyObject *result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5168 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5169 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
|
5170 return NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5171 } |
|
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 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
|
5174 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5175 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
|
5176 Py_DECREF(a); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5177 Py_DECREF(b); |
|
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 return result; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5180 } |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5183 static PyMethodDef context_methods [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5184 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5185 /* Unary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5186 { "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
|
5187 { "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
|
5188 { "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
|
5189 { "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
|
5190 { "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
|
5191 { "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
|
5192 { "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
|
5193 { "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
|
5194 { "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
|
5195 { "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
|
5196 { "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
|
5197 { "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
|
5198 { "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
|
5199 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5200 /* Binary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5201 { "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
|
5202 { "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
|
5203 { "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
|
5204 { "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
|
5205 { "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
|
5206 { "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
|
5207 { "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
|
5208 { "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
|
5209 { "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
|
5210 { "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
|
5211 { "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
|
5212 { "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
|
5213 { "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
|
5214 { "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
|
5215 { "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
|
5216 { "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
|
5217 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5218 /* 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
|
5219 { "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
|
5220 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5221 /* Ternary arithmetic functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5222 { "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
|
5223 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5224 /* No argument */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5225 { "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
|
5226 { "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
|
5227 { "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
|
5228 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5229 /* Boolean functions */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5230 { "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
|
5231 { "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
|
5232 { "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
|
5233 { "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
|
5234 { "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
|
5235 { "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
|
5236 { "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
|
5237 { "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
|
5238 { "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
|
5239 { "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
|
5240 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5241 /* 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
|
5242 { "_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
|
5243 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5244 { "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
|
5245 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5246 { "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
|
5247 { "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
|
5248 { "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
|
5249 { "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
|
5250 { "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
|
5251 { "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
|
5252 { "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
|
5253 { "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
|
5254 { "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
|
5255 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5256 /* 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
|
5257 { "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
|
5258 { "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
|
5259 { "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
|
5260 { "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
|
5261 { "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
|
5262 { "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
|
5263 { "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
|
5264 { "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
|
5265 { "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
|
5266 { "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
|
5267 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5268 /* Set context values */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5269 { "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
|
5270 { "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
|
5271 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5272 #ifdef CONFIG_32 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5273 /* 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
|
5274 { "_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
|
5275 { "_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
|
5276 { "_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
|
5277 #endif |
|
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 /* Miscellaneous */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5280 { "__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
|
5281 { "__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
|
5282 { "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
|
5283 { "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
|
5284 { "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
|
5285 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5286 { NULL, NULL, 1 } |
|
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 static PyTypeObject PyDecContext_Type = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5290 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5291 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
|
5292 "decimal.Context", /* tp_name */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5293 sizeof(PyDecContextObject), /* tp_basicsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5294 0, /* tp_itemsize */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5295 (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
|
5296 0, /* tp_print */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5297 (getattrfunc) 0, /* tp_getattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5298 (setattrfunc) 0, /* tp_setattr */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5299 0, /* tp_reserved */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5300 (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
|
5301 0, /* tp_as_number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5302 0, /* tp_as_sequence */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5303 0, /* tp_as_mapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5304 (hashfunc) 0, /* tp_hash */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5305 0, /* tp_call */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5306 (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
|
5307 (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
|
5308 (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
|
5309 (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
|
5310 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
|
5311 doc_context, /* tp_doc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5312 0, /* tp_traverse */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5313 0, /* tp_clear */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5314 0, /* tp_richcompare */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5315 0, /* tp_weaklistoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5316 0, /* tp_iter */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5317 0, /* tp_iternext */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5318 context_methods, /* tp_methods */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5319 0, /* tp_members */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5320 context_getsets, /* tp_getset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5321 0, /* tp_base */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5322 0, /* tp_dict */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5323 0, /* tp_descr_get */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5324 0, /* tp_descr_set */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5325 0, /* tp_dictoffset */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5326 context_init, /* tp_init */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5327 0, /* tp_alloc */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5328 context_new, /* tp_new */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5329 PyObject_Del, /* tp_free */ |
|
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 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5332 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5333 static PyMethodDef _decimal_methods [] = |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5334 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5335 { "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
|
5336 { "setcontext", (PyCFunction)PyDec_SetCurrentContext, METH_O, doc_setcontext}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5337 { "localcontext", (PyCFunction)ctxmanager_new, METH_VARARGS, doc_localcontext}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5338 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5339 { "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
|
5340 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5341 { NULL, NULL, 1, NULL } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5342 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5343 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5344 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
|
5345 PyModuleDef_HEAD_INIT, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5346 "decimal", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5347 doc__decimal, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5348 -1, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5349 _decimal_methods, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5350 NULL, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5351 NULL, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5352 NULL, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5353 NULL |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5354 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5355 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5356 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
|
5357 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
|
5358 {"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
|
5359 {"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
|
5360 {"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
|
5361 {"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
|
5362 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5363 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5364 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5365 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
|
5366 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
|
5367 /* int constants */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5368 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5369 {"DECIMAL32", MPD_DECIMAL32}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5370 {"DECIMAL64", MPD_DECIMAL64}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5371 {"DECIMAL128", MPD_DECIMAL128}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5372 {"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
|
5373 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5374 {"ROUND_CEILING", MPD_ROUND_CEILING}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5375 {"ROUND_FLOOR", MPD_ROUND_FLOOR}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5376 {"ROUND_UP", MPD_ROUND_UP}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5377 {"ROUND_DOWN", MPD_ROUND_DOWN}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5378 {"ROUND_HALF_UP", MPD_ROUND_HALF_UP}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5379 {"ROUND_HALF_DOWN", MPD_ROUND_HALF_DOWN}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5380 {"ROUND_HALF_EVEN", MPD_ROUND_HALF_EVEN}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5381 {"ROUND_05UP", MPD_ROUND_05UP}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5382 #ifdef EXTRA_FUNCTIONALITY |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5383 {"ROUND_TRUNC", MPD_ROUND_TRUNC}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5384 /* int condition flags */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5385 {"DecClamped", MPD_Clamped}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5386 {"DecConversionSyntax", MPD_Conversion_syntax}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5387 {"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
|
5388 {"DecDivisionImpossible", MPD_Division_impossible}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5389 {"DecDivisionUndefined", MPD_Division_undefined}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5390 {"DecFpuError", MPD_Fpu_error}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5391 {"DecInexact", MPD_Inexact}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5392 {"DecInvalidContext", MPD_Invalid_context}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5393 {"DecInvalidOperation", MPD_Invalid_operation}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5394 {"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
|
5395 {"DecMallocError", MPD_Malloc_error}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5396 {"DecFloatOperation", MPD_Float_operation}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5397 {"DecOverflow", MPD_Overflow}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5398 {"DecRounded", MPD_Rounded}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5399 {"DecSubnormal", MPD_Subnormal}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5400 {"DecUnderflow", MPD_Underflow}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5401 {"DecErrors", MPD_Errors}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5402 {"DecTraps", MPD_Traps}, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5403 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5404 {NULL} |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5405 }; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5406 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5407 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5408 #define CHECK_INT(expr) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5409 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
|
5410 #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
|
5411 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
|
5412 #define CHECK_PTR(expr) \ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5413 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
|
5414 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5415 PyMODINIT_FUNC |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5416 PyInit__decimal(void) |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5417 { |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5418 PyObject *m = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5419 PyObject *numbers = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5420 PyObject *Number = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5421 PyObject *collections = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5422 PyObject *MutableMapping = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5423 PyObject *obj = NULL; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5424 DecCondMap *cm; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5425 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
|
5426 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
|
5427 int i; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5428 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5429 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5430 /* Init libmpdec */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5431 mpd_traphandler = dec_traphandler; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5432 mpd_mallocfunc = PyMem_Malloc; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5433 mpd_reallocfunc = PyMem_Realloc; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5434 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
|
5435 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
|
5436 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
|
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 /* Init types */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5440 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
|
5441 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
|
5442 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
|
5443 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
|
5444 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5445 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
|
5446 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
|
5447 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
|
5448 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
|
5449 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5450 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
|
5451 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
|
5452 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
|
5453 "__module__", obj)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5454 Py_CLEAR(obj); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5455 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5456 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5457 /* Numeric abstract base classes */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5458 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
|
5459 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
|
5460 /* 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
|
5461 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
|
5462 (PyObject *)&PyDec_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5463 Py_CLEAR(obj); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5464 /* 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
|
5465 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
|
5466 /* Done with numbers, Number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5467 Py_CLEAR(numbers); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5468 Py_CLEAR(Number); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5469 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5470 /* DecimalTuple */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5471 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
|
5472 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
|
5473 "namedtuple", "(ss)", "DecimalTuple", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5474 "sign digits exponent")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5475 /* MutableMapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5476 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
|
5477 "MutableMapping")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5478 /* Create SignalDict type */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5479 ASSIGN_PTR(PyDecSignalDict_Type, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5480 (PyTypeObject *)PyObject_CallFunction( |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5481 (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
|
5482 "SignalDict", &PyDecSignalDictMixin_Type, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5483 MutableMapping)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5484 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5485 /* Done with collections, MutableMapping */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5486 Py_CLEAR(collections); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5487 Py_CLEAR(MutableMapping); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5488 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5489 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5490 /* Create the module */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5491 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
|
5492 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5493 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5494 /* 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
|
5495 Py_INCREF(&PyDec_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5496 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
|
5497 Py_INCREF(&PyDecContext_Type); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5498 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
|
5499 (PyObject *)&PyDecContext_Type)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5500 Py_INCREF(DecimalTuple); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5501 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
|
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 /* Create top level exception */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5505 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
|
5506 "decimal.DecimalException", |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5507 PyExc_ArithmeticError, NULL)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5508 Py_INCREF(DecimalException); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5509 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
|
5510 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5511 /* Create signal tuple */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5512 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
|
5513 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5514 /* 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
|
5515 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
|
5516 PyObject *base; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5517 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5518 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
|
5519 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5520 switch (cm->flag) { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5521 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
|
5522 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
|
5523 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5524 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
|
5525 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
|
5526 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5527 case MPD_Overflow: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5528 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
|
5529 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
|
5530 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5531 case MPD_Underflow: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5532 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
|
5533 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
|
5534 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
|
5535 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5536 default: |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5537 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
|
5538 break; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5539 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5540 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5541 if (base == NULL) { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5542 goto error; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5543 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5544 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5545 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
|
5546 Py_DECREF(base); |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5547 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5548 /* add to module */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5549 Py_INCREF(cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5550 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
|
5551 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5552 /* add to signal tuple */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5553 Py_INCREF(cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5554 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
|
5555 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5556 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5557 /* |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5558 * 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
|
5559 * 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
|
5560 * 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
|
5561 */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5562 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
|
5563 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5564 /* 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
|
5565 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
|
5566 PyObject *base; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5567 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
|
5568 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
|
5569 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5570 else { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5571 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
|
5572 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5573 if (base == NULL) { |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5574 goto error; |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5575 } |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5576 |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5577 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
|
5578 Py_DECREF(base); |
|
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5579 |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5580 Py_INCREF(cm->ex); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5581 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
|
5582 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5583 |
|
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 /* 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
|
5586 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
|
5587 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
|
5588 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
|
5589 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
|
5590 default_context_template)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5591 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5592 #ifdef WITHOUT_THREADS |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5593 /* Init module context */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5594 ASSIGN_PTR(module_context, |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5595 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
|
5596 Py_INCREF(Py_False); |
|
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, "HAVE_THREADS", Py_False)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5598 #else |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5599 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
|
5600 Py_INCREF(Py_True); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5601 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
|
5602 #endif |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5603 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5604 /* Init basic context template */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5605 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
|
5606 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
|
5607 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
|
5608 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
|
5609 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
|
5610 basic_context_template)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5611 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5612 /* Init extended context template */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5613 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
|
5614 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
|
5615 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
|
5616 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
|
5617 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
|
5618 extended_context_template)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5619 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5620 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5621 /* 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
|
5622 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
|
5623 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
|
5624 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
|
5625 obj = NULL; |
|
75850
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5626 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5627 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5628 /* Init int constants */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5629 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
|
5630 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
|
5631 int_cm->val)); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5632 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5633 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5634 /* Add specification version number */ |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5635 CHECK_INT(PyModule_AddStringConstant(m, "__version__", " 1.70")); |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5636 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5637 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5638 return m; |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5639 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5640 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5641 error: |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5642 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
|
5643 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
|
5644 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
|
5645 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
|
5646 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
|
5647 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
|
5648 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
|
5649 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
|
5650 #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
|
5651 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
|
5652 #else |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5653 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
|
5654 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
|
5655 #endif |
|
75899
94009b75a09d
Use the same exception hierarchy as decimal.py. FloatOperation now also
Stefan Krah <skrah@bytereef.org>
parents:
75862
diff
changeset
|
5656 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
|
5657 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
|
5658 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
|
5659 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5660 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
|
5661 } |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5662 |
|
7355550d5357
Issue #7652: Integrate the decimal floating point libmpdec library to speed
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5663 |
