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

Support for special float values #126

Open
glennib opened this issue Jun 10, 2020 · 1 comment
Open

Support for special float values #126

glennib opened this issue Jun 10, 2020 · 1 comment

Comments

@glennib
Copy link

glennib commented Jun 10, 2020

I think this genmsg issue is more appropriate here.

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')

A suggestion is to add the lines

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

at the top of the output of msg_generator:

yield '# This Python file uses the following encoding: utf-8'
yield '"""autogenerated by genpy from %s.msg. Do not edit."""' % spec.full_name
yield 'import sys'
yield 'python3 = True if sys.hexversion > 0x03000000 else False'
yield 'import genpy\nimport struct\n'

Another solution would be to have special handling of these types of values at

yield ' %s = %s' % (c.name, c.val)

@dirk-thomas
Copy link
Member

As stated on the referenced ticket already: please consider to provide a pull request for that enhancement.

@dirk-thomas dirk-thomas changed the title Handling of special float values is faulty Support for special float values Jun 10, 2020
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

2 participants