mirror of
https://github.com/python/cpython.git
synced 2025-08-28 12:45:07 +00:00
* Include/classobject.h, Objects/classobject.c, Python/ceval.c:
entirely redone operator overloading. The rules for class instances are now much more relaxed than for other built-in types (whose coerce must still return two objects of the same type) * Objects/floatobject.c: add overflow check when converting float to int and implement truncation towards zero using ceil/float * Objects/longobject.c: change ValueError to OverflowError when converting to int * Objects/rangeobject.c: modernized * Objects/stringobject.c: use HAVE_LIMITS instead of __STDC__ * Objects/xxobject.c: changed to use new style (not finished?)
This commit is contained in:
parent
2929527aed
commit
03093a248d
6 changed files with 220 additions and 205 deletions
|
@ -47,6 +47,18 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define CHECK(x) /* Don't know how to check */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifndef LONG_MAX
|
||||
#define LONG_MAX 0X7FFFFFFFL
|
||||
#endif
|
||||
|
||||
#ifndef LONG_MIN
|
||||
#define LONG_MIN (-LONG_MAX-1)
|
||||
#endif
|
||||
|
||||
#ifndef macintosh
|
||||
extern double fmod PROTO((double, double));
|
||||
extern double pow PROTO((double, double));
|
||||
|
@ -397,8 +409,11 @@ float_int(v)
|
|||
object *v;
|
||||
{
|
||||
double x = getfloatvalue(v);
|
||||
/* XXX should check for overflow */
|
||||
/* XXX should define how we round */
|
||||
if (x < 0 ? (x = ceil(x)) < (double)LONG_MIN
|
||||
: (x = floor(x)) > (double)LONG_MAX) {
|
||||
err_setstr(OverflowError, "float to large to convert");
|
||||
return NULL;
|
||||
}
|
||||
return newintobject((long)x);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue