pjfanning opened a new pull request, #1444:
URL: https://github.com/apache/poi/pull/1444
Three related bugs in the complex number functions.
**IMAGINARY and IMREAL of a number without a real part**
| | before | after |
|---|---|---|
| `IMAGINARY("3i")` | 1 | 3 |
| `IMAGINARY("-i")` | 1 | -1 |
| `IMAGINARY("2.5j")` | 1 | 2.5 |
| `IMREAL("3i")` | 3 | 0 |
| `IMREAL("-3i")` | -3 | 0 |
`COMPLEX_NUMBER_PATTERN` is greedy. For `"3i"` it captures `3` as the real
part and leaves both imaginary groups empty. When a suffix is present and both
imaginary groups are empty, the new `Imaginary.isImaginaryOnly(Matcher)` reads
the real-part groups as the imaginary part. Numbers with both parts, such as
`3-i` and `-3-4i`, already worked and are unchanged.
**COMPLEX**
| | before | after |
|---|---|---|
| `COMPLEX(3,-1)` | `3i` | `3-i` |
| `COMPLEX(0,-1)` | `i` | `-i` |
| `COMPLEX(0,0)` | `""` | `0` |
**Expected values:** Microsoft documents `COMPLEX(0,1)` as `i` and
`COMPLEX(1,0)` as `1`, and the IM* functions have to read back what COMPLEX
produces. The new `TestComplex.testImaginaryAndImRealOfComplex` checks that
IMREAL and IMAGINARY recover both coefficients of COMPLEX output, with both
suffixes, for numbers with and without a real part. It fails before this
change. `testBasic` also gets the `-i`, `3-i` and `0` cases.
**Tests:** `TestComplex`, `TestComplexFunctionsFromSpreadsheet`,
`TestImaginaryFunctionsFromSpreadsheet` and
`TestImRealFunctionsFromSpreadsheet` pass.
**Conflict with #1441:** that PR replaces the regex matching in
`Imaginary`/`ImReal` with `parseComplexNumber` and keeps the same groups. This
one only reads the groups, so whichever is merged second needs a small rebase.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]