power returns invalid complex number for negative base and Infinity as exponent
- Dominant language
- JavaScript
- Stars
- 15.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Following inputs return NaN - aNi in Notepad. Seems like all negative bases yield the same:
(-0.5)^Infinity
(-1)^Infinity
(-2)^Infinty
probably the underlying function pow() returns a Complex with both Real and Imaginary part set to NaN. (haven't checked).
Definitely, NaN + aNi is wrong. But whether this is simply an issue with the rendering, or the underlying logic, is to be analyzed. Some thoughts:
-
Whether the result should be a
Complexwith both Real and Imaginary parts set toNaN, is questionable (after all there is aNaNalready, no need to introduce a "second, complexNaN" value maybe). -
for
-1 < a < 0, the result should probably be zero, as in javascript, this one converges:Math.pow(-0.5,Infinity) // 0 -
for
a < -1the result should not be Infinity (so, unlike javascript), because this is clearly divergent. (I don't understand javascript behavior:Math.pow(-2,Infinity) // Infinity -
-Infinityas exponent should also be considered (currently these cases also return incorrectNaN + aNi, but convergence / divergence should also be considered separately for-Infinity)
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.
Research direction
Start by reviewing issue #804 and the linked open pull request #2097 to determine whether the problem is in power calculation or result rendering. Reproduce the listed negative-base cases with positive and negative Infinity exponents, then define and verify the intended convergence, divergence, and NaN behavior for each case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100