Skip to content

Exp of negative infinity is incorrect for arrays of size larger than 1 (result is non-zero)

Summary

Calling .exp() on an array that contains -inf entries does not result in zero values for those entries, unless the array is size 1.

Environment

  • Operating System : Linux
  • Architecture : x86_64
  • Eigen Version : 3.4.0
  • Compiler Version : Gcc 10.3.0

Minimal Example

Eigen::ArrayXd a(1);
a << -std::numeric_limits<double>::infinity();
Eigen::ArrayXd exp_a = a.exp();
// Printing exp_a will show a zero value, as expected.

Eigen::ArrayXd b(2);
b << -std::numeric_limits<double>::infinity(),
     -std::numeric_limits<double>::infinity();
Eigen::ArrayXd exp_b = b.exp();
// Printing exp_b will show non-zero values (e.g., 5.55553e-309).

Steps to reproduce

  1. Create an Eigen array with more than one entry.
  2. Fill the array with -inf values.
  3. Call .exp() on the array.
  4. See the non-zero results.

What is the current bug behavior?

Exp of negative infinity is non-zero for arrays of size larger than 1.

What is the expected correct behavior?

Exp of negative infinity should always be exactly zero. Non-zero results cause unnecessary numerical issues.