diff options
author | Damien George <damien.p.george@gmail.com> | 2017-04-04 11:57:21 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-04-04 11:57:21 +1000 |
commit | 19f2e47d59b539f94a49137c379c88f0aed53cf1 (patch) | |
tree | 6a98daea2ea1ee8006cfe0dc051c821664b8b76c /py/obj.h | |
parent | bb296482c385d51f1eb8041e18beb5aa9668637c (diff) |
py: Add very simple but correct hashing for float and complex numbers.
Hashing of float and complex numbers that are exact (real) integers should
return the same integer hash value as hashing the corresponding integer
value. Eg hash(1), hash(1.0) and hash(1+0j) should all be the same (this
is how Python is specified: if x==y then hash(x)==hash(y)).
This patch implements the simplest way of doing float/complex hashing by
just converting the value to int and returning that value.
Diffstat (limited to 'py/obj.h')
-rw-r--r-- | py/obj.h | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -718,6 +718,7 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t s #if MICROPY_PY_BUILTINS_FLOAT // float +static inline mp_int_t mp_float_hash(mp_float_t val) { return (mp_int_t)val; } mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported // complex |