[answered] python max integer question

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

[answered] python max integer question

Post by uwestoehr »

When I set an App::PropertyIntegerConstraint that was defined via Python to e.g
1e16

I get this error:

Code: Select all

Python int too large to convert to C long
sys.maxsize gives me:
9.2e18
So why doIi get this error despite 1e16 is smaller than sys.maxsize?

I have:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: python max integer question

Post by uwestoehr »

To be precise, this is my code that fails:

Code: Select all

solver.addProperty(
            "App::PropertyIntegerConstraint",
            "TimestepIntervals",
            "Timestepping",
            "Maximum optimization rounds if 'Simulation Type'\nis either 'Scanning' or 'Transient'"
            )
            solver.TimestepIntervals = (100, 1, int(1e16), 1)
It also fails with int(1e12).
1e8 works.
User avatar
mfro
Posts: 664
Joined: Sat Sep 23, 2017 8:15 am

Re: python max integer question

Post by mfro »

Microsoft, in their ultimate wisdom, decided that a long with 32 bits in length would be long enough.

At least if you use the MSVC compiler.
Cheers,
Markus
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: python max integer question

Post by uwestoehr »

mfro wrote: Fri Aug 05, 2022 4:28 pm Microsoft, in their ultimate wisdom, decided that a long with 32 bits in length would be long enough.
Thanks!
Googling now shows that also on 64bit Win and when compiling with 64bit as target, 32 bit is used. :o
User avatar
mfro
Posts: 664
Joined: Sat Sep 23, 2017 8:15 am

Re: python max integer question

Post by mfro »

uwestoehr wrote: Fri Aug 05, 2022 4:40 pm
mfro wrote: Fri Aug 05, 2022 4:28 pm Microsoft, in their ultimate wisdom, decided that a long with 32 bits in length would be long enough.
Thanks!
Googling now shows that also on 64bit Win and when compiling with 64bit as target, 32 bit is used. :o
If you want a 64 bit type on Windows (64), you have to use size_t.
Cheers,
Markus
Post Reply