You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tnp.around (also tnp.round and round() on a tnp ndarray) returns wrong values for float64 and integer inputs when decimals < 0, and loses precision when decimals >= 11.
Cause (np_array_ops.py#L957-L968): factor = math.pow(10, decimals) is a Python float, and math_ops.cast(factor, float64) first converts it to a float32 tensor and then casts. So 0.1 turns into 0.10000000149011612. For 25, 25 * factor = 2.5000000037, which rounds to 3, and 3 / factor = 29.99999955. Integer inputs are then cast back with truncation, which gives 29. With 5 the result is 9 where NumPy returns 0.
Building the factor directly in the target dtype, e.g. constant_op.constant(factor, dtype), should fix it. Integer inputs with decimals >= 0 could also skip the float round trip (around(2**53 + 1) currently returns 2**53).
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.
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.
Fix several NumPy mismatches in tf.experimental.numpy
google-ml-butler commentedon Oct 23, 2026
Are you satisfied with the resolution of your issue?
Yes
No