Discussion:
vishap Oberon and MIN(LONGINT)
(too old to reply)
d***@gmail.com
2017-11-28 23:08:28 UTC
Permalink
Using the latest vishap from github (v2.1.0 [2017/11/21] on Ubuntu 16.04.2 x64
Using compile option -OC

IMPORT Out;

Out.Int(MIN(LONGINT),0); # produces -9223372036854775808

Out.Int(-9223372036854775808, 0) # produces Out.Int(-9223372036854775808, 0);
^
pos 138 err 203 number too large

Out.Int( (MIN(LONGINT)) DIV 10, 0); # produces 922337203685477579

Out.LongReal( MIN(LONGINT) / 10.0, 20); # produces -9.22337203685478D+017
David Brown
2017-11-29 10:05:30 UTC
Permalink
This is actually an expected result of the design of two's complement numbers and the way the parser is specified.

The minus sign is not parsed as part of the number, but as a separate operator. This is required to correctly parse Oberon operator precedence rules.

Thus the number is parsed as a positive integer.

The largest possible positive twos complement integer for a given integer size is one less than the absolute value of the largest possible negative integer.

Thus 9223372036854775807 is parseable, but 9223372036854775808 is not.

The C compiler does this the same (not that that's saying it's good ...).

The workaround is to code -9223372036854775807-1, or just MIN(LONGINT).
Loading...