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

Document message support for NaN and other special floating point numeric limits #4135

Open
Ryanf55 opened this issue Jan 25, 2024 · 5 comments · May be fixed by #4210
Open

Document message support for NaN and other special floating point numeric limits #4135

Ryanf55 opened this issue Jan 25, 2024 · 5 comments · May be fixed by #4210
Labels
help wanted Extra attention is needed

Comments

@Ryanf55
Copy link
Contributor

Ryanf55 commented Jan 25, 2024

Hello,

Would it be possible to document in Interfaces that you can set constants or default values to special values like NaN? It's not clear what's supported, and whether NAN, NaN, and whether it would be quiet or signaling NaN.

https://en.cppreference.com/w/cpp/types/numeric_limits

I am writing messages that have values that can fail. Rather than add is_X_valid booleans for every field in the message, I would prefer to have support for NaN. This results in significantly less application code and reduces bandwidth when messages are sent over wireless networks using DDS compared to dedicated booleans.

While doing this, it would also be good to document whether infinity is supported.

Related:

@Ryanf55
Copy link
Contributor Author

Ryanf55 commented Feb 5, 2024

And, the CLI also supports it on humble:
ros2 topic pub /ap/cmd_vel geometry_msgs/msg/TwistStamped "{header: {frame_id: base_link}, twist: {linear: {x: .nan, y: .nan, z: .nan}, angular: {z: 0.01}}}"

@clalancette
Copy link
Contributor

Yeah, I think that is a reasonable thing to document; I'd enhance the table in https://docs.ros.org/en/humble/Concepts/Basic/About-Interfaces.html#field-types to add a "Note" column, or something like that. If you'd like to open a PR to add that, I'd be happy to review it.

@clalancette clalancette added the help wanted Extra attention is needed label Feb 6, 2024
@Ryanf55
Copy link
Contributor Author

Ryanf55 commented Mar 5, 2024

Yeah, I think that is a reasonable thing to document; I'd enhance the table in https://docs.ros.org/en/humble/Concepts/Basic/About-Interfaces.html#field-types to add a "Note" column, or something like that. If you'd like to open a PR to add that, I'd be happy to review it.

It doesn't look like it's actually supported.

In a .msg:

# NaN (IEE-754 quiet NaN) signifies no data is available at the location.
float64 my_value NaN

c: error: ‘nanl’ undeclared (first use in this function)

  276 |   msg->my_value = nanl;

c++: error: ‘nan’ was not declared in this scope

  198 |       this->my_value= nan;

@Ryanf55
Copy link
Contributor Author

Ryanf55 commented Mar 5, 2024

Relates to ros2/rosidl#705

@Ryanf55
Copy link
Contributor Author

Ryanf55 commented Mar 5, 2024

Huh, in the IDL 4.2 spec, it says nothing about special floating point values:
https://www.omg.org/spec/IDL/4.2/PDF

See section 7.2.6.4.

Then in the DDS Consolidated JSON 1.0 spec, it says that NaN is supported.
https://www.omg.org/spec/DDS-JSON/1.0/PDF
See section 7.3.7.4.8

Numeric values, such as Infinity, -Infinity, and NaN, which as stated in [ECMA-404] cannot be represented as
sequences of digits, shall be represented using the following JSON strings: "inf", "-inf", and "nan".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants