Skip to content

PyInt.ToString returns wrong strings for values between 128 and 256 #1990

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

Closed
rmadsen-ks opened this issue Oct 28, 2022 · 0 comments · Fixed by #1993
Closed

PyInt.ToString returns wrong strings for values between 128 and 256 #1990

rmadsen-ks opened this issue Oct 28, 2022 · 0 comments · Fixed by #1993
Labels

Comments

@rmadsen-ks
Copy link
Contributor

rmadsen-ks commented Oct 28, 2022

Environment

  • Pythonnet version: 3.0.0-rc6
  • Python version: 3.7
  • Operating System: Windows 10
  • .NET Runtime: .net 6

This test fails with error -56 != 200

def test_object_string_format():
    """Test int to string."""
    from System import String
    integer_value = 200
    string_value = String.Format("{0}", integer_value)
    assert string_value == "200", f"{string_value} != ""200"""

Solution coming up

@filmor filmor added the bug label Oct 28, 2022
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 28, 2022
BigInteger constructor uses the sign bit in the first byte. Since we explicitly handle the sign, the fix is to prepend a zero byte to the number, which does not change it, but ensures sign bit is zero.

fixes pythonnet#1990
lostmsu added a commit to losttech/pythonnet that referenced this issue Oct 28, 2022
BigInteger constructor uses the sign bit in the first byte. Since we explicitly handle the sign, the fix is to prepend a zero byte to the number, which does not change it, but ensures sign bit is zero.

fixes pythonnet#1990
elan-ajain pushed a commit to elancapital/pythonnet that referenced this issue Feb 17, 2023
BigInteger constructor uses the sign bit in the first byte. Since we explicitly handle the sign, the fix is to prepend a zero byte to the number, which does not change it, but ensures sign bit is zero.

fixes pythonnet#1990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants