This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Math-Complex: netbsd-vax: no inf
[perl5.git] / cpan / Math-Complex / t / Complex.t
CommitLineData
89d0527d
RM
1#!./perl
2
89d0527d 3#
5aabfad6 4# Regression tests for the Math::Complex pacakge
b42d0ec9
JH
5# -- Raphael Manfredi since Sep 1996
6# -- Jarkko Hietaniemi since Mar 1997
7# -- Daniel S. Lewart since Sep 1997
5aabfad6 8
f1e71051 9use Math::Complex 1.54;
89d0527d 10
33f0e035
JH
11our $vax_float = (pack("d",1) =~ /^[\x80\x10]\x40/);
12our $has_inf = !$vax_float;
13
fb73857a
PP
14my ($args, $op, $target, $test, $test_set, $try, $val, $zvalue, @set, @val);
15
89d0527d
RM
16$test = 0;
17$| = 1;
fb73857a 18my @script = (
bf5f1b4c 19 'my ($res, $s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$z0,$z1,$z2);' .
fb73857a
PP
20 "\n\n"
21);
b42d0ec9 22my $eps = 1e-13;
89d0527d 23
d09ae4e6 24if ($^O eq 'unicos') { # For some reason root() produces very inaccurate
f3ff050f 25 $eps = 1e-10; # results in Cray UNICOS, and occasionally also
d09ae4e6
JH
26} # cos(), sin(), cosh(), sinh(). The division
27 # of doubles is the current suspect.
28
3194a40a
Z
29$test++;
30push @script, "{ my \$t=$test; ".q{
31 my $a = Math::Complex->new(1);
32 my $b = $a;
33 $a += 2;
34 print "not " unless "$a" eq "3" && "$b" eq "1";
35 print "ok $t\n";
36}."}";
37
89d0527d 38while (<DATA>) {
0c721ce2
JH
39 s/^\s+//;
40 next if $_ eq '' || /^\#/;
41 chomp;
42 $test_set = 0; # Assume not a test over a set of values
0e505df1 43 if (/^&(.+)/) {
89d0527d
RM
44 $op = $1;
45 next;
46 }
0e505df1 47 elsif (/^\{(.+)\}/) {
89d0527d
RM
48 set($1, \@set, \@val);
49 next;
50 }
51 elsif (s/^\|//) {
0c721ce2 52 $test_set = 1; # Requests we loop over the set...
89d0527d
RM
53 }
54 my @args = split(/:/);
0c721ce2 55 if ($test_set == 1) {
89d0527d
RM
56 my $i;
57 for ($i = 0; $i < @set; $i++) {
0c721ce2
JH
58 # complex number
59 $target = $set[$i];
60 # textual value as found in set definition
61 $zvalue = $val[$i];
89d0527d
RM
62 test($zvalue, $target, @args);
63 }
64 } else {
65 test($op, undef, @args);
66 }
67}
68
b42d0ec9
JH
69#
70
71sub test_mutators {
72 my $op;
73
74 $test++;
75push(@script, <<'EOT');
76{
77 my $z = cplx( 1, 1);
78 $z->Re(2);
79 $z->Im(3);
16357284 80 print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
b42d0ec9
JH
81 print 'not ' unless Re($z) == 2 and Im($z) == 3;
82EOT
83 push(@script, qq(print "ok $test\\n"}\n));
84
85 $test++;
86push(@script, <<'EOT');
87{
88 my $z = cplx( 1, 1);
89 $z->abs(3 * sqrt(2));
16357284 90 print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
b42d0ec9
JH
91 print 'not ' unless (abs($z) - 3 * sqrt(2)) < $eps and
92 (arg($z) - pi / 4 ) < $eps and
93 (Re($z) - 3 ) < $eps and
94 (Im($z) - 3 ) < $eps;
95EOT
96 push(@script, qq(print "ok $test\\n"}\n));
97
98 $test++;
99push(@script, <<'EOT');
100{
101 my $z = cplx( 1, 1);
102 $z->arg(-3 / 4 * pi);
16357284 103 print "# $test Re(z) = ",$z->Re(), " Im(z) = ", $z->Im(), " z = $z\n";
b42d0ec9
JH
104 print 'not ' unless (arg($z) + 3 / 4 * pi) < $eps and
105 (abs($z) - sqrt(2) ) < $eps and
106 (Re($z) + 1 ) < $eps and
107 (Im($z) + 1 ) < $eps;
108EOT
109 push(@script, qq(print "ok $test\\n"}\n));
110}
111
112test_mutators();
113
114my $constants = '
115my $i = cplx(0, 1);
116my $pi = cplx(pi, 0);
117my $pii = cplx(0, pi);
118my $pip2 = cplx(pi/2, 0);
bf5f1b4c 119my $pip4 = cplx(pi/4, 0);
b42d0ec9
JH
120my $zero = cplx(0, 0);
121';
122
33f0e035
JH
123if ($has_inf) {
124 $constants .= <<'EOF';
125my $inf = 9**9**9;
126EOF
127}
128
b42d0ec9
JH
129push(@script, $constants);
130
131
5cd24f17
PP
132# test the divbyzeros
133
0e505df1
JH
134sub test_dbz {
135 for my $op (@_) {
136 $test++;
b42d0ec9 137 push(@script, <<EOT);
16357284
JH
138 eval '$op';
139 (\$bad) = (\$@ =~ /(.+)/);
140 print "# $test op = $op divbyzero? \$bad...\n";
141 print 'not ' unless (\$@ =~ /Division by zero/);
b42d0ec9
JH
142EOT
143 push(@script, qq(print "ok $test\\n";\n));
0e505df1
JH
144 }
145}
146
8c03c583
JH
147# test the logofzeros
148
149sub test_loz {
150 for my $op (@_) {
151 $test++;
b42d0ec9 152 push(@script, <<EOT);
16357284
JH
153 eval '$op';
154 (\$bad) = (\$@ =~ /(.+)/);
155 print "# $test op = $op logofzero? \$bad...\n";
156 print 'not ' unless (\$@ =~ /Logarithm of zero/);
b42d0ec9
JH
157EOT
158 push(@script, qq(print "ok $test\\n";\n));
8c03c583
JH
159 }
160}
161
5cd24f17
PP
162test_dbz(
163 'i/0',
b42d0ec9
JH
164 'acot(0)',
165 'acot(+$i)',
166# 'acoth(-1)', # Log of zero.
167 'acoth(0)',
168 'acoth(+1)',
5cd24f17 169 'acsc(0)',
5cd24f17 170 'acsch(0)',
b42d0ec9
JH
171 'asec(0)',
172 'asech(0)',
b42d0ec9
JH
173 'atan($i)',
174# 'atanh(-1)', # Log of zero.
175 'atanh(+1)',
176 'cot(0)',
177 'coth(0)',
178 'csc(0)',
b42d0ec9 179 'csch(0)',
bf5f1b4c 180 'atan(cplx(0, 1), cplx(1, 0))',
8c03c583
JH
181 );
182
183test_loz(
fb73857a 184 'log($zero)',
1fa12f56 185 'atan(-$i)',
b42d0ec9 186 'acot(-$i)',
8c03c583
JH
187 'atanh(-1)',
188 'acoth(-1)',
5cd24f17
PP
189 );
190
0e505df1
JH
191# test the bad roots
192
193sub test_broot {
5cd24f17
PP
194 for my $op (@_) {
195 $test++;
b42d0ec9 196 push(@script, <<EOT);
16357284
JH
197 eval 'root(2, $op)';
198 (\$bad) = (\$@ =~ /(.+)/);
199 print "# $test op = $op badroot? \$bad...\n";
1fa12f56 200 print 'not ' unless (\$@ =~ /root rank must be/);
b42d0ec9
JH
201EOT
202 push(@script, qq(print "ok $test\\n";\n));
5cd24f17
PP
203 }
204}
205
0e505df1
JH
206test_broot(qw(-3 -2.1 0 0.99));
207
16357284 208sub test_display_format {
476757f7
YN
209 $test++;
210 push @script, <<EOS;
211 print "# package display_format cartesian?\n";
212 print "not " unless Math::Complex->display_format eq 'cartesian';
213 print "ok $test\n";
214EOS
215
16357284
JH
216 push @script, <<EOS;
217 my \$j = (root(1,3))[1];
218
219 \$j->display_format('polar');
220EOS
221
222 $test++;
223 push @script, <<EOS;
476757f7 224 print "# j display_format polar?\n";
16357284
JH
225 print "not " unless \$j->display_format eq 'polar';
226 print "ok $test\n";
227EOS
228
229 $test++;
230 push @script, <<EOS;
231 print "# j = \$j\n";
232 print "not " unless "\$j" eq "[1,2pi/3]";
233 print "ok $test\n";
234
235 my %display_format;
236
237 %display_format = \$j->display_format;
238EOS
239
240 $test++;
241 push @script, <<EOS;
242 print "# display_format{style} polar?\n";
243 print "not " unless \$display_format{style} eq 'polar';
244 print "ok $test\n";
245EOS
246
247 $test++;
248 push @script, <<EOS;
249 print "# keys %display_format == 2?\n";
250 print "not " unless keys %display_format == 2;
251 print "ok $test\n";
252
253 \$j->display_format('style' => 'cartesian', 'format' => '%.5f');
254EOS
255
256 $test++;
257 push @script, <<EOS;
258 print "# j = \$j\n";
259 print "not " unless "\$j" eq "-0.50000+0.86603i";
260 print "ok $test\n";
261
262 %display_format = \$j->display_format;
263EOS
264
265 $test++;
266 push @script, <<EOS;
267 print "# display_format{format} %.5f?\n";
268 print "not " unless \$display_format{format} eq '%.5f';
269 print "ok $test\n";
270EOS
271
272 $test++;
273 push @script, <<EOS;
274 print "# keys %display_format == 3?\n";
275 print "not " unless keys %display_format == 3;
276 print "ok $test\n";
277
278 \$j->display_format('format' => undef);
279EOS
280
281 $test++;
282 push @script, <<EOS;
283 print "# j = \$j\n";
057216a3 284 print "not " unless "\$j" =~ /^-0(?:\\.5(?:0000\\d+)?|\\.49999\\d+)\\+0.86602540\\d+i\$/;
16357284
JH
285 print "ok $test\n";
286
287 \$j->display_format('style' => 'polar', 'polar_pretty_print' => 0);
288EOS
289
290 $test++;
291 push @script, <<EOS;
292 print "# j = \$j\n";
1ab88a68 293 print "not " unless "\$j" =~ /^\\[1,2\\.09439510\\d+\\]\$/;
16357284
JH
294 print "ok $test\n";
295
3194a40a
Z
296 \$j->display_format('style' => 'polar', 'format' => "%.4g");
297EOS
298
299 $test++;
300 push @script, <<EOS;
301 print "# j = \$j\n";
302 print "not " unless "\$j" =~ /^\\[1,2\\.094\\]\$/;
303 print "ok $test\n";
304
16357284
JH
305 \$j->display_format('style' => 'cartesian', 'format' => '(%.5g)');
306EOS
476757f7 307
16357284
JH
308 $test++;
309 push @script, <<EOS;
310 print "# j = \$j\n";
311 print "not " unless "\$j" eq "(-0.5)+(0.86603)i";
312 print "ok $test\n";
313EOS
476757f7
YN
314
315 $test++;
316 push @script, <<EOS;
317 print "# j display_format cartesian?\n";
318 print "not " unless \$j->display_format eq 'cartesian';
319 print "ok $test\n";
320EOS
16357284
JH
321}
322
323test_display_format();
324
91cb744f
JH
325sub test_remake {
326 $test++;
327 push @script, <<EOS;
328 print "# remake 2+3i\n";
bf5f1b4c 329 \$z = cplx('2+3i');
91cb744f
JH
330 print "not " unless \$z == Math::Complex->make(2,3);
331 print "ok $test\n";
332EOS
333
334 $test++;
335 push @script, <<EOS;
bf5f1b4c
JH
336 print "# make 3i\n";
337 \$z = Math::Complex->make('3i');
91cb744f
JH
338 print "not " unless \$z == cplx(0,3);
339 print "ok $test\n";
340EOS
341
342 $test++;
343 push @script, <<EOS;
bf5f1b4c
JH
344 print "# emake [2,3]\n";
345 \$z = Math::Complex->emake('[2,3]');
346 print "not " unless \$z == cplxe(2,3);
347 print "ok $test\n";
348EOS
349
350 $test++;
351 push @script, <<EOS;
352 print "# make (2,3)\n";
353 \$z = Math::Complex->make('(2,3)');
354 print "not " unless \$z == cplx(2,3);
355 print "ok $test\n";
356EOS
357
358 $test++;
359 push @script, <<EOS;
360 print "# emake [2,3pi/8]\n";
361 \$z = Math::Complex->emake('[2,3pi/8]');
362 print "not " unless \$z == cplxe(2,3*\$pi/8);
91cb744f
JH
363 print "ok $test\n";
364EOS
365
366 $test++;
367 push @script, <<EOS;
bf5f1b4c
JH
368 print "# emake [2]\n";
369 \$z = Math::Complex->emake('[2]');
91cb744f
JH
370 print "not " unless \$z == cplxe(2);
371 print "ok $test\n";
372EOS
373}
374
bf5f1b4c
JH
375sub test_no_args {
376 push @script, <<'EOS';
377{
378 print "# cplx, cplxe, make, emake without arguments\n";
379EOS
380
381 $test++;
382 push @script, <<EOS;
383 my \$z0 = cplx();
384 print ((\$z0->Re() == 0) ? "ok $test\n" : "not ok $test\n");
385EOS
386
387 $test++;
388 push @script, <<EOS;
389 print ((\$z0->Im() == 0) ? "ok $test\n" : "not ok $test\n");
390EOS
391
392 $test++;
393 push @script, <<EOS;
394 my \$z1 = cplxe();
395 print ((\$z1->rho() == 0) ? "ok $test\n" : "not ok $test\n");
396EOS
397
398 $test++;
399 push @script, <<EOS;
400 print ((\$z1->theta() == 0) ? "ok $test\n" : "not ok $test\n");
401EOS
402
403 $test++;
404 push @script, <<EOS;
405 my \$z2 = Math::Complex->make();
406 print ((\$z2->Re() == 0) ? "ok $test\n" : "not ok $test\n");
407EOS
408
409 $test++;
410 push @script, <<EOS;
411 print ((\$z2->Im() == 0) ? "ok $test\n" : "not ok $test\n");
412EOS
413
414 $test++;
415 push @script, <<EOS;
416 my \$z3 = Math::Complex->emake();
417 print ((\$z3->rho() == 0) ? "ok $test\n" : "not ok $test\n");
418EOS
419
420 $test++;
421 push @script, <<EOS;
422 print ((\$z3->theta() == 0) ? "ok $test\n" : "not ok $test\n");
423}
424EOS
425}
426
427sub test_atan2 {
428 push @script, <<'EOS';
429print "# atan2() with some real arguments\n";
430EOS
431 my @real = (-1, 0, 1);
432 for my $x (@real) {
433 for my $y (@real) {
434 next if $x == 0 && $y == 0;
435 $test++;
436 push @script, <<EOS;
437print ((Math::Complex::atan2($y, $x) == CORE::atan2($y, $x)) ? "ok $test\n" : "not ok $test\n");
438EOS
439 }
440 }
441 push @script, <<'EOS';
442 print "# atan2() with some complex arguments\n";
443EOS
444 $test++;
445 push @script, <<EOS;
446 print (abs(atan2(0, cplx(0, 1))) < $eps ? "ok $test\n" : "not ok $test\n");
447EOS
448 $test++;
449 push @script, <<EOS;
450 print (abs(atan2(cplx(0, 1), 0) - \$pip2) < $eps ? "ok $test\n" : "not ok $test\n");
451EOS
452 $test++;
453 push @script, <<EOS;
454 print (abs(atan2(cplx(0, 1), cplx(0, 1)) - \$pip4) < $eps ? "ok $test\n" : "not ok $test\n");
455EOS
456 $test++;
457 push @script, <<EOS;
458 print (abs(atan2(cplx(0, 1), cplx(1, 1)) - cplx(0.553574358897045, 0.402359478108525)) < $eps ? "ok $test\n" : "not ok $test\n");
459EOS
460}
461
462sub test_decplx {
463}
464
91cb744f
JH
465test_remake();
466
bf5f1b4c
JH
467test_no_args();
468
469test_atan2();
470
471test_decplx();
472
89d0527d 473print "1..$test\n";
bf5f1b4c 474#print @script, "\n";
fe82cf6e 475eval join '', @script;
89d0527d
RM
476die $@ if $@;
477
0e505df1
JH
478sub abop {
479 my ($op) = @_;
480
481 push(@script, qq(print "# $op=\n";));
482}
483
89d0527d
RM
484sub test {
485 my ($op, $z, @args) = @_;
0e505df1 486 my ($baop) = 0;
89d0527d
RM
487 $test++;
488 my $i;
0e505df1 489 $baop = 1 if ($op =~ s/;=$//);
89d0527d
RM
490 for ($i = 0; $i < @args; $i++) {
491 $val = value($args[$i]);
fe82cf6e 492 push @script, "\$z$i = $val;\n";
89d0527d
RM
493 }
494 if (defined $z) {
495 $args = "'$op'"; # Really the value
0c721ce2 496 $try = "abs(\$z0 - \$z1) <= $eps ? \$z1 : \$z0";
fe82cf6e
CS
497 push @script, "\$res = $try; ";
498 push @script, "check($test, $args[0], \$res, \$z$#args, $args);\n";
89d0527d
RM
499 } else {
500 my ($try, $args);
501 if (@args == 2) {
502 $try = "$op \$z0";
503 $args = "'$args[0]'";
504 } else {
505 $try = ($op =~ /^\w/) ? "$op(\$z0, \$z1)" : "\$z0 $op \$z1";
506 $args = "'$args[0]', '$args[1]'";
507 }
fe82cf6e
CS
508 push @script, "\$res = $try; ";
509 push @script, "check($test, '$try', \$res, \$z$#args, $args);\n";
0e505df1
JH
510 if (@args > 2 and $baop) { # binary assignment ops
511 $test++;
512 # check the op= works
513 push @script, <<EOB;
514{
affad850 515 my \$za = cplx(ref \$z0 ? \@{\$z0->_cartesian} : (\$z0, 0));
0e505df1 516
affad850 517 my (\$z1r, \$z1i) = ref \$z1 ? \@{\$z1->_cartesian} : (\$z1, 0);
0e505df1 518
fb73857a 519 my \$zb = cplx(\$z1r, \$z1i);
0e505df1
JH
520
521 \$za $op= \$zb;
affad850 522 my (\$zbr, \$zbi) = \@{\$zb->_cartesian};
0e505df1
JH
523
524 check($test, '\$z0 $op= \$z1', \$za, \$z$#args, $args);
525EOB
526 $test++;
527 # check that the rhs has not changed
528 push @script, qq(print "not " unless (\$zbr == \$z1r and \$zbi == \$z1i););
b42d0ec9 529 push @script, qq(print "ok $test\\n";\n);
0e505df1
JH
530 push @script, "}\n";
531 }
89d0527d
RM
532 }
533}
534
535sub set {
536 my ($set, $setref, $valref) = @_;
537 @{$setref} = ();
538 @{$valref} = ();
539 my @set = split(/;\s*/, $set);
540 my @res;
541 my $i;
542 for ($i = 0; $i < @set; $i++) {
543 push(@{$valref}, $set[$i]);
544 my $val = value($set[$i]);
fe82cf6e
CS
545 push @script, "\$s$i = $val;\n";
546 push @{$setref}, "\$s$i";
89d0527d
RM
547 }
548}
549
550sub value {
551 local ($_) = @_;
552 if (/^\s*\((.*),(.*)\)/) {
553 return "cplx($1,$2)";
554 }
b42d0ec9
JH
555 elsif (/^\s*([\-\+]?(?:\d+(\.\d+)?|\.\d+)(?:[e[\-\+]\d+])?)/) {
556 return "cplx($1,0)";
557 }
89d0527d
RM
558 elsif (/^\s*\[(.*),(.*)\]/) {
559 return "cplxe($1,$2)";
560 }
561 elsif (/^\s*'(.*)'/) {
562 my $ex = $1;
563 $ex =~ s/\bz\b/$target/g;
564 $ex =~ s/\br\b/abs($target)/g;
565 $ex =~ s/\bt\b/arg($target)/g;
566 $ex =~ s/\ba\b/Re($target)/g;
567 $ex =~ s/\bb\b/Im($target)/g;
568 return $ex;
569 }
570 elsif (/^\s*"(.*)"/) {
571 return "\"$1\"";
572 }
573 return $_;
574}
575
576sub check {
577 my ($test, $try, $got, $expected, @z) = @_;
0c721ce2 578
16357284 579 print "# @_\n";
0c721ce2
JH
580
581 if ("$got" eq "$expected"
582 ||
583 ($expected =~ /^-?\d/ && $got == $expected)
584 ||
bf5f1b4c
JH
585 (abs(Math::Complex->make($got) - Math::Complex->make($expected)) < $eps)
586 ||
0c721ce2
JH
587 (abs($got - $expected) < $eps)
588 ) {
89d0527d
RM
589 print "ok $test\n";
590 } else {
591 print "not ok $test\n";
592 my $args = (@z == 1) ? "z = $z[0]" : "z0 = $z[0], z1 = $z[1]";
593 print "# '$try' expected: '$expected' got: '$got' for $args\n";
594 }
595}
fb73857a
PP
596
597sub addsq {
598 my ($z1, $z2) = @_;
599 return ($z1 + i*$z2) * ($z1 - i*$z2);
600}
601
602sub subsq {
603 my ($z1, $z2) = @_;
604 return ($z1 + $z2) * ($z1 - $z2);
605}
606
89d0527d 607__END__
0e505df1 608&+;=
89d0527d
RM
609(3,4):(3,4):(6,8)
610(-3,4):(3,-4):(0,0)
611(3,4):-3:(0,4)
6121:(4,2):(5,2)
613[2,0]:[2,pi]:(0,0)
614
615&++
616(2,1):(3,1)
617
0e505df1 618&-;=
89d0527d
RM
619(2,3):(-2,-3)
620[2,pi/2]:[2,-(pi)/2]
6212:[2,0]:(0,0)
622[3,0]:2:(1,0)
6233:(4,5):(-1,-5)
624(4,5):3:(1,5)
0e505df1 625(2,1):(3,5):(-1,-4)
89d0527d
RM
626
627&--
628(1,2):(0,2)
629[2,pi]:[3,pi]
630
0e505df1 631&*;=
89d0527d
RM
632(0,1):(0,1):(-1,0)
633(4,5):(1,0):(4,5)
634[2,2*pi/3]:(1,0):[2,2*pi/3]
6352:(0,1):(0,2)
636(0,1):3:(0,3)
637(0,1):(4,1):(-1,4)
638(2,1):(4,-1):(9,2)
639
0e505df1 640&/;=
89d0527d
RM
641(3,4):(3,4):(1,0)
642(4,-5):1:(4,-5)
6431:(0,1):(0,-1)
644(0,6):(0,2):(3,0)
645(9,2):(4,-1):(2,1)
646[4,pi]:[2,pi/2]:[2,pi/2]
647[2,pi/2]:[4,pi]:[0.5,-(pi)/2]
648
0e505df1
JH
649&**;=
650(2,0):(3,0):(8,0)
651(3,0):(2,0):(9,0)
652(2,3):(4,0):(-119,-120)
ace5de91
GS
653(0,0):(1,0):(0,0)
654(0,0):(2,3):(0,0)
655(1,0):(0,0):(1,0)
656(1,0):(1,0):(1,0)
657(1,0):(2,3):(1,0)
658(2,3):(0,0):(1,0)
659(2,3):(1,0):(2,3)
2820d885 660(0,0):(0,0):(1,0)
0e505df1 661
0c721ce2
JH
662&Re
663(3,4):3
664(-3,4):-3
665[1,pi/2]:0
666
667&Im
668(3,4):4
669(3,-4):-4
670[1,pi/2]:1
671
89d0527d
RM
672&abs
673(3,4):5
674(-3,4):5
675
0c721ce2
JH
676&arg
677[2,0]:0
678[-2,0]:pi
679
89d0527d
RM
680&~
681(4,5):(4,-5)
682(-3,4):(-3,-4)
683[2,pi/2]:[2,-(pi)/2]
684
685&<
686(3,4):(1,2):0
687(3,4):(3,2):0
688(3,4):(3,8):1
689(4,4):(5,129):1
690
691&==
692(3,4):(4,5):0
693(3,4):(3,5):0
694(3,4):(2,4):0
695(3,4):(3,4):1
696
697&sqrt
0c721ce2 698-9:(0,3)
89d0527d
RM
699(-100,0):(0,10)
700(16,-30):(5,-3)
701
affad850 702&_stringify_cartesian
89d0527d
RM
703(-100,0):"-100"
704(0,1):"i"
705(4,-3):"4-3i"
706(4,0):"4"
707(-4,0):"-4"
708(-2,4):"-2+4i"
709(-2,-1):"-2-i"
710
affad850 711&_stringify_polar
89d0527d
RM
712[-1, 0]:"[1,pi]"
713[1, pi/3]:"[1,pi/3]"
714[6, -2*pi/3]:"[6,-2pi/3]"
715[0.5, -9*pi/11]:"[0.5,-9pi/11]"
3194a40a 716[1, 0.5]:"[1, 0.5]"
89d0527d
RM
717
718{ (4,3); [3,2]; (-3,4); (0,2); [2,1] }
719
720|'z + ~z':'2*Re(z)'
721|'z - ~z':'2*i*Im(z)'
722|'z * ~z':'abs(z) * abs(z)'
723
8c03c583 724{ (0.5, 0); (-0.5, 0); (2,3); [3,2]; (-3,2); (0,2); 3; 1.2; (-3, 0); (-2, -1); [2,1] }
89d0527d 725
0c721ce2
JH
726|'(root(z, 4))[1] ** 4':'z'
727|'(root(z, 5))[3] ** 5':'z'
728|'(root(z, 8))[7] ** 8':'z'
bf5f1b4c
JH
729|'(root(z, 8, 0)) ** 8':'z'
730|'(root(z, 8, 7)) ** 8':'z'
89d0527d 731|'abs(z)':'r'
0c721ce2
JH
732|'acot(z)':'acotan(z)'
733|'acsc(z)':'acosec(z)'
fb73857a
PP
734|'acsc(z)':'asin(1 / z)'
735|'asec(z)':'acos(1 / z)'
89d0527d 736|'cbrt(z)':'cbrt(r) * exp(i * t/3)'
89d0527d 737|'cos(acos(z))':'z'
fb73857a 738|'addsq(cos(z), sin(z))':1
89d0527d 739|'cos(z)':'cosh(i*z)'
fb73857a 740|'subsq(cosh(z), sinh(z))':1
0c721ce2
JH
741|'cot(acot(z))':'z'
742|'cot(z)':'1 / tan(z)'
743|'cot(z)':'cotan(z)'
744|'csc(acsc(z))':'z'
745|'csc(z)':'1 / sin(z)'
746|'csc(z)':'cosec(z)'
89d0527d 747|'exp(log(z))':'z'
0c721ce2
JH
748|'exp(z)':'exp(a) * exp(i * b)'
749|'ln(z)':'log(z)'
750|'log(exp(z))':'z'
751|'log(z)':'log(r) + i*t'
89d0527d 752|'log10(z)':'log(z) / log(10)'
89d0527d 753|'logn(z, 2)':'log(z) / log(2)'
0c721ce2
JH
754|'logn(z, 3)':'log(z) / log(3)'
755|'sec(asec(z))':'z'
756|'sec(z)':'1 / cos(z)'
757|'sin(asin(z))':'z'
758|'sin(i * z)':'i * sinh(z)'
759|'sqrt(z) * sqrt(z)':'z'
760|'sqrt(z)':'sqrt(r) * exp(i * t/2)'
761|'tan(atan(z))':'z'
762|'z**z':'exp(z * log(z))'
89d0527d 763
0c721ce2 764{ (1,1); [1,0.5]; (-2, -1); 2; -3; (-1,0.5); (0,0.5); 0.5; (2, 0); (-1, -2) }
89d0527d 765
89d0527d 766|'cosh(acosh(z))':'z'
0c721ce2
JH
767|'coth(acoth(z))':'z'
768|'coth(z)':'1 / tanh(z)'
769|'coth(z)':'cotanh(z)'
770|'csch(acsch(z))':'z'
771|'csch(z)':'1 / sinh(z)'
772|'csch(z)':'cosech(z)'
773|'sech(asech(z))':'z'
774|'sech(z)':'1 / cosh(z)'
775|'sinh(asinh(z))':'z'
89d0527d 776|'tanh(atanh(z))':'z'
89d0527d 777
0c721ce2 778{ (0.2,-0.4); [1,0.5]; -1.2; (-1,0.5); 0.5; (1.1, 0) }
89d0527d 779
89d0527d 780|'acos(cos(z)) ** 2':'z * z'
89d0527d 781|'acosh(cosh(z)) ** 2':'z * z'
0c721ce2
JH
782|'acoth(z)':'acotanh(z)'
783|'acoth(z)':'atanh(1 / z)'
784|'acsch(z)':'acosech(z)'
785|'acsch(z)':'asinh(1 / z)'
786|'asech(z)':'acosh(1 / z)'
787|'asin(sin(z))':'z'
788|'asinh(sinh(z))':'z'
789|'atan(tan(z))':'z'
89d0527d
RM
790|'atanh(tanh(z))':'z'
791
fb73857a
PP
792&log
793(-2.0,0):( 0.69314718055995, 3.14159265358979)
794(-1.0,0):( 0 , 3.14159265358979)
795(-0.5,0):( -0.69314718055995, 3.14159265358979)
796( 0.5,0):( -0.69314718055995, 0 )
797( 1.0,0):( 0 , 0 )
798( 2.0,0):( 0.69314718055995, 0 )
799
800&log
801( 2, 3):( 1.28247467873077, 0.98279372324733)
802(-2, 3):( 1.28247467873077, 2.15879893034246)
803(-2,-3):( 1.28247467873077, -2.15879893034246)
804( 2,-3):( 1.28247467873077, -0.98279372324733)
805
0c721ce2 806&sin
8c03c583
JH
807(-2.0,0):( -0.90929742682568, 0 )
808(-1.0,0):( -0.84147098480790, 0 )
809(-0.5,0):( -0.47942553860420, 0 )
810( 0.0,0):( 0 , 0 )
811( 0.5,0):( 0.47942553860420, 0 )
812( 1.0,0):( 0.84147098480790, 0 )
813( 2.0,0):( 0.90929742682568, 0 )
814
815&sin
0c721ce2
JH
816( 2, 3):( 9.15449914691143, -4.16890695996656)
817(-2, 3):( -9.15449914691143, -4.16890695996656)
818(-2,-3):( -9.15449914691143, 4.16890695996656)
819( 2,-3):( 9.15449914691143, 4.16890695996656)
820
821&cos
8c03c583
JH
822(-2.0,0):( -0.41614683654714, 0 )
823(-1.0,0):( 0.54030230586814, 0 )
824(-0.5,0):( 0.87758256189037, 0 )
825( 0.0,0):( 1 , 0 )
826( 0.5,0):( 0.87758256189037, 0 )
827( 1.0,0):( 0.54030230586814, 0 )
828( 2.0,0):( -0.41614683654714, 0 )
829
830&cos
0c721ce2
JH
831( 2, 3):( -4.18962569096881, -9.10922789375534)
832(-2, 3):( -4.18962569096881, 9.10922789375534)
833(-2,-3):( -4.18962569096881, -9.10922789375534)
834( 2,-3):( -4.18962569096881, 9.10922789375534)
835
836&tan
8c03c583
JH
837(-2.0,0):( 2.18503986326152, 0 )
838(-1.0,0):( -1.55740772465490, 0 )
839(-0.5,0):( -0.54630248984379, 0 )
840( 0.0,0):( 0 , 0 )
841( 0.5,0):( 0.54630248984379, 0 )
842( 1.0,0):( 1.55740772465490, 0 )
843( 2.0,0):( -2.18503986326152, 0 )
844
845&tan
0c721ce2
JH
846( 2, 3):( -0.00376402564150, 1.00323862735361)
847(-2, 3):( 0.00376402564150, 1.00323862735361)
848(-2,-3):( 0.00376402564150, -1.00323862735361)
849( 2,-3):( -0.00376402564150, -1.00323862735361)
850
851&sec
8c03c583
JH
852(-2.0,0):( -2.40299796172238, 0 )
853(-1.0,0):( 1.85081571768093, 0 )
854(-0.5,0):( 1.13949392732455, 0 )
855( 0.0,0):( 1 , 0 )
856( 0.5,0):( 1.13949392732455, 0 )
857( 1.0,0):( 1.85081571768093, 0 )
858( 2.0,0):( -2.40299796172238, 0 )
859
860&sec
0c721ce2
JH
861( 2, 3):( -0.04167496441114, 0.09061113719624)
862(-2, 3):( -0.04167496441114, -0.09061113719624)
863(-2,-3):( -0.04167496441114, 0.09061113719624)
864( 2,-3):( -0.04167496441114, -0.09061113719624)
865
866&csc
8c03c583
JH
867(-2.0,0):( -1.09975017029462, 0 )
868(-1.0,0):( -1.18839510577812, 0 )
869(-0.5,0):( -2.08582964293349, 0 )
870( 0.5,0):( 2.08582964293349, 0 )
871( 1.0,0):( 1.18839510577812, 0 )
872( 2.0,0):( 1.09975017029462, 0 )
873
874&csc
0c721ce2
JH
875( 2, 3):( 0.09047320975321, 0.04120098628857)
876(-2, 3):( -0.09047320975321, 0.04120098628857)
877(-2,-3):( -0.09047320975321, -0.04120098628857)
878( 2,-3):( 0.09047320975321, -0.04120098628857)
879
880&cot
8c03c583
JH
881(-2.0,0):( 0.45765755436029, 0 )
882(-1.0,0):( -0.64209261593433, 0 )
883(-0.5,0):( -1.83048772171245, 0 )
884( 0.5,0):( 1.83048772171245, 0 )
885( 1.0,0):( 0.64209261593433, 0 )
886( 2.0,0):( -0.45765755436029, 0 )
887
888&cot
0c721ce2
JH
889( 2, 3):( -0.00373971037634, -0.99675779656936)
890(-2, 3):( 0.00373971037634, -0.99675779656936)
891(-2,-3):( 0.00373971037634, 0.99675779656936)
892( 2,-3):( -0.00373971037634, 0.99675779656936)
893
894&asin
8c03c583
JH
895(-2.0,0):( -1.57079632679490, 1.31695789692482)
896(-1.0,0):( -1.57079632679490, 0 )
897(-0.5,0):( -0.52359877559830, 0 )
898( 0.0,0):( 0 , 0 )
899( 0.5,0):( 0.52359877559830, 0 )
900( 1.0,0):( 1.57079632679490, 0 )
901( 2.0,0):( 1.57079632679490, -1.31695789692482)
902
903&asin
0c721ce2
JH
904( 2, 3):( 0.57065278432110, 1.98338702991654)
905(-2, 3):( -0.57065278432110, 1.98338702991654)
906(-2,-3):( -0.57065278432110, -1.98338702991654)
907( 2,-3):( 0.57065278432110, -1.98338702991654)
908
909&acos
8c03c583
JH
910(-2.0,0):( 3.14159265358979, -1.31695789692482)
911(-1.0,0):( 3.14159265358979, 0 )
912(-0.5,0):( 2.09439510239320, 0 )
913( 0.0,0):( 1.57079632679490, 0 )
914( 0.5,0):( 1.04719755119660, 0 )
915( 1.0,0):( 0 , 0 )
916( 2.0,0):( 0 , 1.31695789692482)
917
918&acos
0c721ce2
JH
919( 2, 3):( 1.00014354247380, -1.98338702991654)
920(-2, 3):( 2.14144911111600, -1.98338702991654)
921(-2,-3):( 2.14144911111600, 1.98338702991654)
922( 2,-3):( 1.00014354247380, 1.98338702991654)
923
924&atan
8c03c583
JH
925(-2.0,0):( -1.10714871779409, 0 )
926(-1.0,0):( -0.78539816339745, 0 )
927(-0.5,0):( -0.46364760900081, 0 )
928( 0.0,0):( 0 , 0 )
929( 0.5,0):( 0.46364760900081, 0 )
930( 1.0,0):( 0.78539816339745, 0 )
931( 2.0,0):( 1.10714871779409, 0 )
932
933&atan
0c721ce2
JH
934( 2, 3):( 1.40992104959658, 0.22907268296854)
935(-2, 3):( -1.40992104959658, 0.22907268296854)
936(-2,-3):( -1.40992104959658, -0.22907268296854)
937( 2,-3):( 1.40992104959658, -0.22907268296854)
938
939&asec
8c03c583
JH
940(-2.0,0):( 2.09439510239320, 0 )
941(-1.0,0):( 3.14159265358979, 0 )
942(-0.5,0):( 3.14159265358979, -1.31695789692482)
943( 0.5,0):( 0 , 1.31695789692482)
944( 1.0,0):( 0 , 0 )
945( 2.0,0):( 1.04719755119660, 0 )
946
947&asec
0c721ce2
JH
948( 2, 3):( 1.42041072246703, 0.23133469857397)
949(-2, 3):( 1.72118193112276, 0.23133469857397)
950(-2,-3):( 1.72118193112276, -0.23133469857397)
951( 2,-3):( 1.42041072246703, -0.23133469857397)
952
953&acsc
8c03c583
JH
954(-2.0,0):( -0.52359877559830, 0 )
955(-1.0,0):( -1.57079632679490, 0 )
956(-0.5,0):( -1.57079632679490, 1.31695789692482)
957( 0.5,0):( 1.57079632679490, -1.31695789692482)
958( 1.0,0):( 1.57079632679490, 0 )
959( 2.0,0):( 0.52359877559830, 0 )
960
961&acsc
0c721ce2
JH
962( 2, 3):( 0.15038560432786, -0.23133469857397)
963(-2, 3):( -0.15038560432786, -0.23133469857397)
964(-2,-3):( -0.15038560432786, 0.23133469857397)
965( 2,-3):( 0.15038560432786, 0.23133469857397)
966
967&acot
8c03c583
JH
968(-2.0,0):( -0.46364760900081, 0 )
969(-1.0,0):( -0.78539816339745, 0 )
970(-0.5,0):( -1.10714871779409, 0 )
971( 0.5,0):( 1.10714871779409, 0 )
972( 1.0,0):( 0.78539816339745, 0 )
973( 2.0,0):( 0.46364760900081, 0 )
974
975&acot
0c721ce2
JH
976( 2, 3):( 0.16087527719832, -0.22907268296854)
977(-2, 3):( -0.16087527719832, -0.22907268296854)
978(-2,-3):( -0.16087527719832, 0.22907268296854)
979( 2,-3):( 0.16087527719832, 0.22907268296854)
980
981&sinh
8c03c583
JH
982(-2.0,0):( -3.62686040784702, 0 )
983(-1.0,0):( -1.17520119364380, 0 )
984(-0.5,0):( -0.52109530549375, 0 )
985( 0.0,0):( 0 , 0 )
986( 0.5,0):( 0.52109530549375, 0 )
987( 1.0,0):( 1.17520119364380, 0 )
988( 2.0,0):( 3.62686040784702, 0 )
989
990&sinh
0c721ce2
JH
991( 2, 3):( -3.59056458998578, 0.53092108624852)
992(-2, 3):( 3.59056458998578, 0.53092108624852)
993(-2,-3):( 3.59056458998578, -0.53092108624852)
994( 2,-3):( -3.59056458998578, -0.53092108624852)
995
996&cosh
8c03c583
JH
997(-2.0,0):( 3.76219569108363, 0 )
998(-1.0,0):( 1.54308063481524, 0 )
999(-0.5,0):( 1.12762596520638, 0 )
1000( 0.0,0):( 1 , 0 )
1001( 0.5,0):( 1.12762596520638, 0 )
1002( 1.0,0):( 1.54308063481524, 0 )
1003( 2.0,0):( 3.76219569108363, 0 )
1004
1005&cosh
0c721ce2
JH
1006( 2, 3):( -3.72454550491532, 0.51182256998738)
1007(-2, 3):( -3.72454550491532, -0.51182256998738)
1008(-2,-3):( -3.72454550491532, 0.51182256998738)
1009( 2,-3):( -3.72454550491532, -0.51182256998738)
1010
1011&tanh
8c03c583
JH
1012(-2.0,0):( -0.96402758007582, 0 )
1013(-1.0,0):( -0.76159415595576, 0 )
1014(-0.5,0):( -0.46211715726001, 0 )
1015( 0.0,0):( 0 , 0 )
1016( 0.5,0):( 0.46211715726001, 0 )
1017( 1.0,0):( 0.76159415595576, 0 )
1018( 2.0,0):( 0.96402758007582, 0 )
1019
1020&tanh
0c721ce2
JH
1021( 2, 3):( 0.96538587902213, -0.00988437503832)
1022(-2, 3):( -0.96538587902213, -0.00988437503832)
1023(-2,-3):( -0.96538587902213, 0.00988437503832)
1024( 2,-3):( 0.96538587902213, 0.00988437503832)
1025
1026&sech
8c03c583
JH
1027(-2.0,0):( 0.26580222883408, 0 )
1028(-1.0,0):( 0.64805427366389, 0 )
1029(-0.5,0):( 0.88681888397007, 0 )
1030( 0.0,0):( 1 , 0 )
1031( 0.5,0):( 0.88681888397007, 0 )
1032( 1.0,0):( 0.64805427366389, 0 )
1033( 2.0,0):( 0.26580222883408, 0 )
1034
1035&sech
0c721ce2
JH
1036( 2, 3):( -0.26351297515839, -0.03621163655877)
1037(-2, 3):( -0.26351297515839, 0.03621163655877)
1038(-2,-3):( -0.26351297515839, -0.03621163655877)
1039( 2,-3):( -0.26351297515839, 0.03621163655877)
1040
1041&csch
8c03c583
JH
1042(-2.0,0):( -0.27572056477178, 0 )
1043(-1.0,0):( -0.85091812823932, 0 )
1044(-0.5,0):( -1.91903475133494, 0 )
1045( 0.5,0):( 1.91903475133494, 0 )
1046( 1.0,0):( 0.85091812823932, 0 )
1047( 2.0,0):( 0.27572056477178, 0 )
1048
1049&csch
0c721ce2
JH
1050( 2, 3):( -0.27254866146294, -0.04030057885689)
1051(-2, 3):( 0.27254866146294, -0.04030057885689)
1052(-2,-3):( 0.27254866146294, 0.04030057885689)
1053( 2,-3):( -0.27254866146294, 0.04030057885689)
1054
1055&coth
8c03c583
JH
1056(-2.0,0):( -1.03731472072755, 0 )
1057(-1.0,0):( -1.31303528549933, 0 )
1058(-0.5,0):( -2.16395341373865, 0 )
1059( 0.5,0):( 2.16395341373865, 0 )
1060( 1.0,0):( 1.31303528549933, 0 )
1061( 2.0,0):( 1.03731472072755, 0 )
1062
1063&coth
0c721ce2
JH
1064( 2, 3):( 1.03574663776500, 0.01060478347034)
1065(-2, 3):( -1.03574663776500, 0.01060478347034)
1066(-2,-3):( -1.03574663776500, -0.01060478347034)
1067( 2,-3):( 1.03574663776500, -0.01060478347034)
1068
1069&asinh
8c03c583
JH
1070(-2.0,0):( -1.44363547517881, 0 )
1071(-1.0,0):( -0.88137358701954, 0 )
1072(-0.5,0):( -0.48121182505960, 0 )
1073( 0.0,0):( 0 , 0 )
1074( 0.5,0):( 0.48121182505960, 0 )
1075( 1.0,0):( 0.88137358701954, 0 )
1076( 2.0,0):( 1.44363547517881, 0 )
1077
1078&asinh
0c721ce2
JH
1079( 2, 3):( 1.96863792579310, 0.96465850440760)
1080(-2, 3):( -1.96863792579310, 0.96465850440761)
1081(-2,-3):( -1.96863792579310, -0.96465850440761)
1082( 2,-3):( 1.96863792579310, -0.96465850440760)
1083
1084&acosh
9bc5fa8d 1085(-2.0,0):( 1.31695789692482, 3.14159265358979)
8c03c583
JH
1086(-1.0,0):( 0, 3.14159265358979)
1087(-0.5,0):( 0, 2.09439510239320)
1088( 0.0,0):( 0, 1.57079632679490)
1089( 0.5,0):( 0, 1.04719755119660)
1090( 1.0,0):( 0 , 0 )
1091( 2.0,0):( 1.31695789692482, 0 )
1092
1093&acosh
0c721ce2 1094( 2, 3):( 1.98338702991654, 1.00014354247380)
9bc5fa8d
JH
1095(-2, 3):( 1.98338702991653, 2.14144911111600)
1096(-2,-3):( 1.98338702991653, -2.14144911111600)
0c721ce2
JH
1097( 2,-3):( 1.98338702991654, -1.00014354247380)
1098
1099&atanh
8c03c583
JH
1100(-2.0,0):( -0.54930614433405, 1.57079632679490)
1101(-0.5,0):( -0.54930614433405, 0 )
1102( 0.0,0):( 0 , 0 )
1103( 0.5,0):( 0.54930614433405, 0 )
1104( 2.0,0):( 0.54930614433405, 1.57079632679490)
1105
1106&atanh
0c721ce2
JH
1107( 2, 3):( 0.14694666622553, 1.33897252229449)
1108(-2, 3):( -0.14694666622553, 1.33897252229449)
1109(-2,-3):( -0.14694666622553, -1.33897252229449)
1110( 2,-3):( 0.14694666622553, -1.33897252229449)
1111
1112&asech
8c03c583
JH
1113(-2.0,0):( 0 , 2.09439510239320)
1114(-1.0,0):( 0 , 3.14159265358979)
9bc5fa8d 1115(-0.5,0):( 1.31695789692482, 3.14159265358979)
8c03c583
JH
1116( 0.5,0):( 1.31695789692482, 0 )
1117( 1.0,0):( 0 , 0 )
1118( 2.0,0):( 0 , 1.04719755119660)
1119
1120&asech
0c721ce2 1121( 2, 3):( 0.23133469857397, -1.42041072246703)
9bc5fa8d
JH
1122(-2, 3):( 0.23133469857397, -1.72118193112276)
1123(-2,-3):( 0.23133469857397, 1.72118193112276)
0c721ce2
JH
1124( 2,-3):( 0.23133469857397, 1.42041072246703)
1125
1126&acsch
8c03c583
JH
1127(-2.0,0):( -0.48121182505960, 0 )
1128(-1.0,0):( -0.88137358701954, 0 )
1129(-0.5,0):( -1.44363547517881, 0 )
1130( 0.5,0):( 1.44363547517881, 0 )
1131( 1.0,0):( 0.88137358701954, 0 )
1132( 2.0,0):( 0.48121182505960, 0 )
1133
1134&acsch
0c721ce2
JH
1135( 2, 3):( 0.15735549884499, -0.22996290237721)
1136(-2, 3):( -0.15735549884499, -0.22996290237721)
1137(-2,-3):( -0.15735549884499, 0.22996290237721)
1138( 2,-3):( 0.15735549884499, 0.22996290237721)
1139
1140&acoth
8c03c583
JH
1141(-2.0,0):( -0.54930614433405, 0 )
1142(-0.5,0):( -0.54930614433405, 1.57079632679490)
1143( 0.5,0):( 0.54930614433405, 1.57079632679490)
1144( 2.0,0):( 0.54930614433405, 0 )
1145
1146&acoth
0c721ce2
JH
1147( 2, 3):( 0.14694666622553, -0.23182380450040)
1148(-2, 3):( -0.14694666622553, -0.23182380450040)
1149(-2,-3):( -0.14694666622553, 0.23182380450040)
1150( 2,-3):( 0.14694666622553, 0.23182380450040)
1151
1152# eof