Skip to content

fix: engineering notation of negative numbers - #2948

Open
b84330808 wants to merge 1 commit into
WerWolv:masterfrom
b84330808:fix-engineering-string-negative
Open

b84330808 wants to merge 1 commit into
WerWolv:masterfrom
b84330808:fix-engineering-string-negative

Conversation

@b84330808

Copy link
Copy Markdown

Problem description

The calculator's Engineering display mode shows negative numbers wrong: -5 is shown as -5000a and -1500 as -1500a. toEngineeringString() treats every negative value as < 1 and keeps multiplying it by 1000 until it reaches the last suffix (a). It then cuts the result to 5 characters.

Implementation description

Scale the absolute value and put the - back in front. New ToEngineeringString test in tests/helpers/source/utils.cpp covers positive and negative values.

Screenshots

None. The change is only in the text the Engineering mode shows.

Additional things

I couldn't do a full ImHex build here (Windows without MSYS2). I compiled the function text from utils.cpp as-is with zig c++ (clang, C++23) in a small harness with the same checks as the new test. The 3 negative cases fail on master and all pass with the fix. The test file compiles against the real tests.hpp, but CI is the first run of it inside helpers_test.

toEngineeringString() treated every negative value as "< 1" and kept
multiplying by 1000 until it ran out of suffixes, so the calculator's
Engineering mode showed -5 as "-5000a" and -1500 as "-1500a".

Scale the absolute value and put the sign back in front.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant