tensorflow / tensorflow/tensorflow
tf.math.erf returns NaN for very large finite float64 inputs instead of saturating to +/-1
@Kayyuri is already working on this.
Since Aug 17, 2026.
- Dominant language
- C++
- Stars
- 200k
- Forks
- 76.9k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 433
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
source
TensorFlow version
tf 2.21.0
Custom code
Yes
OS platform and distribution
Linux Ubuntu 22.04
Mobile device
No response
Python version
Python 3.11
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
N/A
GPU model and memory
N/A
Current behavior?
tf.math.erf returns NaN for very large finite float64 inputs.
For large positive inputs such as 1e200 and 1e300, erf(x) should saturate to 1.0. For large negative inputs such as -1e200 and -1e300, erf(x) should saturate to -1.0. However, TensorFlow returns NaN for all of these finite inputs.
The same inputs match the expected values in the high-precision mpmath reference, and peer libraries such as jax.scipy.special.erf, scipy.special.erf, torch.erf, and torch.special.erf compute the expected saturated values.
Expected behavior?
tf.math.erf should return values close to 1.0 for very large positive finite float64 inputs and values close to -1.0 for very large negative finite float64 inputs, instead of returning NaN.
Standalone code to reproduce the issue
import os
os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "3")
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
import numpy as np
import tensorflow as tf
x = tf.constant([1e200, 1e300, -1e200, -1e300], dtype=tf.float64)
y = tf.math.erf(x).numpy()
truth = np.array([1.0, 1.0, -1.0, -1.0], dtype=np.float64)
print("input:", x.numpy())
print("tensorflow:", y)
print("truth:", truth)
print("isfinite tensorflow:", np.isfinite(y))
print("isfinite truth:", np.isfinite(truth))
if np.any(np.isnan(y)) and np.all(np.isfinite(truth)):
print("BUG REPRODUCED: tf.math.erf returns NaN for very large finite float64 inputs")
else:
print("not reproduced")
Relevant log output
input: [ 1.e+200 1.e+300 -1.e+200 -1.e+300]
tensorflow: [nan nan nan nan]
truth: [ 1. 1. -1. -1.]
isfinite tensorflow: [False False False False]
isfinite truth: [ True True True True]
BUG REPRODUCED: tf.math.erf returns NaN for very large finite float64 inputs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.