Skip to content

Long integers less than 64 bits wide are returned to CLR as System.Numerics.BigInteger rather than System.Int64 #681

@Dewb

Description

@Dewb

Prerequisites

  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

Description

Integers consumed by a C# application embedding IronPython 2.7.8 see long integers returned as System.Numerics.BigInteger even though they would fit inside an Int64.

Steps to Reproduce

IronPython 2.7.8 (2.7.8.0) on .NET 4.0.30319.42000 (64-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 2**30
>>> a
1073741824
>>> a.GetType()
<System.RuntimeType object at 0x000000000000006E [System.Int32]>
>>> a = 2**31
>>> a
2147483648L
>>> a.GetType()
<System.RuntimeType object at 0x000000000000006D [System.Numerics.BigInteger]>
>>> a = System.Int64(2**31)
>>> a
2147483648L
>>> a.GetType()
<System.RuntimeType object at 0x000000000000006F [System.Int64]>
>>>

Expected behavior: Expectation is that values representable as an Int64 would be returned to the CLR world as Int64, and System.Numerics.BigInteger types would not enter the picture unless a value was too large for a 64-bit integer.

Actual behavior: CLR sees Python integers over some threshold between 2**30 and 2**31 as BigInteger, and an explicit cast is required to make sure the CLR sees a long integer as an Int64.

Versions

IronPython 2.7.8 (2.7.8.0) on .NET 4.0.30319.42000 (64-bit)
Behavior also reproduced in 2.7.3 (2.7.0.40).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions