Quote
Karel has special Constants:
MAXINT +2147483647
MININT -2147483648
I have done some research on these issues.
- Behavior of Karel/Karel variables
- Behavior of TP programs or registers
Error inside Karel manual:
----
2.1.6 Predefined Identifiers
...
MAXINT INTEGER +2147483647
MININT INTEGER-2147483648
...However,the predefined identifier MININT is an exception to this rule. This identifier must always be used in place of its value, -2147483648. The value or number itself can not be used...
----
The above statement is wrong.
The value -2147483648 (MININT) can be used normally and is displayed correctly.
It turns out that the value of MAXINT is always 2147483646.
However, if the value is stored after the two's complement, it should be 2147483647.
In Karel, however, the maximum integer value is 2147483646. If the bits are set to the "regular value of MAXINT, i.e. 2147483647, and then assigned to a Karel integer variable, the value is uninitialized.
So not all (regular)values are possible.
In TP, however, it behaves differently with the registers.
Calculating and setting with MaxINTEGER works. Also the overflow behaves as expected.
Only the display on TP and in the web interface is not "nice".
Here are some comparisons TP / Karel
Karel:
--
value = MININT; --> value -2147483648
value = -2147483648; --> value -2147483648
--
value = MAXINT; --> value +2147483646
value = 2147483646; --> value +2147483646
IF value = MAXINT ... --> true
value = 2147483647 ; --> value *****
value = MAXINT +1 ; --> value *****
value = 2147483646 +1 ; --> value *****
IF UNINIT(value)... --> true
-- no more calculation possible, only query if UNINIT works
--> recognition is possible, but "calculating" becomes "messy"
TP
R[1] = -2147483648; --> R[1] -2147483648
R[1] = -2147483647-1; --> R[1] -2147483648
R[1] = 2147483646; --> R[1] 2147483646
R[1] = 2147483646+1; --> R[1] ******* (2147483647)
R[1] = R[1] +1 ; --> R[1] -2147483648
-- Calculation and overflow works as expected
-- The display is ***** not nice
When a program with ascii upload is played to the controller with the following code:
: R[1] = 2147483647;
it will be displayed like this:
: R[1] = ******; --> When the LS prog is downloaded it contains the stars and cannot be uploaded anymore. It is like with uninitialized positions in TP programs.
I hope I could help a little further and/or bring light into the darkness.
best regards
PnsStarter