[metapost] Metafun : is "atan" the arctangent function?

Daniel H. Luecking luecking at uark.edu
Mon Jan 13 17:29:37 CET 2014


Franck Pastor wrote:

>I had a look in grafbase.mp, the file that contains the MetaPost 
>macros for the mfpic package. It also defines an atan function this way:
>
>vardef atan primary X =  angle (1, X)  enddef;

This, as well as asin and acos, comes right out of Knuth's suggestions in 
"The METAFONT book".

>
>There is also an "invtan" function that gives the result in radians:
>
>vardef invtan primary X =  radians (atan X)  enddef;
>
>where the radians function is
>
>vardef radians (expr t) =  t/radian  enddef;
>
>and
>
>radian := 57.29578;
>
>is a rounding of 180/pi.

The next version of grafbase.mp will have something like
  radian := 57.2957795130823209;
in the hope that it wil benefit from Metapost's new double precision
number system (and not cause any problems for Metafont's less precise
system).

The name "atan" (rather than "atand") was chosen for grafbase 
because that is what I found already being used for the function 
that returned degrees. I assume it is shorthand for arctan, which 
I grew up expecting to produce degrees. 

In most areas of pure analysis we say "inverse tangent" for the 
function returning radians because our tangent function always 
takes radians. 

Logically, the arctangent returning degrees is the inverse of tand 
so maybe it should be "invtand"?

The accuracy of the definitions given in terms of angle() is due to
Knuth's efforts to produce the maximum theoretical accuracy for
angle(), given the limitation of a system based on scaled integers.

One can get pretty good accuracy using power series, provided
one applies the series _after_ certain reductions that leave 
0<x<1/2 . Then, of course, the accuracy for the series taken only 
to the 7th power is only $\pm 2^{-9}/9$. To get Knuth's accuracy 
(roughly $\pm 2^{-16}$) would require at least two more terms.

I actually use a hybrid of Knuth's algorithm (based on something 
called the CORDIC algorithm) and the power series, to provide an 
"angle" function in the minifp package. 

Regards,
Dan

-- 
Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
Fayetteville, Arkansas



More information about the metapost mailing list