[metapost] bug in arctime calculation

Martin Budaj m.budaj at gmail.com
Thu Aug 6 20:37:56 CEST 2020


Hi,

there is a bug in arctime calculation when using numbersystems decimal
and binary (double and scaled work fine). See the following example:

def test(expr P) =
  pos := 0;
  len := arclength P;
  d := 10bp;
  forever:
    arc_t := arctime pos of P;
    draw ((point arc_t of P) --
         (point arc_t of P) + 1mm * unitvector(direction arc_t of P rotated 90))
         withcolor (1-pos/len);
    message decimal pos & " " & decimal arc_t;
    pos := pos + d;
    exitif pos > len;
  endfor;
  draw P;
enddef;

beginfig(1);
  test((0,0)--(100,0));
endfig;

end

As the test is run on a simple line segment, arctime should increase
linearly from 0 to 1. This is the case for scaled and double
numbersystems:

pos arc_t
0 0
10 0.09999
20 0.2
30 0.29999
40 0.4
50 0.5
60 0.59999
70 0.7
80 0.79999
90 0.9
100 1

But for decimal and binary, arctime is not only non-linear, it's even
non-monotonous:

pos arc_t
0 0
10 0.218357288800015125792849022379372
20 0.338083509141544805383550503071265
30 0.45780972290631604654943093962971
40 0.038767960662661419366106762617287
50 0.098631047814785205469201499670517
60 0.718357199283058404647430603398735
70 0.838083397702050143830649542333004
80 0.957809611466813022214145595635334
90 0.538767915904170514622883519402551
100 0.598631024978811668703918040345015

Could you please look into this issue?

Best wishes
Martin


More information about the metapost mailing list.