include/cxx/{cstdlib,cmath}: Provide std::abs(float) overloads - #19891
Open
mpflanzer wants to merge 1 commit into
Open
include/cxx/{cstdlib,cmath}: Provide std::abs(float) overloads#19891mpflanzer wants to merge 1 commit into
mpflanzer wants to merge 1 commit into
Conversation
mpflanzer
requested review from
davids5,
jerpelea and
xiaoxiang781216
as code owners
August 17, 2026 17:12
Author
|
How shall I address the style errors in the |
mpflanzer
force-pushed
the
pflanzem-std-abs
branch
2 times, most recently
from
August 19, 2026 07:12
79172d4 to
8f1617f
Compare
The overloads of std::abs are defined in cstdlib and cmath according to the C++ standard. Without these new definitions the `int std::abs(int)` function was selected for all argument types resulting in a truncation of the return values. Signed-off-by: Moritz Pflanzer <moritz@chickadee-engineering.com>
mpflanzer
force-pushed
the
pflanzem-std-abs
branch
from
August 19, 2026 07:17
8f1617f to
94f62fb
Compare
xiaoxiang781216
approved these changes
Aug 19, 2026
jerpelea
approved these changes
Aug 19, 2026
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The new overloads of
std::absadded tocstdlibandcmathare defined as specified by the C++ standard: https://en.cppreference.com/cpp/numeric/math/fabsWithout these new definitions the
int std::abs(int)function, provided byusing ::abs, was selected for all argument types resulting in a truncation of the result.Impact
Improved compatibility with the C++ standard
Testing
Without the changes running this program results in the following output:
That is compliant for
::absbut not forstd::abs.With the changes the right overloads of
std::absare selected and the output is:Tested with the
qemu-armv7a:nshconfig