Repository navigation
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
binary
TensorFlow version
tf-nightly 2.23.0-dev20261014 (git v1.12.1-146947-gfcb676979cd)
Custom code
Yes
OS platform and distribution
macOS 15.7.2 (arm64)
Mobile device
No response
Python version
3.11.7
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
In eager mode, Python scalars converted to a tensor with an explicit dtype go through TFE_TensorHandleCache. Its key equality (PyObjectPtr::operator==) uses Python ==, and 0.0 == -0.0 is True with equal hashes. So whichever signed zero gets converted first is returned for both later on.
The result is silently wrong signed zeros. After x * 0.0 has run once, x * -0.0 gives +0.0, and 1 / (x * -0.0) gives +inf where it should be -inf. The reverse order is affected too: once tf.constant(-0.0, dtype=...) has been cached, tf.constant(0.0, dtype=...) comes back as -0.0. Anything that depends on the sign of zero is affected, including atan2, copysign-style logic, 1/x and signbit, and results depend on what code happened to run earlier in the process.
ConvertToEagerTensor already skips the cache for non-finite floats. It probably needs to skip (or key on the sign bit for) floats equal to zero, and the same goes for complex values with a zero real or imaginary part.
Expected: x * -0.0 == [-0., -0.] and 1 / (x * -0.0) == [-inf, -inf] regardless of earlier conversions; 1.0 / tf.constant(0.0, tf.float64) == inf.
Standalone code to reproduce the issue
import tensorflow as tf
x = tf.constant([1.0, 2.0])
print(x * 0.0) # [0. 0.]
print(x * -0.0) # expected [-0. -0.]
print(1.0 / (x * -0.0)) # expected [-inf -inf]
# The reverse order is also affected: once -0.0 is cached, 0.0 comes back negative.
a = tf.constant(-0.0, dtype=tf.float64)
b = tf.constant(0.0, dtype=tf.float64)
print(1.0 / b) # expected infRelevant log output
tf.Tensor([0. 0.], shape=(2,), dtype=float32)
tf.Tensor([0. 0.], shape=(2,), dtype=float32)
tf.Tensor([inf inf], shape=(2,), dtype=float32)
tf.Tensor(-inf, shape=(), dtype=float64)
Activity
Kayyuri commentedon Oct 19, 2026
Hi @bodapatisaikrishna,
Thanks for reporting this issue and submitting a fix for TensorFlow. Once the PR is merged, the issue will be resolved. We appreciate your contribution.
google-ml-butler commentedon Oct 23, 2026
Are you satisfied with the resolution of your issue?
Yes
No
Keep the sign of zero in the eager scalar tensor cache