Skip to content

Conversation

@duncanita
Copy link

Summary

  • Fix mathematical error in complex expm1 function
  • Add tests for complex expm1 to prevent regression

Problem

The complex implementation of expm1(z) incorrectly computed e^(z-1) instead of e^z - 1.

For example:

  • expm1(0) returned e^(-1) ≈ 0.3679 instead of 0
  • expm1(1) returned e^0 = 1 instead of e - 1 ≈ 1.7183

Fix

Changed src/complex.cc line 1275 from exp(z - one) to exp(z) - one.

Known Limitations

This fix corrects the formula but is still a temporary solution. For small values of z, computing exp(z) - 1 directly suffers from catastrophic cancellation. A proper implementation should use a numerically stable algorithm (e.g., Taylor series for small |z|).

Testing

  • Added 3 new tests for complex expm1 in complex_functions()
  • Ran full test suite with -T flag - no regressions

The complex implementation of expm1(z) incorrectly computed e^(z-1)
instead of e^z - 1. Added tests for complex expm1 to prevent regression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant