File Objects/clinic/floatobject.c.h added (mode: 100644) (index 0000000000..18c6918c17) |
|
1 |
|
/*[clinic input] |
|
2 |
|
preserve |
|
3 |
|
[clinic start generated code]*/ |
|
4 |
|
|
|
5 |
|
PyDoc_STRVAR(float_is_integer__doc__, |
|
6 |
|
"is_integer($self, /)\n" |
|
7 |
|
"--\n" |
|
8 |
|
"\n" |
|
9 |
|
"Return True if the float is an integer."); |
|
10 |
|
|
|
11 |
|
#define FLOAT_IS_INTEGER_METHODDEF \ |
|
12 |
|
{"is_integer", (PyCFunction)float_is_integer, METH_NOARGS, float_is_integer__doc__}, |
|
13 |
|
|
|
14 |
|
static PyObject * |
|
15 |
|
float_is_integer_impl(PyObject *self); |
|
16 |
|
|
|
17 |
|
static PyObject * |
|
18 |
|
float_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored)) |
|
19 |
|
{ |
|
20 |
|
return float_is_integer_impl(self); |
|
21 |
|
} |
|
22 |
|
|
|
23 |
|
PyDoc_STRVAR(float___trunc____doc__, |
|
24 |
|
"__trunc__($self, /)\n" |
|
25 |
|
"--\n" |
|
26 |
|
"\n" |
|
27 |
|
"Return the Integral closest to x between 0 and x."); |
|
28 |
|
|
|
29 |
|
#define FLOAT___TRUNC___METHODDEF \ |
|
30 |
|
{"__trunc__", (PyCFunction)float___trunc__, METH_NOARGS, float___trunc____doc__}, |
|
31 |
|
|
|
32 |
|
static PyObject * |
|
33 |
|
float___trunc___impl(PyObject *self); |
|
34 |
|
|
|
35 |
|
static PyObject * |
|
36 |
|
float___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
|
37 |
|
{ |
|
38 |
|
return float___trunc___impl(self); |
|
39 |
|
} |
|
40 |
|
|
|
41 |
|
PyDoc_STRVAR(float___round____doc__, |
|
42 |
|
"__round__($self, ndigits=None, /)\n" |
|
43 |
|
"--\n" |
|
44 |
|
"\n" |
|
45 |
|
"Return the Integral closest to x, rounding half toward even.\n" |
|
46 |
|
"\n" |
|
47 |
|
"When an argument is passed, work like built-in round(x, ndigits)."); |
|
48 |
|
|
|
49 |
|
#define FLOAT___ROUND___METHODDEF \ |
|
50 |
|
{"__round__", (PyCFunction)float___round__, METH_FASTCALL, float___round____doc__}, |
|
51 |
|
|
|
52 |
|
static PyObject * |
|
53 |
|
float___round___impl(PyObject *self, PyObject *o_ndigits); |
|
54 |
|
|
|
55 |
|
static PyObject * |
|
56 |
|
float___round__(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
|
57 |
|
{ |
|
58 |
|
PyObject *return_value = NULL; |
|
59 |
|
PyObject *o_ndigits = NULL; |
|
60 |
|
|
|
61 |
|
if (!_PyArg_UnpackStack(args, nargs, "__round__", |
|
62 |
|
0, 1, |
|
63 |
|
&o_ndigits)) { |
|
64 |
|
goto exit; |
|
65 |
|
} |
|
66 |
|
|
|
67 |
|
if (!_PyArg_NoStackKeywords("__round__", kwnames)) { |
|
68 |
|
goto exit; |
|
69 |
|
} |
|
70 |
|
return_value = float___round___impl(self, o_ndigits); |
|
71 |
|
|
|
72 |
|
exit: |
|
73 |
|
return return_value; |
|
74 |
|
} |
|
75 |
|
|
|
76 |
|
PyDoc_STRVAR(float_conjugate__doc__, |
|
77 |
|
"conjugate($self, /)\n" |
|
78 |
|
"--\n" |
|
79 |
|
"\n" |
|
80 |
|
"Return self, the complex conjugate of any float."); |
|
81 |
|
|
|
82 |
|
#define FLOAT_CONJUGATE_METHODDEF \ |
|
83 |
|
{"conjugate", (PyCFunction)float_conjugate, METH_NOARGS, float_conjugate__doc__}, |
|
84 |
|
|
|
85 |
|
static PyObject * |
|
86 |
|
float_conjugate_impl(PyObject *self); |
|
87 |
|
|
|
88 |
|
static PyObject * |
|
89 |
|
float_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) |
|
90 |
|
{ |
|
91 |
|
return float_conjugate_impl(self); |
|
92 |
|
} |
|
93 |
|
|
|
94 |
|
PyDoc_STRVAR(float_hex__doc__, |
|
95 |
|
"hex($self, /)\n" |
|
96 |
|
"--\n" |
|
97 |
|
"\n" |
|
98 |
|
"Return a hexadecimal representation of a floating-point number.\n" |
|
99 |
|
"\n" |
|
100 |
|
">>> (-0.1).hex()\n" |
|
101 |
|
"\'-0x1.999999999999ap-4\'\n" |
|
102 |
|
">>> 3.14159.hex()\n" |
|
103 |
|
"\'0x1.921f9f01b866ep+1\'"); |
|
104 |
|
|
|
105 |
|
#define FLOAT_HEX_METHODDEF \ |
|
106 |
|
{"hex", (PyCFunction)float_hex, METH_NOARGS, float_hex__doc__}, |
|
107 |
|
|
|
108 |
|
static PyObject * |
|
109 |
|
float_hex_impl(PyObject *self); |
|
110 |
|
|
|
111 |
|
static PyObject * |
|
112 |
|
float_hex(PyObject *self, PyObject *Py_UNUSED(ignored)) |
|
113 |
|
{ |
|
114 |
|
return float_hex_impl(self); |
|
115 |
|
} |
|
116 |
|
|
|
117 |
|
PyDoc_STRVAR(float_fromhex__doc__, |
|
118 |
|
"fromhex($type, string, /)\n" |
|
119 |
|
"--\n" |
|
120 |
|
"\n" |
|
121 |
|
"Create a floating-point number from a hexadecimal string.\n" |
|
122 |
|
"\n" |
|
123 |
|
">>> float.fromhex(\'0x1.ffffp10\')\n" |
|
124 |
|
"2047.984375\n" |
|
125 |
|
">>> float.fromhex(\'-0x1p-1074\')\n" |
|
126 |
|
"-5e-324"); |
|
127 |
|
|
|
128 |
|
#define FLOAT_FROMHEX_METHODDEF \ |
|
129 |
|
{"fromhex", (PyCFunction)float_fromhex, METH_O|METH_CLASS, float_fromhex__doc__}, |
|
130 |
|
|
|
131 |
|
PyDoc_STRVAR(float_as_integer_ratio__doc__, |
|
132 |
|
"as_integer_ratio($self, /)\n" |
|
133 |
|
"--\n" |
|
134 |
|
"\n" |
|
135 |
|
"Return integer ratio.\n" |
|
136 |
|
"\n" |
|
137 |
|
"Return a pair of integers, whose ratio is exactly equal to the original float\n" |
|
138 |
|
"and with a positive denominator.\n" |
|
139 |
|
"\n" |
|
140 |
|
"Raise OverflowError on infinities and a ValueError on NaNs.\n" |
|
141 |
|
"\n" |
|
142 |
|
">>> (10.0).as_integer_ratio()\n" |
|
143 |
|
"(10, 1)\n" |
|
144 |
|
">>> (0.0).as_integer_ratio()\n" |
|
145 |
|
"(0, 1)\n" |
|
146 |
|
">>> (-.25).as_integer_ratio()\n" |
|
147 |
|
"(-1, 4)"); |
|
148 |
|
|
|
149 |
|
#define FLOAT_AS_INTEGER_RATIO_METHODDEF \ |
|
150 |
|
{"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS, float_as_integer_ratio__doc__}, |
|
151 |
|
|
|
152 |
|
static PyObject * |
|
153 |
|
float_as_integer_ratio_impl(PyObject *self); |
|
154 |
|
|
|
155 |
|
static PyObject * |
|
156 |
|
float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) |
|
157 |
|
{ |
|
158 |
|
return float_as_integer_ratio_impl(self); |
|
159 |
|
} |
|
160 |
|
|
|
161 |
|
PyDoc_STRVAR(float___getnewargs____doc__, |
|
162 |
|
"__getnewargs__($self, /)\n" |
|
163 |
|
"--\n" |
|
164 |
|
"\n"); |
|
165 |
|
|
|
166 |
|
#define FLOAT___GETNEWARGS___METHODDEF \ |
|
167 |
|
{"__getnewargs__", (PyCFunction)float___getnewargs__, METH_NOARGS, float___getnewargs____doc__}, |
|
168 |
|
|
|
169 |
|
static PyObject * |
|
170 |
|
float___getnewargs___impl(PyObject *self); |
|
171 |
|
|
|
172 |
|
static PyObject * |
|
173 |
|
float___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
|
174 |
|
{ |
|
175 |
|
return float___getnewargs___impl(self); |
|
176 |
|
} |
|
177 |
|
|
|
178 |
|
PyDoc_STRVAR(float___getformat____doc__, |
|
179 |
|
"__getformat__($type, typestr, /)\n" |
|
180 |
|
"--\n" |
|
181 |
|
"\n" |
|
182 |
|
"You probably don\'t want to use this function.\n" |
|
183 |
|
"\n" |
|
184 |
|
" typestr\n" |
|
185 |
|
" Must be \'double\' or \'float\'.\n" |
|
186 |
|
"\n" |
|
187 |
|
"It exists mainly to be used in Python\'s test suite.\n" |
|
188 |
|
"\n" |
|
189 |
|
"This function returns whichever of \'unknown\', \'IEEE, big-endian\' or \'IEEE,\n" |
|
190 |
|
"little-endian\' best describes the format of floating point numbers used by the\n" |
|
191 |
|
"C type named by typestr."); |
|
192 |
|
|
|
193 |
|
#define FLOAT___GETFORMAT___METHODDEF \ |
|
194 |
|
{"__getformat__", (PyCFunction)float___getformat__, METH_O|METH_CLASS, float___getformat____doc__}, |
|
195 |
|
|
|
196 |
|
static PyObject * |
|
197 |
|
float___getformat___impl(PyTypeObject *type, const char *typestr); |
|
198 |
|
|
|
199 |
|
static PyObject * |
|
200 |
|
float___getformat__(PyTypeObject *type, PyObject *arg) |
|
201 |
|
{ |
|
202 |
|
PyObject *return_value = NULL; |
|
203 |
|
const char *typestr; |
|
204 |
|
|
|
205 |
|
if (!PyArg_Parse(arg, "s:__getformat__", &typestr)) { |
|
206 |
|
goto exit; |
|
207 |
|
} |
|
208 |
|
return_value = float___getformat___impl(type, typestr); |
|
209 |
|
|
|
210 |
|
exit: |
|
211 |
|
return return_value; |
|
212 |
|
} |
|
213 |
|
|
|
214 |
|
PyDoc_STRVAR(float___set_format____doc__, |
|
215 |
|
"__set_format__($type, typestr, fmt, /)\n" |
|
216 |
|
"--\n" |
|
217 |
|
"\n" |
|
218 |
|
"You probably don\'t want to use this function.\n" |
|
219 |
|
"\n" |
|
220 |
|
" typestr\n" |
|
221 |
|
" Must be \'double\' or \'float\'.\n" |
|
222 |
|
" fmt\n" |
|
223 |
|
" Must be one of \'unknown\', \'IEEE, big-endian\' or \'IEEE, little-endian\',\n" |
|
224 |
|
" and in addition can only be one of the latter two if it appears to\n" |
|
225 |
|
" match the underlying C reality.\n" |
|
226 |
|
"\n" |
|
227 |
|
"It exists mainly to be used in Python\'s test suite.\n" |
|
228 |
|
"\n" |
|
229 |
|
"Override the automatic determination of C-level floating point type.\n" |
|
230 |
|
"This affects how floats are converted to and from binary strings."); |
|
231 |
|
|
|
232 |
|
#define FLOAT___SET_FORMAT___METHODDEF \ |
|
233 |
|
{"__set_format__", (PyCFunction)float___set_format__, METH_FASTCALL|METH_CLASS, float___set_format____doc__}, |
|
234 |
|
|
|
235 |
|
static PyObject * |
|
236 |
|
float___set_format___impl(PyTypeObject *type, const char *typestr, |
|
237 |
|
const char *fmt); |
|
238 |
|
|
|
239 |
|
static PyObject * |
|
240 |
|
float___set_format__(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
|
241 |
|
{ |
|
242 |
|
PyObject *return_value = NULL; |
|
243 |
|
const char *typestr; |
|
244 |
|
const char *fmt; |
|
245 |
|
|
|
246 |
|
if (!_PyArg_ParseStack(args, nargs, "ss:__set_format__", |
|
247 |
|
&typestr, &fmt)) { |
|
248 |
|
goto exit; |
|
249 |
|
} |
|
250 |
|
|
|
251 |
|
if (!_PyArg_NoStackKeywords("__set_format__", kwnames)) { |
|
252 |
|
goto exit; |
|
253 |
|
} |
|
254 |
|
return_value = float___set_format___impl(type, typestr, fmt); |
|
255 |
|
|
|
256 |
|
exit: |
|
257 |
|
return return_value; |
|
258 |
|
} |
|
259 |
|
|
|
260 |
|
PyDoc_STRVAR(float___format____doc__, |
|
261 |
|
"__format__($self, format_spec, /)\n" |
|
262 |
|
"--\n" |
|
263 |
|
"\n" |
|
264 |
|
"Formats the float according to format_spec."); |
|
265 |
|
|
|
266 |
|
#define FLOAT___FORMAT___METHODDEF \ |
|
267 |
|
{"__format__", (PyCFunction)float___format__, METH_O, float___format____doc__}, |
|
268 |
|
|
|
269 |
|
static PyObject * |
|
270 |
|
float___format___impl(PyObject *self, PyObject *format_spec); |
|
271 |
|
|
|
272 |
|
static PyObject * |
|
273 |
|
float___format__(PyObject *self, PyObject *arg) |
|
274 |
|
{ |
|
275 |
|
PyObject *return_value = NULL; |
|
276 |
|
PyObject *format_spec; |
|
277 |
|
|
|
278 |
|
if (!PyArg_Parse(arg, "U:__format__", &format_spec)) { |
|
279 |
|
goto exit; |
|
280 |
|
} |
|
281 |
|
return_value = float___format___impl(self, format_spec); |
|
282 |
|
|
|
283 |
|
exit: |
|
284 |
|
return return_value; |
|
285 |
|
} |
|
286 |
|
/*[clinic end generated code: output=9257442b321d6a8b input=a9049054013a1b77]*/ |
File Objects/floatobject.c changed (mode: 100644) (index 9267b9f27b..8f87f8ec11) |
9 |
9 |
#include <ctype.h> |
#include <ctype.h> |
10 |
10 |
#include <float.h> |
#include <float.h> |
11 |
11 |
|
|
|
12 |
|
/*[clinic input] |
|
13 |
|
class float "PyObject *" "&PyFloat_Type" |
|
14 |
|
[clinic start generated code]*/ |
|
15 |
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=dd0003f68f144284]*/ |
|
16 |
|
|
|
17 |
|
#include "clinic/floatobject.c.h" |
12 |
18 |
|
|
13 |
19 |
/* Special free list |
/* Special free list |
14 |
20 |
free_list is a singly-linked list of available PyFloatObjects, linked |
free_list is a singly-linked list of available PyFloatObjects, linked |
|
... |
... |
float_bool(PyFloatObject *v) |
824 |
830 |
return v->ob_fval != 0.0; |
return v->ob_fval != 0.0; |
825 |
831 |
} |
} |
826 |
832 |
|
|
|
833 |
|
/*[clinic input] |
|
834 |
|
float.is_integer |
|
835 |
|
|
|
836 |
|
Return True if the float is an integer. |
|
837 |
|
[clinic start generated code]*/ |
|
838 |
|
|
827 |
839 |
static PyObject * |
static PyObject * |
828 |
|
float_is_integer(PyObject *v) |
|
|
840 |
|
float_is_integer_impl(PyObject *self) |
|
841 |
|
/*[clinic end generated code: output=7112acf95a4d31ea input=311810d3f777e10d]*/ |
829 |
842 |
{ |
{ |
830 |
|
double x = PyFloat_AsDouble(v); |
|
|
843 |
|
double x = PyFloat_AsDouble(self); |
831 |
844 |
PyObject *o; |
PyObject *o; |
832 |
845 |
|
|
833 |
846 |
if (x == -1.0 && PyErr_Occurred()) |
if (x == -1.0 && PyErr_Occurred()) |
|
... |
... |
float_is_finite(PyObject *v) |
876 |
889 |
} |
} |
877 |
890 |
#endif |
#endif |
878 |
891 |
|
|
|
892 |
|
/*[clinic input] |
|
893 |
|
float.__trunc__ |
|
894 |
|
|
|
895 |
|
Return the Integral closest to x between 0 and x. |
|
896 |
|
[clinic start generated code]*/ |
|
897 |
|
|
879 |
898 |
static PyObject * |
static PyObject * |
880 |
|
float_trunc(PyObject *v) |
|
|
899 |
|
float___trunc___impl(PyObject *self) |
|
900 |
|
/*[clinic end generated code: output=dd3e289dd4c6b538 input=591b9ba0d650fdff]*/ |
881 |
901 |
{ |
{ |
882 |
|
double x = PyFloat_AsDouble(v); |
|
|
902 |
|
double x = PyFloat_AsDouble(self); |
883 |
903 |
double wholepart; /* integral portion of x, rounded toward 0 */ |
double wholepart; /* integral portion of x, rounded toward 0 */ |
884 |
904 |
|
|
885 |
905 |
(void)modf(x, &wholepart); |
(void)modf(x, &wholepart); |
|
... |
... |
double_round(double x, int ndigits) { |
1018 |
1038 |
|
|
1019 |
1039 |
/* round a Python float v to the closest multiple of 10**-ndigits */ |
/* round a Python float v to the closest multiple of 10**-ndigits */ |
1020 |
1040 |
|
|
|
1041 |
|
/*[clinic input] |
|
1042 |
|
float.__round__ |
|
1043 |
|
|
|
1044 |
|
ndigits as o_ndigits: object = NULL |
|
1045 |
|
/ |
|
1046 |
|
|
|
1047 |
|
Return the Integral closest to x, rounding half toward even. |
|
1048 |
|
|
|
1049 |
|
When an argument is passed, work like built-in round(x, ndigits). |
|
1050 |
|
[clinic start generated code]*/ |
|
1051 |
|
|
1021 |
1052 |
static PyObject * |
static PyObject * |
1022 |
|
float_round(PyObject *v, PyObject *args) |
|
|
1053 |
|
float___round___impl(PyObject *self, PyObject *o_ndigits) |
|
1054 |
|
/*[clinic end generated code: output=374c36aaa0f13980 input=1ca2316b510293b8]*/ |
1023 |
1055 |
{ |
{ |
1024 |
1056 |
double x, rounded; |
double x, rounded; |
1025 |
|
PyObject *o_ndigits = NULL; |
|
1026 |
1057 |
Py_ssize_t ndigits; |
Py_ssize_t ndigits; |
1027 |
1058 |
|
|
1028 |
|
x = PyFloat_AsDouble(v); |
|
1029 |
|
if (!PyArg_ParseTuple(args, "|O", &o_ndigits)) |
|
1030 |
|
return NULL; |
|
|
1059 |
|
x = PyFloat_AsDouble(self); |
1031 |
1060 |
if (o_ndigits == NULL || o_ndigits == Py_None) { |
if (o_ndigits == NULL || o_ndigits == Py_None) { |
1032 |
1061 |
/* single-argument round or with None ndigits: |
/* single-argument round or with None ndigits: |
1033 |
1062 |
* round to nearest integer */ |
* round to nearest integer */ |
|
... |
... |
float_float(PyObject *v) |
1075 |
1104 |
return v; |
return v; |
1076 |
1105 |
} |
} |
1077 |
1106 |
|
|
|
1107 |
|
/*[clinic input] |
|
1108 |
|
float.conjugate |
|
1109 |
|
|
|
1110 |
|
Return self, the complex conjugate of any float. |
|
1111 |
|
[clinic start generated code]*/ |
|
1112 |
|
|
|
1113 |
|
static PyObject * |
|
1114 |
|
float_conjugate_impl(PyObject *self) |
|
1115 |
|
/*[clinic end generated code: output=8ca292c2479194af input=82ba6f37a9ff91dd]*/ |
|
1116 |
|
{ |
|
1117 |
|
return float_float(self); |
|
1118 |
|
} |
|
1119 |
|
|
1078 |
1120 |
/* turn ASCII hex characters into integer values and vice versa */ |
/* turn ASCII hex characters into integer values and vice versa */ |
1079 |
1121 |
|
|
1080 |
1122 |
static char |
static char |
|
... |
... |
hex_from_char(char c) { |
1155 |
1197 |
of the form 4k+1. */ |
of the form 4k+1. */ |
1156 |
1198 |
#define TOHEX_NBITS DBL_MANT_DIG + 3 - (DBL_MANT_DIG+2)%4 |
#define TOHEX_NBITS DBL_MANT_DIG + 3 - (DBL_MANT_DIG+2)%4 |
1157 |
1199 |
|
|
|
1200 |
|
/*[clinic input] |
|
1201 |
|
float.hex |
|
1202 |
|
|
|
1203 |
|
Return a hexadecimal representation of a floating-point number. |
|
1204 |
|
|
|
1205 |
|
>>> (-0.1).hex() |
|
1206 |
|
'-0x1.999999999999ap-4' |
|
1207 |
|
>>> 3.14159.hex() |
|
1208 |
|
'0x1.921f9f01b866ep+1' |
|
1209 |
|
[clinic start generated code]*/ |
|
1210 |
|
|
1158 |
1211 |
static PyObject * |
static PyObject * |
1159 |
|
float_hex(PyObject *v) |
|
|
1212 |
|
float_hex_impl(PyObject *self) |
|
1213 |
|
/*[clinic end generated code: output=0ebc9836e4d302d4 input=bec1271a33d47e67]*/ |
1160 |
1214 |
{ |
{ |
1161 |
1215 |
double x, m; |
double x, m; |
1162 |
1216 |
int e, shift, i, si, esign; |
int e, shift, i, si, esign; |
|
... |
... |
float_hex(PyObject *v) |
1164 |
1218 |
trailing NUL byte. */ |
trailing NUL byte. */ |
1165 |
1219 |
char s[(TOHEX_NBITS-1)/4+3]; |
char s[(TOHEX_NBITS-1)/4+3]; |
1166 |
1220 |
|
|
1167 |
|
CONVERT_TO_DOUBLE(v, x); |
|
|
1221 |
|
CONVERT_TO_DOUBLE(self, x); |
1168 |
1222 |
|
|
1169 |
1223 |
if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) |
if (Py_IS_NAN(x) || Py_IS_INFINITY(x)) |
1170 |
|
return float_repr((PyFloatObject *)v); |
|
|
1224 |
|
return float_repr((PyFloatObject *)self); |
1171 |
1225 |
|
|
1172 |
1226 |
if (x == 0.0) { |
if (x == 0.0) { |
1173 |
1227 |
if (copysign(1.0, x) == -1.0) |
if (copysign(1.0, x) == -1.0) |
|
... |
... |
float_hex(PyObject *v) |
1208 |
1262 |
return PyUnicode_FromFormat("0x%sp%c%d", s, esign, e); |
return PyUnicode_FromFormat("0x%sp%c%d", s, esign, e); |
1209 |
1263 |
} |
} |
1210 |
1264 |
|
|
1211 |
|
PyDoc_STRVAR(float_hex_doc, |
|
1212 |
|
"float.hex() -> string\n\ |
|
1213 |
|
\n\ |
|
1214 |
|
Return a hexadecimal representation of a floating-point number.\n\ |
|
1215 |
|
>>> (-0.1).hex()\n\ |
|
1216 |
|
'-0x1.999999999999ap-4'\n\ |
|
1217 |
|
>>> 3.14159.hex()\n\ |
|
1218 |
|
'0x1.921f9f01b866ep+1'"); |
|
1219 |
|
|
|
1220 |
1265 |
/* Convert a hexadecimal string to a float. */ |
/* Convert a hexadecimal string to a float. */ |
1221 |
1266 |
|
|
|
1267 |
|
/*[clinic input] |
|
1268 |
|
@classmethod |
|
1269 |
|
float.fromhex |
|
1270 |
|
|
|
1271 |
|
string: object |
|
1272 |
|
/ |
|
1273 |
|
|
|
1274 |
|
Create a floating-point number from a hexadecimal string. |
|
1275 |
|
|
|
1276 |
|
>>> float.fromhex('0x1.ffffp10') |
|
1277 |
|
2047.984375 |
|
1278 |
|
>>> float.fromhex('-0x1p-1074') |
|
1279 |
|
-5e-324 |
|
1280 |
|
[clinic start generated code]*/ |
|
1281 |
|
|
1222 |
1282 |
static PyObject * |
static PyObject * |
1223 |
|
float_fromhex(PyObject *cls, PyObject *arg) |
|
|
1283 |
|
float_fromhex(PyTypeObject *type, PyObject *string) |
|
1284 |
|
/*[clinic end generated code: output=46c0274d22b78e82 input=0407bebd354bca89]*/ |
1224 |
1285 |
{ |
{ |
1225 |
1286 |
PyObject *result; |
PyObject *result; |
1226 |
1287 |
double x; |
double x; |
|
... |
... |
float_fromhex(PyObject *cls, PyObject *arg) |
1274 |
1335 |
* exp+4*ndigits and exp-4*ndigits are within the range of a long. |
* exp+4*ndigits and exp-4*ndigits are within the range of a long. |
1275 |
1336 |
*/ |
*/ |
1276 |
1337 |
|
|
1277 |
|
s = PyUnicode_AsUTF8AndSize(arg, &length); |
|
|
1338 |
|
s = PyUnicode_AsUTF8AndSize(string, &length); |
1278 |
1339 |
if (s == NULL) |
if (s == NULL) |
1279 |
1340 |
return NULL; |
return NULL; |
1280 |
1341 |
s_end = s + length; |
s_end = s + length; |
|
... |
... |
float_fromhex(PyObject *cls, PyObject *arg) |
1438 |
1499 |
if (s != s_end) |
if (s != s_end) |
1439 |
1500 |
goto parse_error; |
goto parse_error; |
1440 |
1501 |
result = PyFloat_FromDouble(negate ? -x : x); |
result = PyFloat_FromDouble(negate ? -x : x); |
1441 |
|
if (cls != (PyObject *)&PyFloat_Type && result != NULL) { |
|
1442 |
|
Py_SETREF(result, PyObject_CallFunctionObjArgs(cls, result, NULL)); |
|
|
1502 |
|
if (type != &PyFloat_Type && result != NULL) { |
|
1503 |
|
Py_SETREF(result, PyObject_CallFunctionObjArgs((PyObject *)type, result, NULL)); |
1443 |
1504 |
} |
} |
1444 |
1505 |
return result; |
return result; |
1445 |
1506 |
|
|
|
... |
... |
float_fromhex(PyObject *cls, PyObject *arg) |
1459 |
1520 |
return NULL; |
return NULL; |
1460 |
1521 |
} |
} |
1461 |
1522 |
|
|
1462 |
|
PyDoc_STRVAR(float_fromhex_doc, |
|
1463 |
|
"float.fromhex(string) -> float\n\ |
|
1464 |
|
\n\ |
|
1465 |
|
Create a floating-point number from a hexadecimal string.\n\ |
|
1466 |
|
>>> float.fromhex('0x1.ffffp10')\n\ |
|
1467 |
|
2047.984375\n\ |
|
1468 |
|
>>> float.fromhex('-0x1p-1074')\n\ |
|
1469 |
|
-5e-324"); |
|
|
1523 |
|
/*[clinic input] |
|
1524 |
|
float.as_integer_ratio |
1470 |
1525 |
|
|
|
1526 |
|
Return integer ratio. |
|
1527 |
|
|
|
1528 |
|
Return a pair of integers, whose ratio is exactly equal to the original float |
|
1529 |
|
and with a positive denominator. |
|
1530 |
|
|
|
1531 |
|
Raise OverflowError on infinities and a ValueError on NaNs. |
|
1532 |
|
|
|
1533 |
|
>>> (10.0).as_integer_ratio() |
|
1534 |
|
(10, 1) |
|
1535 |
|
>>> (0.0).as_integer_ratio() |
|
1536 |
|
(0, 1) |
|
1537 |
|
>>> (-.25).as_integer_ratio() |
|
1538 |
|
(-1, 4) |
|
1539 |
|
[clinic start generated code]*/ |
1471 |
1540 |
|
|
1472 |
1541 |
static PyObject * |
static PyObject * |
1473 |
|
float_as_integer_ratio(PyObject *v, PyObject *unused) |
|
|
1542 |
|
float_as_integer_ratio_impl(PyObject *self) |
|
1543 |
|
/*[clinic end generated code: output=65f25f0d8d30a712 input=e21d08b4630c2e44]*/ |
1474 |
1544 |
{ |
{ |
1475 |
|
double self; |
|
|
1545 |
|
double self_double; |
1476 |
1546 |
double float_part; |
double float_part; |
1477 |
1547 |
int exponent; |
int exponent; |
1478 |
1548 |
int i; |
int i; |
|
... |
... |
float_as_integer_ratio(PyObject *v, PyObject *unused) |
1483 |
1553 |
PyObject *result_pair = NULL; |
PyObject *result_pair = NULL; |
1484 |
1554 |
PyNumberMethods *long_methods = PyLong_Type.tp_as_number; |
PyNumberMethods *long_methods = PyLong_Type.tp_as_number; |
1485 |
1555 |
|
|
1486 |
|
CONVERT_TO_DOUBLE(v, self); |
|
|
1556 |
|
CONVERT_TO_DOUBLE(self, self_double); |
1487 |
1557 |
|
|
1488 |
|
if (Py_IS_INFINITY(self)) { |
|
|
1558 |
|
if (Py_IS_INFINITY(self_double)) { |
1489 |
1559 |
PyErr_SetString(PyExc_OverflowError, |
PyErr_SetString(PyExc_OverflowError, |
1490 |
1560 |
"cannot convert Infinity to integer ratio"); |
"cannot convert Infinity to integer ratio"); |
1491 |
1561 |
return NULL; |
return NULL; |
1492 |
1562 |
} |
} |
1493 |
|
if (Py_IS_NAN(self)) { |
|
|
1563 |
|
if (Py_IS_NAN(self_double)) { |
1494 |
1564 |
PyErr_SetString(PyExc_ValueError, |
PyErr_SetString(PyExc_ValueError, |
1495 |
1565 |
"cannot convert NaN to integer ratio"); |
"cannot convert NaN to integer ratio"); |
1496 |
1566 |
return NULL; |
return NULL; |
1497 |
1567 |
} |
} |
1498 |
1568 |
|
|
1499 |
1569 |
PyFPE_START_PROTECT("as_integer_ratio", goto error); |
PyFPE_START_PROTECT("as_integer_ratio", goto error); |
1500 |
|
float_part = frexp(self, &exponent); /* self == float_part * 2**exponent exactly */ |
|
|
1570 |
|
float_part = frexp(self_double, &exponent); /* self_double == float_part * 2**exponent exactly */ |
1501 |
1571 |
PyFPE_END_PROTECT(float_part); |
PyFPE_END_PROTECT(float_part); |
1502 |
1572 |
|
|
1503 |
1573 |
for (i=0; i<300 && float_part != floor(float_part) ; i++) { |
for (i=0; i<300 && float_part != floor(float_part) ; i++) { |
|
... |
... |
error: |
1541 |
1611 |
return result_pair; |
return result_pair; |
1542 |
1612 |
} |
} |
1543 |
1613 |
|
|
1544 |
|
PyDoc_STRVAR(float_as_integer_ratio_doc, |
|
1545 |
|
"float.as_integer_ratio() -> (int, int)\n" |
|
1546 |
|
"\n" |
|
1547 |
|
"Return a pair of integers, whose ratio is exactly equal to the original\n" |
|
1548 |
|
"float and with a positive denominator.\n" |
|
1549 |
|
"Raise OverflowError on infinities and a ValueError on NaNs.\n" |
|
1550 |
|
"\n" |
|
1551 |
|
">>> (10.0).as_integer_ratio()\n" |
|
1552 |
|
"(10, 1)\n" |
|
1553 |
|
">>> (0.0).as_integer_ratio()\n" |
|
1554 |
|
"(0, 1)\n" |
|
1555 |
|
">>> (-.25).as_integer_ratio()\n" |
|
1556 |
|
"(-1, 4)"); |
|
1557 |
|
|
|
1558 |
|
|
|
1559 |
1614 |
static PyObject * |
static PyObject * |
1560 |
1615 |
float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
1561 |
1616 |
|
|
|
... |
... |
float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
1602 |
1657 |
return newobj; |
return newobj; |
1603 |
1658 |
} |
} |
1604 |
1659 |
|
|
|
1660 |
|
/*[clinic input] |
|
1661 |
|
float.__getnewargs__ |
|
1662 |
|
[clinic start generated code]*/ |
|
1663 |
|
|
1605 |
1664 |
static PyObject * |
static PyObject * |
1606 |
|
float_getnewargs(PyFloatObject *v) |
|
|
1665 |
|
float___getnewargs___impl(PyObject *self) |
|
1666 |
|
/*[clinic end generated code: output=873258c9d206b088 input=002279d1d77891e6]*/ |
1607 |
1667 |
{ |
{ |
1608 |
|
return Py_BuildValue("(d)", v->ob_fval); |
|
|
1668 |
|
return Py_BuildValue("(d)", ((PyFloatObject *)self)->ob_fval); |
1609 |
1669 |
} |
} |
1610 |
1670 |
|
|
1611 |
1671 |
/* this is for the benefit of the pack/unpack routines below */ |
/* this is for the benefit of the pack/unpack routines below */ |
|
... |
... |
typedef enum { |
1617 |
1677 |
static float_format_type double_format, float_format; |
static float_format_type double_format, float_format; |
1618 |
1678 |
static float_format_type detected_double_format, detected_float_format; |
static float_format_type detected_double_format, detected_float_format; |
1619 |
1679 |
|
|
|
1680 |
|
/*[clinic input] |
|
1681 |
|
@classmethod |
|
1682 |
|
float.__getformat__ |
|
1683 |
|
|
|
1684 |
|
typestr: str |
|
1685 |
|
Must be 'double' or 'float'. |
|
1686 |
|
/ |
|
1687 |
|
|
|
1688 |
|
You probably don't want to use this function. |
|
1689 |
|
|
|
1690 |
|
It exists mainly to be used in Python's test suite. |
|
1691 |
|
|
|
1692 |
|
This function returns whichever of 'unknown', 'IEEE, big-endian' or 'IEEE, |
|
1693 |
|
little-endian' best describes the format of floating point numbers used by the |
|
1694 |
|
C type named by typestr. |
|
1695 |
|
[clinic start generated code]*/ |
|
1696 |
|
|
1620 |
1697 |
static PyObject * |
static PyObject * |
1621 |
|
float_getformat(PyTypeObject *v, PyObject* arg) |
|
|
1698 |
|
float___getformat___impl(PyTypeObject *type, const char *typestr) |
|
1699 |
|
/*[clinic end generated code: output=2bfb987228cc9628 input=d5a52600f835ad67]*/ |
1622 |
1700 |
{ |
{ |
1623 |
|
const char *s; |
|
1624 |
1701 |
float_format_type r; |
float_format_type r; |
1625 |
1702 |
|
|
1626 |
|
if (!PyUnicode_Check(arg)) { |
|
1627 |
|
PyErr_Format(PyExc_TypeError, |
|
1628 |
|
"__getformat__() argument must be string, not %.500s", |
|
1629 |
|
Py_TYPE(arg)->tp_name); |
|
1630 |
|
return NULL; |
|
1631 |
|
} |
|
1632 |
|
s = PyUnicode_AsUTF8(arg); |
|
1633 |
|
if (s == NULL) |
|
1634 |
|
return NULL; |
|
1635 |
|
if (strcmp(s, "double") == 0) { |
|
|
1703 |
|
if (strcmp(typestr, "double") == 0) { |
1636 |
1704 |
r = double_format; |
r = double_format; |
1637 |
1705 |
} |
} |
1638 |
|
else if (strcmp(s, "float") == 0) { |
|
|
1706 |
|
else if (strcmp(typestr, "float") == 0) { |
1639 |
1707 |
r = float_format; |
r = float_format; |
1640 |
1708 |
} |
} |
1641 |
1709 |
else { |
else { |
|
... |
... |
float_getformat(PyTypeObject *v, PyObject* arg) |
1658 |
1726 |
} |
} |
1659 |
1727 |
} |
} |
1660 |
1728 |
|
|
1661 |
|
PyDoc_STRVAR(float_getformat_doc, |
|
1662 |
|
"float.__getformat__(typestr) -> string\n" |
|
1663 |
|
"\n" |
|
1664 |
|
"You probably don't want to use this function. It exists mainly to be\n" |
|
1665 |
|
"used in Python's test suite.\n" |
|
1666 |
|
"\n" |
|
1667 |
|
"typestr must be 'double' or 'float'. This function returns whichever of\n" |
|
1668 |
|
"'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the\n" |
|
1669 |
|
"format of floating point numbers used by the C type named by typestr."); |
|
|
1729 |
|
/*[clinic input] |
|
1730 |
|
@classmethod |
|
1731 |
|
float.__set_format__ |
|
1732 |
|
|
|
1733 |
|
typestr: str |
|
1734 |
|
Must be 'double' or 'float'. |
|
1735 |
|
fmt: str |
|
1736 |
|
Must be one of 'unknown', 'IEEE, big-endian' or 'IEEE, little-endian', |
|
1737 |
|
and in addition can only be one of the latter two if it appears to |
|
1738 |
|
match the underlying C reality. |
|
1739 |
|
/ |
|
1740 |
|
|
|
1741 |
|
You probably don't want to use this function. |
|
1742 |
|
|
|
1743 |
|
It exists mainly to be used in Python's test suite. |
|
1744 |
|
|
|
1745 |
|
Override the automatic determination of C-level floating point type. |
|
1746 |
|
This affects how floats are converted to and from binary strings. |
|
1747 |
|
[clinic start generated code]*/ |
1670 |
1748 |
|
|
1671 |
1749 |
static PyObject * |
static PyObject * |
1672 |
|
float_setformat(PyTypeObject *v, PyObject* args) |
|
|
1750 |
|
float___set_format___impl(PyTypeObject *type, const char *typestr, |
|
1751 |
|
const char *fmt) |
|
1752 |
|
/*[clinic end generated code: output=504460f5dc85acbd input=5306fa2b81a997e4]*/ |
1673 |
1753 |
{ |
{ |
1674 |
|
char* typestr; |
|
1675 |
|
char* format; |
|
1676 |
1754 |
float_format_type f; |
float_format_type f; |
1677 |
1755 |
float_format_type detected; |
float_format_type detected; |
1678 |
1756 |
float_format_type *p; |
float_format_type *p; |
1679 |
1757 |
|
|
1680 |
|
if (!PyArg_ParseTuple(args, "ss:__setformat__", &typestr, &format)) |
|
1681 |
|
return NULL; |
|
1682 |
|
|
|
1683 |
1758 |
if (strcmp(typestr, "double") == 0) { |
if (strcmp(typestr, "double") == 0) { |
1684 |
1759 |
p = &double_format; |
p = &double_format; |
1685 |
1760 |
detected = detected_double_format; |
detected = detected_double_format; |
|
... |
... |
float_setformat(PyTypeObject *v, PyObject* args) |
1695 |
1770 |
return NULL; |
return NULL; |
1696 |
1771 |
} |
} |
1697 |
1772 |
|
|
1698 |
|
if (strcmp(format, "unknown") == 0) { |
|
|
1773 |
|
if (strcmp(fmt, "unknown") == 0) { |
1699 |
1774 |
f = unknown_format; |
f = unknown_format; |
1700 |
1775 |
} |
} |
1701 |
|
else if (strcmp(format, "IEEE, little-endian") == 0) { |
|
|
1776 |
|
else if (strcmp(fmt, "IEEE, little-endian") == 0) { |
1702 |
1777 |
f = ieee_little_endian_format; |
f = ieee_little_endian_format; |
1703 |
1778 |
} |
} |
1704 |
|
else if (strcmp(format, "IEEE, big-endian") == 0) { |
|
|
1779 |
|
else if (strcmp(fmt, "IEEE, big-endian") == 0) { |
1705 |
1780 |
f = ieee_big_endian_format; |
f = ieee_big_endian_format; |
1706 |
1781 |
} |
} |
1707 |
1782 |
else { |
else { |
|
... |
... |
float_setformat(PyTypeObject *v, PyObject* args) |
1724 |
1799 |
Py_RETURN_NONE; |
Py_RETURN_NONE; |
1725 |
1800 |
} |
} |
1726 |
1801 |
|
|
1727 |
|
PyDoc_STRVAR(float_setformat_doc, |
|
1728 |
|
"float.__setformat__(typestr, fmt) -> None\n" |
|
1729 |
|
"\n" |
|
1730 |
|
"You probably don't want to use this function. It exists mainly to be\n" |
|
1731 |
|
"used in Python's test suite.\n" |
|
1732 |
|
"\n" |
|
1733 |
|
"typestr must be 'double' or 'float'. fmt must be one of 'unknown',\n" |
|
1734 |
|
"'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be\n" |
|
1735 |
|
"one of the latter two if it appears to match the underlying C reality.\n" |
|
1736 |
|
"\n" |
|
1737 |
|
"Override the automatic determination of C-level floating point type.\n" |
|
1738 |
|
"This affects how floats are converted to and from binary strings."); |
|
|
1802 |
|
static PyObject * |
|
1803 |
|
float_getreal(PyObject *v, void *closure) |
|
1804 |
|
{ |
|
1805 |
|
return float_float(v); |
|
1806 |
|
} |
1739 |
1807 |
|
|
1740 |
1808 |
static PyObject * |
static PyObject * |
1741 |
|
float_getzero(PyObject *v, void *closure) |
|
|
1809 |
|
float_getimag(PyObject *v, void *closure) |
1742 |
1810 |
{ |
{ |
1743 |
1811 |
return PyFloat_FromDouble(0.0); |
return PyFloat_FromDouble(0.0); |
1744 |
1812 |
} |
} |
1745 |
1813 |
|
|
|
1814 |
|
/*[clinic input] |
|
1815 |
|
float.__format__ |
|
1816 |
|
|
|
1817 |
|
format_spec: unicode |
|
1818 |
|
/ |
|
1819 |
|
|
|
1820 |
|
Formats the float according to format_spec. |
|
1821 |
|
[clinic start generated code]*/ |
|
1822 |
|
|
1746 |
1823 |
static PyObject * |
static PyObject * |
1747 |
|
float__format__(PyObject *self, PyObject *args) |
|
|
1824 |
|
float___format___impl(PyObject *self, PyObject *format_spec) |
|
1825 |
|
/*[clinic end generated code: output=b260e52a47eade56 input=2ece1052211fd0e6]*/ |
1748 |
1826 |
{ |
{ |
1749 |
|
PyObject *format_spec; |
|
1750 |
1827 |
_PyUnicodeWriter writer; |
_PyUnicodeWriter writer; |
1751 |
1828 |
int ret; |
int ret; |
1752 |
1829 |
|
|
1753 |
|
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) |
|
1754 |
|
return NULL; |
|
1755 |
|
|
|
1756 |
1830 |
_PyUnicodeWriter_Init(&writer); |
_PyUnicodeWriter_Init(&writer); |
1757 |
1831 |
ret = _PyFloat_FormatAdvancedWriter( |
ret = _PyFloat_FormatAdvancedWriter( |
1758 |
1832 |
&writer, |
&writer, |
|
... |
... |
float__format__(PyObject *self, PyObject *args) |
1765 |
1839 |
return _PyUnicodeWriter_Finish(&writer); |
return _PyUnicodeWriter_Finish(&writer); |
1766 |
1840 |
} |
} |
1767 |
1841 |
|
|
1768 |
|
PyDoc_STRVAR(float__format__doc, |
|
1769 |
|
"float.__format__(format_spec) -> string\n" |
|
1770 |
|
"\n" |
|
1771 |
|
"Formats the float according to format_spec."); |
|
1772 |
|
|
|
1773 |
|
|
|
1774 |
1842 |
static PyMethodDef float_methods[] = { |
static PyMethodDef float_methods[] = { |
1775 |
|
{"conjugate", (PyCFunction)float_float, METH_NOARGS, |
|
1776 |
|
"Return self, the complex conjugate of any float."}, |
|
1777 |
|
{"__trunc__", (PyCFunction)float_trunc, METH_NOARGS, |
|
1778 |
|
"Return the Integral closest to x between 0 and x."}, |
|
1779 |
|
{"__round__", (PyCFunction)float_round, METH_VARARGS, |
|
1780 |
|
"Return the Integral closest to x, rounding half toward even.\n" |
|
1781 |
|
"When an argument is passed, work like built-in round(x, ndigits)."}, |
|
1782 |
|
{"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS, |
|
1783 |
|
float_as_integer_ratio_doc}, |
|
1784 |
|
{"fromhex", (PyCFunction)float_fromhex, |
|
1785 |
|
METH_O|METH_CLASS, float_fromhex_doc}, |
|
1786 |
|
{"hex", (PyCFunction)float_hex, |
|
1787 |
|
METH_NOARGS, float_hex_doc}, |
|
1788 |
|
{"is_integer", (PyCFunction)float_is_integer, METH_NOARGS, |
|
1789 |
|
"Return True if the float is an integer."}, |
|
|
1843 |
|
FLOAT_CONJUGATE_METHODDEF |
|
1844 |
|
FLOAT___TRUNC___METHODDEF |
|
1845 |
|
FLOAT___ROUND___METHODDEF |
|
1846 |
|
FLOAT_AS_INTEGER_RATIO_METHODDEF |
|
1847 |
|
FLOAT_FROMHEX_METHODDEF |
|
1848 |
|
FLOAT_HEX_METHODDEF |
|
1849 |
|
FLOAT_IS_INTEGER_METHODDEF |
1790 |
1850 |
#if 0 |
#if 0 |
1791 |
1851 |
{"is_inf", (PyCFunction)float_is_inf, METH_NOARGS, |
{"is_inf", (PyCFunction)float_is_inf, METH_NOARGS, |
1792 |
1852 |
"Return True if the float is positive or negative infinite."}, |
"Return True if the float is positive or negative infinite."}, |
|
... |
... |
static PyMethodDef float_methods[] = { |
1795 |
1855 |
{"is_nan", (PyCFunction)float_is_nan, METH_NOARGS, |
{"is_nan", (PyCFunction)float_is_nan, METH_NOARGS, |
1796 |
1856 |
"Return True if the float is not a number (NaN)."}, |
"Return True if the float is not a number (NaN)."}, |
1797 |
1857 |
#endif |
#endif |
1798 |
|
{"__getnewargs__", (PyCFunction)float_getnewargs, METH_NOARGS}, |
|
1799 |
|
{"__getformat__", (PyCFunction)float_getformat, |
|
1800 |
|
METH_O|METH_CLASS, float_getformat_doc}, |
|
1801 |
|
{"__setformat__", (PyCFunction)float_setformat, |
|
1802 |
|
METH_VARARGS|METH_CLASS, float_setformat_doc}, |
|
1803 |
|
{"__format__", (PyCFunction)float__format__, |
|
1804 |
|
METH_VARARGS, float__format__doc}, |
|
|
1858 |
|
FLOAT___GETNEWARGS___METHODDEF |
|
1859 |
|
FLOAT___GETFORMAT___METHODDEF |
|
1860 |
|
FLOAT___SET_FORMAT___METHODDEF |
|
1861 |
|
FLOAT___FORMAT___METHODDEF |
1805 |
1862 |
{NULL, NULL} /* sentinel */ |
{NULL, NULL} /* sentinel */ |
1806 |
1863 |
}; |
}; |
1807 |
1864 |
|
|
1808 |
1865 |
static PyGetSetDef float_getset[] = { |
static PyGetSetDef float_getset[] = { |
1809 |
1866 |
{"real", |
{"real", |
1810 |
|
(getter)float_float, (setter)NULL, |
|
|
1867 |
|
float_getreal, (setter)NULL, |
1811 |
1868 |
"the real part of a complex number", |
"the real part of a complex number", |
1812 |
1869 |
NULL}, |
NULL}, |
1813 |
1870 |
{"imag", |
{"imag", |
1814 |
|
(getter)float_getzero, (setter)NULL, |
|
|
1871 |
|
float_getimag, (setter)NULL, |
1815 |
1872 |
"the imaginary part of a complex number", |
"the imaginary part of a complex number", |
1816 |
1873 |
NULL}, |
NULL}, |
1817 |
1874 |
{NULL} /* Sentinel */ |
{NULL} /* Sentinel */ |
|
... |
... |
Convert a string or number to a floating point number, if possible."); |
1824 |
1881 |
|
|
1825 |
1882 |
|
|
1826 |
1883 |
static PyNumberMethods float_as_number = { |
static PyNumberMethods float_as_number = { |
1827 |
|
float_add, /*nb_add*/ |
|
1828 |
|
float_sub, /*nb_subtract*/ |
|
1829 |
|
float_mul, /*nb_multiply*/ |
|
1830 |
|
float_rem, /*nb_remainder*/ |
|
1831 |
|
float_divmod, /*nb_divmod*/ |
|
1832 |
|
float_pow, /*nb_power*/ |
|
1833 |
|
(unaryfunc)float_neg, /*nb_negative*/ |
|
1834 |
|
(unaryfunc)float_float, /*nb_positive*/ |
|
1835 |
|
(unaryfunc)float_abs, /*nb_absolute*/ |
|
1836 |
|
(inquiry)float_bool, /*nb_bool*/ |
|
1837 |
|
0, /*nb_invert*/ |
|
1838 |
|
0, /*nb_lshift*/ |
|
1839 |
|
0, /*nb_rshift*/ |
|
1840 |
|
0, /*nb_and*/ |
|
1841 |
|
0, /*nb_xor*/ |
|
1842 |
|
0, /*nb_or*/ |
|
1843 |
|
float_trunc, /*nb_int*/ |
|
1844 |
|
0, /*nb_reserved*/ |
|
1845 |
|
float_float, /*nb_float*/ |
|
|
1884 |
|
float_add, /* nb_add */ |
|
1885 |
|
float_sub, /* nb_subtract */ |
|
1886 |
|
float_mul, /* nb_multiply */ |
|
1887 |
|
float_rem, /* nb_remainder */ |
|
1888 |
|
float_divmod, /* nb_divmod */ |
|
1889 |
|
float_pow, /* nb_power */ |
|
1890 |
|
(unaryfunc)float_neg, /* nb_negative */ |
|
1891 |
|
float_float, /* nb_positive */ |
|
1892 |
|
(unaryfunc)float_abs, /* nb_absolute */ |
|
1893 |
|
(inquiry)float_bool, /* nb_bool */ |
|
1894 |
|
0, /* nb_invert */ |
|
1895 |
|
0, /* nb_lshift */ |
|
1896 |
|
0, /* nb_rshift */ |
|
1897 |
|
0, /* nb_and */ |
|
1898 |
|
0, /* nb_xor */ |
|
1899 |
|
0, /* nb_or */ |
|
1900 |
|
float___trunc___impl, /* nb_int */ |
|
1901 |
|
0, /* nb_reserved */ |
|
1902 |
|
float_float, /* nb_float */ |
1846 |
1903 |
0, /* nb_inplace_add */ |
0, /* nb_inplace_add */ |
1847 |
1904 |
0, /* nb_inplace_subtract */ |
0, /* nb_inplace_subtract */ |
1848 |
1905 |
0, /* nb_inplace_multiply */ |
0, /* nb_inplace_multiply */ |
|
... |
... |
static PyNumberMethods float_as_number = { |
1853 |
1910 |
0, /* nb_inplace_and */ |
0, /* nb_inplace_and */ |
1854 |
1911 |
0, /* nb_inplace_xor */ |
0, /* nb_inplace_xor */ |
1855 |
1912 |
0, /* nb_inplace_or */ |
0, /* nb_inplace_or */ |
1856 |
|
float_floor_div, /* nb_floor_divide */ |
|
|
1913 |
|
float_floor_div, /* nb_floor_divide */ |
1857 |
1914 |
float_div, /* nb_true_divide */ |
float_div, /* nb_true_divide */ |
1858 |
1915 |
0, /* nb_inplace_floor_divide */ |
0, /* nb_inplace_floor_divide */ |
1859 |
1916 |
0, /* nb_inplace_true_divide */ |
0, /* nb_inplace_true_divide */ |
|
... |
... |
PyTypeObject PyFloat_Type = { |
1879 |
1936 |
PyObject_GenericGetAttr, /* tp_getattro */ |
PyObject_GenericGetAttr, /* tp_getattro */ |
1880 |
1937 |
0, /* tp_setattro */ |
0, /* tp_setattro */ |
1881 |
1938 |
0, /* tp_as_buffer */ |
0, /* tp_as_buffer */ |
1882 |
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
|
1939 |
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
1883 |
1940 |
float_doc, /* tp_doc */ |
float_doc, /* tp_doc */ |
1884 |
1941 |
0, /* tp_traverse */ |
0, /* tp_traverse */ |
1885 |
1942 |
0, /* tp_clear */ |
0, /* tp_clear */ |