mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
* Changed all copyright messages to include 1993.
* Stubs for faster implementation of local variables (not yet finished) * Added function name to code object. Print it for code and function objects. THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version number has changed accordingly) * Print address of self for built-in methods * New internal functions getattro and setattro (getattr/setattr with string object arg) * Replaced "dictobject" with more powerful "mappingobject" * New per-type functio tp_hash to implement arbitrary object hashing, and hashobject() to interface to it * Added built-in functions hash(v) and hasattr(v, 'name') * classobject: made some functions static that accidentally weren't; added __hash__ special instance method to implement hash() * Added proper comparison for built-in methods and functions
This commit is contained in:
parent
4b1302bd1d
commit
9bfef44d97
97 changed files with 559 additions and 246 deletions
|
@ -145,6 +145,38 @@ float_compare(v, w)
|
|||
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
||||
}
|
||||
|
||||
static long
|
||||
float_hash(v)
|
||||
floatobject *v;
|
||||
{
|
||||
double intpart, fractpart;
|
||||
int expo;
|
||||
long x;
|
||||
/* This is designed so that Python numbers with the same
|
||||
value hash to the same value, otherwise comparisons
|
||||
of mapping keys will turn out weird */
|
||||
fractpart = modf(v->ob_fval, &intpart);
|
||||
if (fractpart == 0.0) {
|
||||
if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
|
||||
/* Convert to long int and use its hash... */
|
||||
object *w = dnewlongobject(v->ob_fval);
|
||||
if (w == NULL)
|
||||
return -1;
|
||||
x = hashobject(w);
|
||||
DECREF(w);
|
||||
return x;
|
||||
}
|
||||
x = (long)intpart;
|
||||
}
|
||||
else {
|
||||
fractpart = frexp(fractpart, &expo);
|
||||
x = (long) (intpart + fractpart) ^ expo; /* Rather arbitrary */
|
||||
}
|
||||
if (x == -1)
|
||||
x = -2;
|
||||
return x;
|
||||
}
|
||||
|
||||
static object *
|
||||
float_add(v, w)
|
||||
floatobject *v;
|
||||
|
@ -378,4 +410,5 @@ typeobject Floattype = {
|
|||
&float_as_number, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
float_hash, /*tp_hash */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue