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

Special Float Generation #85

Open
sye8 opened this issue Jun 18, 2019 · 3 comments
Open

Special Float Generation #85

sye8 opened this issue Jun 18, 2019 · 3 comments

Comments

@sye8
Copy link

sye8 commented Jun 18, 2019

In cases where constants in messages are set to special floats, for example:

float32 a = NaN
float32 p = Inf
float32 n = -Inf 

The successfully generated Python script declare those as:

a = nan
p = inf
n = -inf

However, those causes NameError as nan, inf don't exist.

The following works in Python:

a = float('nan')
p = float('inf')
n = float('-inf')
@dirk-thomas
Copy link
Member

That would be a great addition. Please consider to provide a pull request for that enhancement.

@glennib
Copy link

glennib commented Jun 10, 2020

I think the issue may be with this line in genpy: https://github.com/ros/genpy/blob/5008399c9e8f936c0a7067505c2b7cc4c6c09748/src/genpy/generator.py#L864

yield '  %s = %s' % (c.name, c.val)
# where c.name is the constant name and c.val is the actual value
# when converted to string, c.val just becomes nan

There should probably be a check for special values and provide the appropriate strings OR we should add the lines

nan = float('nan')
inf = float('inf')

at the top.

I have created a new issue ros/genpy#126. Perhaps this issue can be closed, as I don't think we can fix it from genmsg?

@dirk-thomas
Copy link
Member

dirk-thomas commented Jun 10, 2020

Perhaps this issue can be closed, as I don't think we can fix it from genmsg?

genmsg provides the parsing logic and the cross-language API. So the concept needs to be added here first and then genpy can use it to generate Python specific code. gencpp (and other languages) will need to be updated accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants