Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make double parsing locale independent #921

Merged

Conversation

henningkayser
Copy link
Contributor

@henningkayser henningkayser commented Jan 23, 2023

A recent comment in a MoveIt issue made me curious about locale-dependent bugs and runtime flakiness in general. Turns out, parsing doubles with std::stod is locale dependent and will silently remove decimals if the parsed text doesn't fit the configured locale. This has been found out and fixed a while ago (see ros/urdfdom#98 for instance), but it still seems to be an issue in several packages, ros2_control is just a prominent one and a great example for a start. See this MoveIt issue for other examples moveit/moveit2#1882.

Solution: use https://en.cppreference.com/w/cpp/utility/from_chars which implements locale default "C" using dot notation.

(I just pushed 958be1c to demonstrate the issue by making the test fail)

@henningkayser henningkayser force-pushed the pr/locale_independent_doubles branch from fcbda9b to 958be1c Compare January 23, 2023 16:36
@henningkayser henningkayser force-pushed the pr/locale_independent_doubles branch from af611d8 to 1a427bc Compare January 23, 2023 16:44
@henningkayser henningkayser changed the title Draft: Make double parsing locale independent Make double parsing locale independent Jan 23, 2023
Copy link
Member

@destogl destogl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great PR and detailed explanation. Can you just a do a small cosmetic fix please?

hardware_interface/src/mock_components/generic_system.cpp Outdated Show resolved Hide resolved
@bmagyar bmagyar merged commit 78bb0ca into ros-controls:master Jan 24, 2023
@bmagyar
Copy link
Member

bmagyar commented Jan 24, 2023

@Mergifyio backport to humble

mergify bot pushed a commit that referenced this pull request Jan 24, 2023
@mergify
Copy link
Contributor

mergify bot commented Jan 24, 2023

backport to humble

✅ Backports have been created

bmagyar pushed a commit that referenced this pull request Jan 25, 2023
(cherry picked from commit 78bb0ca)

Co-authored-by: Henning Kayser <[email protected]>
bmagyar added a commit to bmagyar/ros2_control that referenced this pull request Mar 8, 2023
bmagyar added a commit that referenced this pull request Mar 9, 2023
christophfroehlich pushed a commit to christophfroehlich/ros2_control that referenced this pull request Aug 22, 2023
@paulm-planted
Copy link

Usage of std::from_chars requires C++17. Which is not available on all target hardware platforms. :(

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.

4 participants