-
Notifications
You must be signed in to change notification settings - Fork 128
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
Allow using NaN default values #825
Changes from all commits
5d424cc
63c3f3d
1447047
75b47b0
bd08015
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ extern "C" | |
{ | ||
#endif | ||
|
||
#include <math.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,7 +287,17 @@ non_defaulted_zero_initialized_members = [ | |
u@ | ||
@[ end if]@ | ||
@[ elif constant.type.typename == 'float']@ | ||
@[ if constant.value == 'nan'] | ||
std::numeric_limits<float>::quiet_NaN()@ | ||
@[ else]@ | ||
@(constant.value)f@ | ||
@[ end if]@ | ||
@[ elif constant.type.typename == 'double']@ | ||
@[ if constant.value == 'nan'] | ||
std::numeric_limits<double>::quiet_NaN()@ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of coding this, I chose to use the |
||
@[ else]@ | ||
@(constant.value)f@ | ||
@[ end if]@ | ||
@[ else]@ | ||
@(constant.value)@ | ||
@[ end if]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
# limitations under the License. | ||
|
||
from ast import literal_eval | ||
from math import isnan | ||
|
||
from rosidl_parser.definition import AbstractGenericString | ||
from rosidl_parser.definition import AbstractNestedType | ||
|
@@ -198,13 +199,18 @@ def primitive_value_to_cpp(type_, value): | |
if type_.typename in [ | ||
'short', 'unsigned short', | ||
'char', 'wchar', | ||
'double', 'long double', | ||
'octet', | ||
'int8', 'uint8', | ||
'int16', 'uint16', | ||
]: | ||
return str(value) | ||
|
||
if type_.typename in ['double', 'long double']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also checked if it was a float here. |
||
if isnan(value): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, I needed to surroudn |
||
return 'std::numeric_limits<double>::quiet_NaN()' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of hard-coding as double, I used the type name here. |
||
else: | ||
return str(value) | ||
|
||
if type_.typename == 'int32': | ||
# Handle edge case for INT32_MIN | ||
# Specifically, MSVC is not happy in this case | ||
|
@@ -226,6 +232,8 @@ def primitive_value_to_cpp(type_, value): | |
return '%sull' % value | ||
|
||
if type_.typename == 'float': | ||
if isnan(value): | ||
return 'std::numeric_limits<float>::quiet_NaN()' | ||
return '%sf' % value | ||
|
||
assert False, "unknown primitive type '%s'" % type_.typename | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
float64 FLOAT64_NAN_UC=NAN | ||
float64 FLOAT64_NAN_LC=nan | ||
float32 FLOAT32_NAN_UC=NAN | ||
float32 FLOAT32_NAN_LC=nan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to use
'nanf(\"\")'
on my PR to avoid the c-style cast to a double later.