-
Notifications
You must be signed in to change notification settings - Fork 202
Fixed HighLimit and LowLimit for SIGNED values in EDS #345
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
Conversation
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.
Hi, thanks for the PR.
I know this library now supports python 3.x+, but I would drop the type hints for sake of uniformization with the rest of the files, since the new functions are the only ones using it.
Sure, I thought I wrote this fix without type hints, but in the function header I forgot them. (habbits don't die easily) |
…#345) * Fixed incorrect min (LowLImit) and max (HighLimit) values when using signed integer types. * Fixed min/max for non-signed datatypes and added tests * Removed type hints
self.assertEqual(uint8.min, 2) | ||
self.assertEqual(uint8.max, 10) | ||
int32 = self.od[0x3030] | ||
self.assertEqual(int32.min, -2147483648) |
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.
int32.min should be -1 in my understanding.
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.
You are correct. I don't know why I didn't see it. This should be the correct function:
def _signed_int_from_hex(hex_str, bit_length):
number = int(hex_str, 0)
max_value = (1 << (bit_length - 1)) - 1
if number > max_value:
return number - (1 << bit_length)
else:
return number
I will commit a full fix with correct tests in the evening.
These values have been interpreted as unsigned values and therefore valid values raised warnings.