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

repr Infinity #1449

Open
wants to merge 1 commit into
base: RB-10.5
Choose a base branch
from
Open

Conversation

ericmehl
Copy link
Collaborator

@ericmehl ericmehl commented Dec 6, 2024

This fixes a bug where imath vectors and colors with values set to infinity were not repr-ing in a form that could then be eval-ed.

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Cortex project's prevailing coding style and conventions.

Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

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

Thanks Eric - repr() changes LGTM, but I think we can omit the str() changes - see inline comment for rationale...

Comment on lines 89 to 119
s << boost::lexical_cast<string>( x[i] );\
if constexpr( std::numeric_limits<VEC::BaseType>::has_infinity )\
{\
s << (\
x[i] == std::numeric_limits<VEC::BaseType>::infinity() ? g_positiveInfString :\
( x[i] == -std::numeric_limits<VEC::BaseType>::infinity() ? g_negativeInfString :\
boost::lexical_cast<std::string>( x[i] ) ) \
);\
}\
else\
{\
s << boost::lexical_cast<string>( x[i] );\
}\
Copy link
Member

Choose a reason for hiding this comment

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

I think we should omit this special treatment for str(), and limit it only to repr(). The main requirement for str() is that it be simple and readable, which I think we had covered already. Only repr() has the requirement that it generate a string that executes in Python, so I think that's the only place it makes sense to use the Python-specific syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense to me. I reverted the str() treatment and added a test to verify str() is correct for inf values and squashed into 3b46e20.

@ericmehl
Copy link
Collaborator Author

Squashed down a fix for the str() handling and ready for another look.

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.

2 participants