Skip to content

Fix NumberUtils min/max varargs dropping the sign of zero#1733

Merged
garydgregory merged 1 commit into
apache:masterfrom
alhudz:numberutils-minmax-signed-zero
Jun 26, 2026
Merged

Fix NumberUtils min/max varargs dropping the sign of zero#1733
garydgregory merged 1 commit into
apache:masterfrom
alhudz:numberutils-minmax-signed-zero

Conversation

@alhudz

@alhudz alhudz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Repro: NumberUtils.max(-0.0d, 0.0d) returns -0.0 (so 1 / result is -Infinity); NumberUtils.min(0.0d, -0.0d) returns 0.0.

Cause: the double/float varargs overloads pick the extreme with </>, which rank -0.0 and 0.0 as equal, so the sign held in the accumulator survives. Math.max/Math.min, the three-argument min/max overloads and IEEE754rUtils all return the other sign for these inputs.

Fix: run the loop through Math.max/Math.min in the four double/float overloads, matching the three-argument versions. Those also propagate NaN, so the explicit isNaN check is no longer needed and the existing NaN results stay the same.

@garydgregory garydgregory changed the title fix NumberUtils min/max varargs dropping the sign of zero Fix NumberUtils min/max varargs dropping the sign of zero Jun 26, 2026
@garydgregory garydgregory merged commit aafee70 into apache:master Jun 26, 2026
20 of 21 checks passed
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.

2 participants