[metapost] Metafun : is "atan" the arctangent function?
Franck Pastor
franck.pastor at me.com
Sun Jan 12 18:19:31 CET 2014
Le 12 janv. 2014 à 16:32, John Kitzmiller a écrit :
> On Jan 12, 2014, at 6:28 AM, Franck Pastor <franck.pastor at me.com> wrote:
>
>> Hello,
>>
>> Reading the "Metafun manual" (2010 edition), I noticed that it mentions p. 324 the existence of a specific "atan" unary operator. I assumed it was the arctangent function and I was pleasantly surprised, since this important inverse trigonometric function was not referenced in chapter 9 ("Functions") of the same Metafun manual. So I gave this atan operator a try but it returned me surprising results. For example, this short line
>>
>> show atan(1);
>>
>> gives me "0.7282" as result ("0.7238095238095239" with numbersystem set to "double"), whereas the right result should be something like "0.7854" in radians (approximation of the exact result, pi/4) and exactly "45" in degrees.
>>
>> Is "atan" thus actually meant as the arctangent function, of something else? Or is it a bug?
>
>
> atan is vardef'd in mp-tool.mpiv as: x = x-(x**3)/3+(x**5)/5-(x**7)/7 , part of the infinite series form. Maybe better to use asin(a/sqrt(a**2+1))?
>
> John
>
I didn't know about this definition (haven't been smart enough to search into mp-tool.mpiv…). Well, I suppose that this definition becomes increasingly unaccurate as x gets away from zero, which would explain the bad result above.
asin(a/sqrt(a**2+1)) gives indeed the good result in degrees. But in the meantime I realised that the atan function in degrees could be more simply defined as "angle(1, —)". And in radians, using
pi/180*angle(1, 1)
gives 0.78552 in scaled number system, not very precise but quite a better result than the infinite series form.
(Note that the angle function with the "double" number representation is somewhat broken in MetaPost 1.803, as I reported a few days previously — Taco Hoekwater told me it was fixed in the latest development versions).
Franck
More information about the metapost
mailing list