Limts of arclength

Toby Thurston <[email protected]> Wed, 23 Apr 2025 16:09:41 +0100
Newsgroups gmane.comp.tex.metapost
Message-ID <[email protected]>
This is related to the earlier query about intersectiontimes failing with long paths.

I don't think that I am reporting a bug here, but I just wanted to understand the limits on arclength of paths.

Consider this program:

> warningcheck := 0;
> N = 2**15 - 1;
> 
> show numbersystem;
> show arclength (origin -- right * (N + 63/64));
> show arclength (origin -- right * (N + 1    ));
> end
> 

With the scaled number system, I get this output

> >> "scaled"
> >> 32767.98438
> ! Arithmetic overflow.
> l.6 ... arclength (origin -- right * (N + 1    ));
>                                                   
> ? 
> >> 32767.99998 )


Here `arclength` has failed when the result is >= 2**15 which is perhaps not surprising since the MetafontBook
tells us 

"On the other hand, it turns out that larger numbers can actually 
arise when an expression is being evaluated; MetaFont doesn't
worry about this unless the resulting magnitude is at least 32768."

And if I run that with one of the new number systems I get no error:

> >> "decimal"
> >> 32767.98438262939453125000000000006
> >> 32768.00000762939453125000000000008 )

(At least no error up to 5 decimal places... )

But if I increase the limit, I do get an arithmetic overflow.  Trial and error
shows that the magic number is now 2**15 * 3/2 = 49152

> warningcheck := 0;
> N = 2**15 * 3/2 - 1;
> 
> show numbersystem;
> show arclength (origin -- right * (N + 63/64));
> show arclength (origin -- right * (N + 1    ));
> end


With this new value for N, I get this:

> >> "decimal"
> >> 49151.9843826293945312500000000001
> ! Arithmetic overflow.
> l.6 ... arclength (origin -- right * (N + 1    ));
>                                                   
> ? 
> >> 1E+1000000 )

and

> >> "interval"
> >> 49151.984382629394531249999999999886
> ! Arithmetic overflow.
> l.6 ... arclength (origin -- right * (N + 1    ));
>                                                   
> ? 
> >> -2 )


why is there an overflow with these other number systems?  And why at 2**15 * 3/2 ??

Thanks Toby
--
http://tug.org/metapost/