In JavaScript the highest integer possible is defined via
Number.MAX_SAFE_INTEGER.
and also in C++ can be obtained with the std:
std::numeric_limits<int>::max()
Is there such a constant in QML for ints or doubles?
As originally suspected, the 2000000000
number listed in the documentation is incorrect. Also, IMO this is an important value that shouldn't really be subject to such careless approximations. "Around" should only be used when the actual value is unknown for certain or not crucial.
A simple test verifies that the largest possible value for an int
property in QML is 2147483647
, or as expected 2^31 - 1
.
Note that this is different from Number.MAX_SAFE_INTEGER
which is a JS thing, and that value is 2^53 - 1
- substantially higher than what int
will give you. Number
is a 64 bit real data type, and it supports integers by using the 53 fraction bits of the number, the 11 exponent bits are left unused.
Edit: In 5.15 and possibly earlier, it is possible to use the full range of an unsigned 32 bit int, doubling the effective range over qml's int
type, but you have to use var
as the property type, it may even be possible to use uint64 with values within the ^53
range.
Another alternative is to use IntValidator. By default, top and bottom property contains the maximum and minimum Qt int value.
readonly property IntValdiator intValdiator: IntValidator {}
readonly property int MAX_VALUE: intValidator.top
readonly property int MIN_VALUE: intValidator.bottom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With