Skip to content

fix: unsigned integer axis maps values below start to overflow - #447

Open
vera-rubin wants to merge 1 commit into
boostorg:developfrom
vera-rubin:fix/integer-unsigned-underflow
Open

vera-rubin wants to merge 1 commit into
boostorg:developfrom
vera-rubin:fix/integer-unsigned-underflow

Conversation

@vera-rubin

Copy link
Copy Markdown

For unsigned, integer::index() evaluated x - min_ before converting to double. When x < min_, wrapping made axis::integer<unsigned>(1, 4) count 0u as overflow instead of underflow, and its circular variant returned bin 0 instead of bin 2.

We negate min_ - x for unsigned x < min_. Signed and floating-point subtraction and growing-axis update() are unchanged.

We added a regression in test/axis_integer_test.cpp: plain and circular unsigned [1, 4) axes fail base, pass fix with both compilers. GCC standalone CMake check passed 89/89 before and after. Axis builds passed C++17 -Wall -Wextra -Werror and C++14/C++20 -Wconversion -Wsign-conversion -Werror. GCC C++14/C++20 passed ASan and UBSan.

Version: base develop at f9017f94684583eeef80eb230768c932a8a6e76c, GCC 13.3.0, Clang 18.1.3, x86-64 Linux.

Fixes #446

— ChipLab

integer::index() computed x - min_ in the value type before converting
to double. For an unsigned value type and x < min_ this wraps around to
a large positive number, so axis::integer<unsigned>(1, 4) put 0 into the
overflow bin instead of the underflow bin, and a circular unsigned axis
returned the wrong bin. Compute min_ - x and negate it in that case.
Signed and floating point value types are unchanged.

Fixes boostorg#446

This branch has not been deployed

No deployments
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.

Unsigned integer axis maps below-range values to overflow

1 participant