"long" is 8 bytes, not 4 bytes. and those values are of "int" type which is 4 bytes. Please refer to the documentation:
Documentation on MQL5: Language Basics / Data Types / Integer TypesDocumentation on MQL5: Constants, Enumerations and Structures / Named Constants / Numerical Type Constants
4
- 2 147 483 648
2 147 483 647
int
8
-9 223 372 036 854 775 808
9 223 372 036 854 775 807
__int64
INT_MIN
Minimal value, which can be represented by int type
-2147483648
INT_MAX
Maximal value, which can be represented by int type
2147483647
"long" is 8 bytes, not 4 bytes. and those values are of "int" type which is 4 bytes. Please refer to the documentation:
Thanks. I know that well.
The bug is the literal value -2147483649 should be coded as long type instead of uint.
The tested result on mt4 shows it is long type (8 bytes)
How can a negative constant be typed as a "uint"? And why should it be typed as a "long"? Your code is faulty. see the following ...
void OnStart() { Print( "INT_MAX: ", INT_MAX, ", sizeof = ", sizeof(INT_MAX), ", type = ", typename(INT_MAX) ); Print( "INT_MIN: ", INT_MIN, ", sizeof = ", sizeof(INT_MIN), ", type = ", typename(INT_MIN) ); };
// Results the same on both MT4 and MT5 INT_MAX: 2147483647, sizeof = 4, type = int INT_MIN: -2147483648, sizeof = 4, type = int
How can a negative constant be typed as a "uint"? And why should it be typed as a "long"? Your code is faulty. see the following ...
You did not notice that -2147483649 is INT_MIN -1 , so -2147483649 is not in the range of int type
-2147483649 should be hard-coded as long type but the mt5 compiler coded it as uint type
Ok, now I understand. I did not notice that your values were off by one. Sorry about the misunderstanding.
Yes, you are correct. The compiler is incorrectly considering the value as an "unit" and wrapping the value.
This does seem to be a bug present in both MT4 and MT5.
void OnStart() { Print( "INT_MAX: ", INT_MAX, ", sizeof = ", sizeof(INT_MAX), ", type = ", typename(INT_MAX) ); Print( "INT_MIN: ", INT_MIN, ", sizeof = ", sizeof(INT_MIN), ", type = ", typename(INT_MIN) ); Print( "2147483648: ", 2147483648, ", sizeof = ", sizeof(2147483648), ", type = ", typename(2147483648) ); Print( "-2147483649: ", -2147483649, ", sizeof = ", sizeof(-2147483649), ", type = ", typename(-2147483649) ); Print( "2147483649: ", 2147483649, ", sizeof = ", sizeof(2147483649), ", type = ", typename(2147483649) ); Print( "-2147483650: ", -2147483650, ", sizeof = ", sizeof(-2147483650), ", type = ", typename(-2147483650) ); };
INT_MAX: 2147483647, sizeof = 4, type = int INT_MIN: -2147483648, sizeof = 4, type = int 2147483648: 2147483648, sizeof = 4, type = uint -2147483649: 2147483647, sizeof = 4, type = uint 2147483649: 2147483649, sizeof = 4, type = uint -2147483650: 2147483646, sizeof = 4, type = uint
My work-around was to use "(long)INT_MIN - 1" and "(long)INT_MAX + 1".
void OnStart() { Print( "INT_MAX: ", INT_MAX, ", sizeof = ", sizeof(INT_MAX), ", type = ", typename(INT_MAX) ); Print( "INT_MIN: ", INT_MIN, ", sizeof = ", sizeof(INT_MIN), ", type = ", typename(INT_MIN) ); Print( "2147483648: ", 2147483648, ", sizeof = ", sizeof(2147483648), ", type = ", typename(2147483648) ); Print( "-2147483649: ", -2147483649, ", sizeof = ", sizeof(-2147483649), ", type = ", typename(-2147483649) ); Print( "2147483649: ", 2147483649, ", sizeof = ", sizeof(2147483649), ", type = ", typename(2147483649) ); Print( "-2147483650: ", -2147483650, ", sizeof = ", sizeof(-2147483650), ", type = ", typename(-2147483650) ); Print( "INT_MAX + 1: ", (long)INT_MAX + 1, ", sizeof = ", sizeof((long)INT_MAX + 1), ", type = ", typename((long)INT_MAX + 1) ); Print( "INT_MIN - 1: ", (long)INT_MIN - 1, ", sizeof = ", sizeof((long)INT_MIN - 1), ", type = ", typename((long)INT_MIN - 1) ); };
INT_MAX: 2147483647, sizeof = 4, type = int INT_MIN: -2147483648, sizeof = 4, type = int 2147483648: 2147483648, sizeof = 4, type = uint -2147483649: 2147483647, sizeof = 4, type = uint 2147483649: 2147483649, sizeof = 4, type = uint -2147483650: 2147483646, sizeof = 4, type = uint INT_MAX + 1: 2147483648, sizeof = 8, type = long INT_MIN - 1: -2147483649, sizeof = 8, type = long
Another work-around is to insert "(long)" after the sign, (e.g. "-(long)2147483650").
void OnStart() { Print( "INT_MAX: ", INT_MAX, ", sizeof = ", sizeof(INT_MAX), ", type = ", typename(INT_MAX) ); Print( "INT_MIN: ", INT_MIN, ", sizeof = ", sizeof(INT_MIN), ", type = ", typename(INT_MIN) ); Print( "2147483648: ", 2147483648, ", sizeof = ", sizeof(2147483648), ", type = ", typename(2147483648) ); Print( "-2147483649: ", -2147483649, ", sizeof = ", sizeof(-2147483649), ", type = ", typename(-2147483649) ); Print( "2147483649: ", 2147483649, ", sizeof = ", sizeof(2147483649), ", type = ", typename(2147483649) ); Print( "-2147483650: ", -2147483650, ", sizeof = ", sizeof(-2147483650), ", type = ", typename(-2147483650) ); Print( "(long)INT_MAX + 1: ", (long)INT_MAX + 1, ", sizeof = ", sizeof((long)INT_MAX + 1), ", type = ", typename((long)INT_MAX + 1) ); Print( "(long)INT_MIN - 1: ", (long)INT_MIN - 1, ", sizeof = ", sizeof((long)INT_MIN - 1), ", type = ", typename((long)INT_MIN - 1) ); Print( "-(long)2147483650: ", -(long)2147483650, ", sizeof = ", sizeof(-(long)2147483650), ", type = ", typename(-(long)2147483650) ); };
INT_MIN: -2147483648, sizeof = 4, type = int 2147483648: 2147483648, sizeof = 4, type = uint -2147483649: 2147483647, sizeof = 4, type = uint 2147483649: 2147483649, sizeof = 4, type = uint -2147483650: 2147483646, sizeof = 4, type = uint (long)INT_MAX + 1: 2147483648, sizeof = 8, type = long (long)INT_MIN - 1: -2147483649, sizeof = 8, type = long -(long)2147483650: -2147483650, sizeof = 8, type = long
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I found the literal value -2147483649 and 2147483648 are hard-coded as uint type ,I think they should be long type.
Test code:
Test result:
Verion 5.0 Build 3391
Edited, please note:
-2147483649 = INT_MIN - 1
2147483648 = INT_MAX +1
What I tesed is -2147483649 instead of INT_MIN.