[metapost] The "angle" function clashes with numbersystem=double

Franck Pastor franck.pastor at me.com
Wed Jan 1 14:02:42 CET 2014


Firstly, I wish an happy new year to everybody in this mailing list!

Now to my problem: recently, I have been playing a bit with the brand new floating point number representation in MetaPost, and I have just ran into something that looks like a bug: the "angle" function does not always give the right results with this floating point system.

An example: suppose I wish to compute the angle in degrees associated to the (1, 6) vector and then check the result with the tangent function (given  by sind/cosd in plain format). That is what this Metapost program does:

a = angle((1, 6));
show numbersystem, a, sind(a)/cosd(a);

With the numbersystem internal set to "scaled", it results in this console message:

This is MetaPost, version 1.803 (kpathsea version 6.1.1)
(mpost.mp (/usr/local/texlive/2013/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.004) ) (./essai.mp
>> "scaled"
>> 80.53767
>> 6 )

In this case, the results are as good as expected.


But if the same program is executed with numbersystem set to "double", a=angle((1, 6)) becomes way too approximate: 80,5625 instead of 80.5367, and the accuracy of its tangent suffers accordingly. Here is the console output: 

This is MetaPost, version 1.803 (kpathsea version 6.1.1)
(mpost.mp (/usr/local/texlive/2013/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.004) ) (./essai.mp
>> "double"
>> 80.5625
>> 6.016071258776007 )

Any idea of why it has gone wrong?

Thanks in advance,

Franck Pastor







More information about the metapost mailing list