rdiankov / openrave

Open Robotics Automation Virtual Environment: An environment for testing, developing, and deploying robotics motion planning algorithms.
http://www.openrave.org
Other
706 stars 344 forks source link

support interger 2**64-1 #1306

Closed eisoku9618 closed 1 year ago

eisoku9618 commented 1 year ago
name = 'aaa'
body = RaveCreateKinBody(env, "")
body.SetName(name)
robot.Grab(body, robot.GetLinks()[0], [0], {'bigNumber': 2**64 - 1})
print(robot.GetGrabbedInfo(name).SerializeJSON()['grabbedUserData']['bigNumber'])

When we call toRapidJSONValue -> PyLong_AsLong via Grab for an interger which value is 2**64-1, I get the following error from CPython

In [1]: name = 'aaa'; body = RaveCreateKinBody(env, ""); body.SetName(name); robot.Grab(body, robot.GetLinks()[0], [0], {'bigNumber': 2**64 - 1}); robot.GetGrabbedInfo(name).SerializeJSON()['grabbedUserData']['bigNumber'];
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
OverflowError: Python int too large to convert to C long

for my record: https://levelup.gitconnected.com/how-python-represents-integers-using-bignum-f8f0574d0d6b

cielavenir commented 1 year ago

@eisoku9618 just in case, could you check if 2**63-2 works?

eisoku9618 commented 1 year ago

@cielavenir Thank you, it didn't work...

cielavenir commented 1 year ago

Please try PyLong_AsUnsignedLong

eisoku9618 commented 1 year ago

Here is my test summary

input number result
-2**63 ok
-2**63-1 OverflowError: can't convert negative value to unsigned long
2**63-1 ok
2**63 ok
2**64-2 ok
2**64-1 ok
2**64 OverflowError: long int too large to convert
rdiankov commented 1 year ago

Thanks~