[metapost] Bugs in mpost 1.202 (and less)?

Dan Luecking luecking at uark.edu
Mon Jun 8 19:57:09 CEST 2009

At 01:51 AM 6/8/2009, you wrote:
>Steve Checkoway wrote:
>>On Jun 6, 2009, at 2:53 AM, Taco Hoekwater wrote:
>>>The endless loop is an artifact of 32-bit integer wrapping, where
>>>32767+1 == -32767. Because of this, it loops endlessly through all the
>>>values from -32767 upto 32767.
>>16-bit signed integers have a range of -32768 to 32767 so 32767+1 = 
>>-32768. 32-bit integers have a range of -2147483648 to 2147483647.
>Ah ok, I was off by one. The other 16 bits of the 32-bit integer are
>used for fractional parts, so to make this work it would need 64-bit 
>integers, but these have to be squeezed inside a heap-based data
>structure that only accepts 32-bit values, making it somewhat tedious.

One could change the rules for loops just slightly: add
a test for wrapping. For example, in case of positive
step size, check whether the new value of the index is
now less than the previous value. When wrapping occurs,
terminate the loop.

Alternatively, make it an error to increment the index
when the result would wrap. Surely trapping integer
overflow is a common programming requirement.


Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
"Dubito ergo cogito, cogito ergo sum" --Descartes

More information about the metapost mailing list