Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: dec32f3ffb
Fetching contributors…

Cannot retrieve contributors at this time

file 56 lines (47 sloc) 1.574 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
use v6;
use Test;
plan 48;

# L<S32::Numeric/Complex/"=item polar">

=begin pod

#Basic tests for polar()

=end pod

my $sq2 = 2.sqrt;
sub check_polar($complex, $magnitude_want, $angle_want) {
   my ($magnitude, $angle) = $complex.polar;
   is_approx($magnitude, $magnitude_want, "$complex has a magnitude of $magnitude_want");
   is_approx($angle, $angle_want, "$complex has an angle of $angle_want");
}

# reference angles
{
   check_polar( 1+0i, 1 , 0 );
   check_polar( 1+1i, $sq2, pi/4 );
   check_polar( 0+1i, 1 , pi/2 );
   check_polar(-1+1i, $sq2, pi/4+pi/2 );
   check_polar(-1+0i, 1 , pi );
   check_polar(-1-1i, $sq2, -pi+pi/4 );
   check_polar( 0-1i, 1 , -pi/2 );
   check_polar( 1-1i, $sq2, -pi/4 );
}

# ints
{
   check_polar( 4+0i, 4 , 0 );
   check_polar( 2+5i, 5.38516, 1.19028995);
   check_polar( 0+9i, 9 , pi/2 );
   check_polar(-3+2i, 3.60555, 2.55359005);
   check_polar(-9+0i, 9 , pi );
   check_polar(-4-7i, 8.06226, -2.0899424);
   check_polar( 0-6i, 6 , -pi/2 );
   check_polar( 7-6i, 9.21954, -0.7086263);
}

# rats
{
   check_polar( 9.375+0i , 9.375 , 0 );
   check_polar( 4.302+8.304i, 9.352198, 1.09280250);
   check_polar( 0+ 2.631i, 2.631 , pi/2 );
   check_polar(-4.175+6.180i, 7.458085, 2.16493496);
   check_polar(-8.087+0i , 8.087 , pi );
   check_polar(-9.191-4.810i, 10.37355, -2.6594494);
   check_polar( 0- 0.763i, 0.763 , -pi/2 );
   check_polar( 9.927-5.192i, 11.20277, -0.4818920);
}

# vim: ft=perl6
Something went wrong with that request. Please try again.