ray-project / ray-legacy

An experimental distributed execution engine
BSD 3-Clause "New" or "Revised" License
21 stars 18 forks source link

Putting and getting a float does not preserve the exact value #433

Closed robertnishihara closed 8 years ago

robertnishihara commented 8 years ago
import ray
ray.init(start_ray_local=True, num_workers=0)
x = 0.9
ray.get(ray.put(x))  # prints 0.8999999761581421
robertnishihara commented 8 years ago

The problem is not in the Python C extensions. For example, defining a simple function

static PyObject* convert_float(PyObject* self, PyObject* args) {
  PyObject* obj;
  if (!PyArg_ParseTuple(args, "O", &obj)) {
    return NULL;
  }
  double d = PyFloat_AsDouble(obj);
  return PyFloat_FromDouble(d);
}

And calling convert_float preserves the value.

robertnishihara commented 8 years ago

Note the following.

import numpy as np
float(np.float32(0.9))  # prints 0.8999999761581421
robertnishihara commented 8 years ago

This is addressed by #435.