Mercurial > cpython-lru_cache-weakref
annotate Objects/floatobject.c @ 892:11ea669c231e legacy-trunk
Documented new contents of lib5.tex
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 03 Jun 1992 17:56:44 +0000 |
| parents | 0cd197947d81 |
| children | 03de67080c95 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
795
0cd197947d81
Copyright for 1992 added
Guido van Rossum <guido@python.org>
parents:
745
diff
changeset
|
2 Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
| 145 | 3 Netherlands. |
| 4 | |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Float object implementation */ |
| 26 | |
| 27 | 27 /* XXX There should be overflow checks here, but it's hard to check |
| 28 for any kind of float exception without losing portability. */ | |
| 29 | |
| 86 | 30 #include "allobjects.h" |
| 6 | 31 |
| 91 | 32 #include <errno.h> |
| 33 #ifndef errno | |
| 34 extern int errno; | |
| 35 #endif | |
| 36 | |
| 86 | 37 #include <ctype.h> |
| 38 #include <math.h> | |
| 6 | 39 |
|
496
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
40 #ifdef HUGE_VAL |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
41 #define CHECK(x) if (errno != 0) ; \ |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
42 else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; \ |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
43 else errno = ERANGE |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
44 #else |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
45 #define CHECK(x) /* Don't know how to check */ |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
46 #endif |
|
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
47 |
|
60
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
48 #ifndef THINK_C |
|
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
49 extern double fmod PROTO((double, double)); |
|
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
50 extern double pow PROTO((double, double)); |
|
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
51 #endif |
|
4f593b38d061
Moved prototyes for fmod and pow, and don't use them for THINK C.
Guido van Rossum <guido@python.org>
parents:
46
diff
changeset
|
52 |
| 6 | 53 object * |
| 54 newfloatobject(fval) | |
| 55 double fval; | |
| 56 { | |
| 57 /* For efficiency, this code is copied from newobject() */ | |
| 58 register floatobject *op = (floatobject *) malloc(sizeof(floatobject)); | |
| 27 | 59 if (op == NULL) |
| 60 return err_nomem(); | |
| 61 NEWREF(op); | |
| 62 op->ob_type = &Floattype; | |
| 63 op->ob_fval = fval; | |
| 6 | 64 return (object *) op; |
| 65 } | |
| 66 | |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
67 void |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
68 float_dealloc(op) |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
69 object *op; |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
70 { |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
71 DEL(op); |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
72 } |
|
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
73 |
| 6 | 74 double |
| 75 getfloatvalue(op) | |
| 76 object *op; | |
| 77 { | |
| 78 if (!is_floatobject(op)) { | |
| 27 | 79 err_badarg(); |
| 6 | 80 return -1; |
| 81 } | |
| 82 else | |
| 83 return ((floatobject *)op) -> ob_fval; | |
| 84 } | |
| 85 | |
| 86 /* Methods */ | |
| 87 | |
|
268
0fe2471166f0
Export float_buf_repr() interface, for marshalling of floats.
Guido van Rossum <guido@python.org>
parents:
249
diff
changeset
|
88 void |
| 6 | 89 float_buf_repr(buf, v) |
| 90 char *buf; | |
| 91 floatobject *v; | |
| 92 { | |
| 93 register char *cp; | |
| 94 /* Subroutine for float_repr and float_print. | |
| 95 We want float numbers to be recognizable as such, | |
| 96 i.e., they should contain a decimal point or an exponent. | |
| 97 However, %g may print the number as an integer; | |
| 98 in such cases, we append ".0" to the string. */ | |
| 99 sprintf(buf, "%.12g", v->ob_fval); | |
| 100 cp = buf; | |
| 101 if (*cp == '-') | |
| 102 cp++; | |
| 103 for (; *cp != '\0'; cp++) { | |
| 104 /* Any non-digit means it's not an integer; | |
| 105 this takes care of NAN and INF as well. */ | |
| 106 if (!isdigit(*cp)) | |
| 107 break; | |
| 108 } | |
| 109 if (*cp == '\0') { | |
| 110 *cp++ = '.'; | |
| 111 *cp++ = '0'; | |
| 112 *cp++ = '\0'; | |
| 113 } | |
| 114 } | |
| 115 | |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
116 /* ARGSUSED */ |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
268
diff
changeset
|
117 static int |
| 6 | 118 float_print(v, fp, flags) |
| 119 floatobject *v; | |
| 120 FILE *fp; | |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
121 int flags; /* Not used but required by interface */ |
| 6 | 122 { |
| 123 char buf[100]; | |
| 124 float_buf_repr(buf, v); | |
| 125 fputs(buf, fp); | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
268
diff
changeset
|
126 return 0; |
| 6 | 127 } |
| 128 | |
| 129 static object * | |
| 130 float_repr(v) | |
| 131 floatobject *v; | |
| 132 { | |
| 133 char buf[100]; | |
| 134 float_buf_repr(buf, v); | |
| 135 return newstringobject(buf); | |
| 136 } | |
| 137 | |
| 138 static int | |
| 139 float_compare(v, w) | |
| 140 floatobject *v, *w; | |
| 141 { | |
| 142 double i = v->ob_fval; | |
| 143 double j = w->ob_fval; | |
| 144 return (i < j) ? -1 : (i > j) ? 1 : 0; | |
| 145 } | |
| 146 | |
| 147 static object * | |
| 148 float_add(v, w) | |
| 149 floatobject *v; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
150 floatobject *w; |
| 6 | 151 { |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
152 return newfloatobject(v->ob_fval + w->ob_fval); |
| 6 | 153 } |
| 154 | |
| 155 static object * | |
| 156 float_sub(v, w) | |
| 157 floatobject *v; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
158 floatobject *w; |
| 6 | 159 { |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
160 return newfloatobject(v->ob_fval - w->ob_fval); |
| 6 | 161 } |
| 162 | |
| 163 static object * | |
| 164 float_mul(v, w) | |
| 165 floatobject *v; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
166 floatobject *w; |
| 6 | 167 { |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
168 return newfloatobject(v->ob_fval * w->ob_fval); |
| 6 | 169 } |
| 170 | |
| 171 static object * | |
| 172 float_div(v, w) | |
| 173 floatobject *v; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
174 floatobject *w; |
| 6 | 175 { |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
176 if (w->ob_fval == 0) { |
|
470
a1025cbba30d
Formulate better error strings.
Guido van Rossum <guido@python.org>
parents:
405
diff
changeset
|
177 err_setstr(ZeroDivisionError, "float division"); |
| 6 | 178 return NULL; |
| 179 } | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
180 return newfloatobject(v->ob_fval / w->ob_fval); |
| 6 | 181 } |
| 182 | |
| 183 static object * | |
| 184 float_rem(v, w) | |
| 185 floatobject *v; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
186 floatobject *w; |
| 6 | 187 { |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
188 double vx, wx; |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
189 double /* div, */ mod; |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
190 wx = w->ob_fval; |
|
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
191 if (wx == 0.0) { |
|
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
192 err_setstr(ZeroDivisionError, "float modulo"); |
| 6 | 193 return NULL; |
| 194 } | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
195 vx = v->ob_fval; |
|
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
196 mod = fmod(vx, wx); |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
197 /* div = (vx - mod) / wx; */ |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
198 if (wx*mod < 0) { |
|
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
199 mod += wx; |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
200 /* div -= 1.0; */ |
| 6 | 201 } |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
202 return newfloatobject(mod); |
| 6 | 203 } |
| 204 | |
| 205 static object * | |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
206 float_divmod(v, w) |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
207 floatobject *v; |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
208 floatobject *w; |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
209 { |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
210 double vx, wx; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
211 double div, mod; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
212 object *t; |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
213 wx = w->ob_fval; |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
214 if (wx == 0.0) { |
|
470
a1025cbba30d
Formulate better error strings.
Guido van Rossum <guido@python.org>
parents:
405
diff
changeset
|
215 err_setstr(ZeroDivisionError, "float divmod()"); |
|
391
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
216 return NULL; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
217 } |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
218 vx = v->ob_fval; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
219 mod = fmod(vx, wx); |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
220 div = (vx - mod) / wx; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
221 if (wx*mod < 0) { |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
222 mod += wx; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
223 div -= 1.0; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
224 } |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
225 t = newtupleobject(2); |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
226 if (t != NULL) { |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
227 settupleitem(t, 0, newfloatobject(div)); |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
228 settupleitem(t, 1, newfloatobject(mod)); |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
229 if (err_occurred()) { |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
230 DECREF(t); |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
231 t = NULL; |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
232 } |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
233 } |
|
caf8466dcc9c
Finally implemented divmod().
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
234 return t; |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
235 } |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
236 |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
237 static object * |
| 6 | 238 float_pow(v, w) |
| 239 floatobject *v; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
240 floatobject *w; |
| 6 | 241 { |
| 242 double iv, iw, ix; | |
| 243 iv = v->ob_fval; | |
|
632
0c1938f2e0c0
Get rid of redundant type checks.
Guido van Rossum <guido@python.org>
parents:
496
diff
changeset
|
244 iw = w->ob_fval; |
|
249
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
245 /* Sort out special cases here instead of relying on pow() */ |
| 27 | 246 if (iw == 0.0) |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
247 return newfloatobject(1.0); /* x**0 is 1, even 0**0 */ |
|
249
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
248 if (iv == 0.0) { |
|
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
249 if (iw < 0.0) { |
|
470
a1025cbba30d
Formulate better error strings.
Guido van Rossum <guido@python.org>
parents:
405
diff
changeset
|
250 err_setstr(ValueError, "0.0 to the negative power"); |
|
249
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
251 return NULL; |
|
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
252 } |
|
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
253 return newfloatobject(0.0); |
|
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
254 } |
|
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
255 if (iv < 0.0) { |
|
470
a1025cbba30d
Formulate better error strings.
Guido van Rossum <guido@python.org>
parents:
405
diff
changeset
|
256 err_setstr(ValueError, "negative float to float power"); |
|
249
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
257 return NULL; |
|
bab1f5494b8e
Fix special cases in pow()
Guido van Rossum <guido@python.org>
parents:
239
diff
changeset
|
258 } |
| 6 | 259 errno = 0; |
| 260 ix = pow(iv, iw); | |
|
496
0ac392b7f76e
Explicitly check for weird values after calling pow().
Guido van Rossum <guido@python.org>
parents:
470
diff
changeset
|
261 CHECK(ix); |
| 27 | 262 if (errno != 0) { |
| 263 /* XXX could it be another type of error? */ | |
| 264 err_errno(OverflowError); | |
| 6 | 265 return NULL; |
| 27 | 266 } |
| 267 return newfloatobject(ix); | |
| 6 | 268 } |
| 269 | |
| 270 static object * | |
| 271 float_neg(v) | |
| 272 floatobject *v; | |
| 273 { | |
| 274 return newfloatobject(-v->ob_fval); | |
| 275 } | |
| 276 | |
| 277 static object * | |
| 278 float_pos(v) | |
| 279 floatobject *v; | |
| 280 { | |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
281 INCREF(v); |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
282 return (object *)v; |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
283 } |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
284 |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
285 static object * |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
286 float_abs(v) |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
287 floatobject *v; |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
288 { |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
289 if (v->ob_fval < 0) |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
290 return float_neg(v); |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
291 else |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
292 return float_pos(v); |
| 6 | 293 } |
| 294 | |
| 239 | 295 static int |
| 296 float_nonzero(v) | |
| 297 floatobject *v; | |
| 298 { | |
| 299 return v->ob_fval != 0.0; | |
| 300 } | |
| 301 | |
| 6 | 302 static number_methods float_as_number = { |
|
227
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
303 float_add, /*nb_add*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
304 float_sub, /*nb_subtract*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
305 float_mul, /*nb_multiply*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
306 float_div, /*nb_divide*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
307 float_rem, /*nb_remainder*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
308 float_divmod, /*nb_divmod*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
309 float_pow, /*nb_power*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
310 float_neg, /*nb_negative*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
311 float_pos, /*nb_positive*/ |
|
7ec6058b539b
Added (dummy) divmod and (functional) abs.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
312 float_abs, /*nb_absolute*/ |
| 239 | 313 float_nonzero, /*nb_nonzero*/ |
|
405
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
314 0, /*nb_invert*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
315 0, /*nb_lshift*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
316 0, /*nb_rshift*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
317 0, /*nb_and*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
318 0, /*nb_xor*/ |
|
d3d328680328
Added NULL function pointers for shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
391
diff
changeset
|
319 0, /*nb_or*/ |
| 6 | 320 }; |
| 321 | |
| 322 typeobject Floattype = { | |
| 323 OB_HEAD_INIT(&Typetype) | |
| 324 0, | |
| 325 "float", | |
| 326 sizeof(floatobject), | |
| 327 0, | |
|
745
c7b23cc8cded
answer lint's complaints
Guido van Rossum <guido@python.org>
parents:
632
diff
changeset
|
328 float_dealloc, /*tp_dealloc*/ |
| 6 | 329 float_print, /*tp_print*/ |
| 330 0, /*tp_getattr*/ | |
| 331 0, /*tp_setattr*/ | |
| 332 float_compare, /*tp_compare*/ | |
| 333 float_repr, /*tp_repr*/ | |
| 334 &float_as_number, /*tp_as_number*/ | |
| 335 0, /*tp_as_sequence*/ | |
| 336 0, /*tp_as_mapping*/ | |
| 337 }; |
