atan2
ErrorsCollection

atan2

Synthesised documentation from type/Cool

From type/Cool

See Original text in context

sub atan2($y$x = 1e0)
method atan2($x = 1e0)

The sub should usually be written with two arguments for clarity as it is seen in other languages and in mathematical texts, but the single-argument form is available; its result will always match that of atan.

say atan2 31;             # OUTPUT: «1.2490457723982544␤» 
say atan2 3;                # OUTPUT: «1.2490457723982544␤» 
say atan2 ⅔, ⅓;             # OUTPUT: «1.1071487177940904␤»

The method coerces self and its single argument to Numeric, using them to compute the two-argument arc-tangent in radians.

say 3.atan2;                # OUTPUT: «1.24904577239825␤» 
say ⅔.atan2(⅓);             # OUTPUT: «1.1071487177940904␤»

The $x argument in either the method or the sub defaults to 1 so, in both single-argument cases, the function will return the angle θ in radians between the x-axis and a vector that goes from the origin to the point (3, 1).