2 # Copyright (C) 2001-2009, Parrot Foundation.
7 t/pmc/complex.t - Complex Numbers
11 % prove t/pmc/complex.t
15 Tests the Complex PMC.
20 .include 'test_more.pir'
21 .include 'fp_equality.pasm'
22 .include "iglobals.pasm"
27 exception_malformed_string__real_part()
28 exception_malformed_string__imaginary_part()
29 exception_malformed_string__missing_plus_or_minus()
31 test_complex_subtract()
32 test_complex_multiply()
34 complex_divide_by_zero_Complex()
35 complex_divide_by_zero_Float()
36 complex_divide_by_zero_Integer()
37 get_int_or_num_or_bool()
39 exception_get_keyed__invalid_string_key()
40 exception_get_keyed__invalid_numeric_key()
43 exception_set_keyed__invalid_key()
46 check_whether_interface_is_done()
47 instantiate__pasm__i()
55 sprintf_with_a_complex()
56 pow_with_complex_numbers()
57 e_raised_pi_time_i__plus_1_equal_0()
58 ln_of_complex_numbers()
59 exp_of_complex_numbers()
60 sqrt_of_complex_numbers()
61 sin_of_complex_numbers()
62 cos_of_complex_numbers()
63 tan_of_complex_numbers()
64 cot_of_complex_numbers()
65 sec_of_complex_numbers()
66 csc_of_complex_numbers()
67 asin_of_complex_numbers()
68 acos_of_complex_numbers()
69 atan_of_complex_numbers()
70 acot_of_complex_numbers()
71 asec_of_complex_numbers()
72 acsc_of_complex_numbers()
73 sinh_of_complex_numbers()
74 cosh_of_complex_numbers()
75 tanh_of_complex_numbers()
76 coth_of_complex_numbers()
77 sech_of_complex_numbers()
78 csch_of_complex_numbers()
79 add_using_subclass_of_complex_bug_59630()
85 .macro exception_is( M )
88 .get_results (exception)
90 message = exception['message']
99 is( $P0, "4+0i", '"4" parsed as 4+0i' )
102 is( $P0, "3.14+0i", '"3.14" parsed as 3.14+0i' )
105 is( $P0, "0.5+0i", '".5" parsed as 0.5+0i' )
108 is( $P0, "-13+0i", '"-13" parsed as -13+0i' )
111 is( $P0, "-0.3+0i", '"-.3" parsed as -0.3+0i' )
114 is( $P0, "0+1i", '"i" parsed as 0+1i' )
117 is( $P0, "0-1i", '"-i" parsed as 0-1i' )
120 is( $P0, "0+0.3i", '".3i" parsed as 0+0.3i' )
123 is( $P0, "2+3i", '"2 + 3i" parsed as 2+3i' )
126 is( $P0, "4+3.5i", '"4 + 3.5i" parsed as 4+3.5i' )
129 is( $P0, "2+0.1i", '"2 + .1 i" parsed as 2+0.1i' )
132 is( $P0, "10-1i", '"10 - i" parsed as 10-1i' )
135 is( $P0, "5-0.3i", '"5 - .3i" parsed as 5-0.3i' )
139 is( $P0, "-4-1i", '"-4-i" parsed as -4-1i' )
141 set $P1, "- 20 - .5 i"
143 is( $P0, "-20-0.5i", '"- 20 - .5 i" parsed as -20-0.5i' )
147 is( $P0, "-13+2i", '"-13 +2i" parsed as -13+2i' )
150 .sub exception_malformed_string__real_part
151 $P0 = new ['Complex']
156 .exception_is( "Complex: malformed string" )
159 .sub exception_malformed_string__imaginary_part
160 $P0 = new ['Complex']
165 .exception_is( "Complex: malformed string" )
168 .sub exception_malformed_string__missing_plus_or_minus
169 $P0 = new ['Complex']
174 .exception_is( "Complex: malformed string" )
177 .sub test_complex_add
178 $P0 = new ['Complex']
179 $P1 = new ['Complex']
181 $P3 = new ['Integer']
185 is( $P0, "2+2i", '1+i plus 1+i' )
190 is( $P0, "2+0i", '1-i plus 1+i' )
191 is( $P1, "1+1i", '1+i as text is 1+1i' )
196 is( $P0, "0-1i", '-i as text is 0-1i' )
197 is( $P1, "1-1i", '-i plus 1 is 1-1i' )
202 is( $P1, "5.3+1i", '2+i plus 3.3 is 5.3+1i' )
206 is( $P1, "5+5i", '3+5i plus literal 2 is 5+5i' )
210 is( $P1, "0+2i", '2+2i plus literal -2.0 is 0+2i' )
215 is( $P1, "0+3i", '3+3i plus -3 is 0+3i' )
217 is( $P1, "0+3i", '-2 plus 3+3i is 0+3i' )
220 .sub test_complex_subtract
221 $P0 = new ['Complex']
222 $P1 = new ['Complex']
224 $P3 = new ['Integer']
228 is( $P0, "0+0i", '1+i minus 1+i is 0+0i' )
233 is( $P0, "0-2i", '1-i minus 1+i is 0-2i' )
234 is( $P1, "1+1i", '... original $3 is unchanged' )
239 is( $P0, "0-1i", '-i minus 1 is 0-1i' )
240 is( $P1, "-1-1i", '... original $3 is unchanged' )
245 is( $P1, "2-4i", '1-4i minus -1.0 is 2-4i' )
249 is( $P1, "2-2i", '-2-2i minus -4 is 2-2i' )
253 is( $P1, "1.8+1i", '3+i - literal 1.2 is 1.8+1i' )
258 is( $P1, "-1024-3i", '1024-3i minus 2048 is -1024-3i' )
260 is( $P1, "1024+3i", '2048 minus 1024-3i is 1024+3i' )
263 .sub test_complex_multiply
264 $P0 = new ['Complex']
265 $P1 = new ['Complex']
267 $P3 = new ['Integer']
271 is( $P0, "-5+12i", '2+3i x 2+3i = -5+12i' )
276 is( $P0, "29+0i", '5-2i x 5+2i = 29+0i' )
277 is( $P1, "5+2i", '... original $3 is unchanged' )
282 is( $P0, "0+3i", '3i x 2-i = 0+3i' )
283 is( $P1, "3+6i", '... original $3 is unchanged' )
288 is( $P1, "1-1i", '2-2i x 0.5 = 1-1i' )
292 is( $P1, "2-2i", '1-i x literal 2 = 2-2i' )
296 is( $P1, "1-1i", '-1+i x literal -1.0 = 1-1i' )
301 is( $P1, "10+10i", '1+i x literal 10 = 10+10i' )
304 is( $P1, "10+10i", '10 x 1+i is 10+10i' )
307 .sub test_complex_divide
308 $P0 = new ['Complex']
309 $P1 = new ['Complex']
314 is( $P0, "1+0i", '2+3i / 2+3i = 1+0i' )
319 is( $P0, "0+1i", '3+5i / 5-3i = 0+1i' )
320 is( $P1, "5-3i", '... original $3 is unchanged' )
325 is( $P1, "3-4i", '25 / 3+4i = 3-4i' )
326 is( $P0, "25+0i", '... original $2 is unchanged' )
331 is( $P1, "-1+2i", '-3+6i / 3.0 = -1+2i' )
335 is( $P1, "-1+1.5i", '-2+3i / 2 = -1+1.5i' )
339 is( $P1, "4-6i", '2-3i / 0.5 = 4-6i' )
342 .sub complex_divide_by_zero_Complex
343 skip( 1, 'div by zero not caught' )
346 $P0 = new ['Complex']
348 $P1 = new ['Complex']
349 ## divide by a zero Complex
350 $P2 = new ['Complex']
356 .exception_is( 'Divide by zero' )
359 .sub complex_divide_by_zero_Float
360 skip( 1, 'div by zero not caught' )
363 $P0 = new ['Complex']
365 $P1 = new ['Complex']
366 ## divide by a zero Float
372 .exception_is( 'Divide by zero' )
375 .sub complex_divide_by_zero_Integer
376 skip( 1, 'div by zero not caught' )
379 $P0 = new ['Complex']
381 $P1 = new ['Complex']
382 ## divide by a zero Integer
383 $P2 = new ['Integer']
388 .exception_is( 'Divide by zero' )
391 .sub get_int_or_num_or_bool
392 $P0 = new ['Complex']
394 is( $P0, "2-1.5i", 'Complex "2 - 1.5i" returned ok' )
397 is( $I0, "2", 'Complex -> Int = 2' )
400 .fp_eq_ok( $N0, 2.5, 'Complex -> Num = 2.5')
402 ok( $P0, 'Complex(2-1.5i) -> bool = true' )
405 nok( $P0, 'Complex(0) -> bool = true' )
409 $P0 = new ['Complex']
411 set $P0, "- 3.3 + 1.2i"
417 .fp_eq_ok( $N0, -3.3, 'got real part')
418 .fp_eq_ok( $N1, 1.2, 'got imag part')
419 .fp_eq_ok( $N2, 1.2, 'got imag part using variable' )
423 is( $P2, "-3.3", 'get real portion of -3.3i1.2i' )
424 is( $P3, "1.2", 'get imag portion of -3.3+1.2i' )
428 is( $I0, "-3", 'get real portion -> Int' )
429 is( $I1, "1", 'get imag portion -> Int' )
432 .sub exception_get_keyed__invalid_string_key
433 $P0 = new ['Complex']
436 set $N0, $P0["Foo55"]
438 .exception_is( "Complex: key is neither 'real' or 'imag'" )
441 .sub exception_get_keyed__invalid_numeric_key
442 $P0 = new ['Complex']
447 .exception_is( "Complex: key must be 0 or 1" )
451 $P0 = new ['Complex']
455 is( $P0, "-2+0i", '-2 -> Complex = -2+0i' )
459 is( $P0, "0.4+0i", '.4 -> Complex = 0.4+0i' )
463 $P0 = new ['Complex']
470 is( $P0, "1+4i", 'set imag and real portion separately' )
473 set $P0["imag"], -2.3
474 is( $P0, "3.2-2.3i", '... again' )
480 is( $P0, "0.5+6i", '... now using String PMCs' )
483 .sub exception_set_keyed__invalid_key
484 $P0 = new ['Complex']
488 .exception_is( "Complex: key must be 0 or 1" )
492 $P0 = new ['Complex']
493 $P1 = new ['Complex']
499 is( $P0, $P1, 'create new Complex from real/imag and test eq' )
501 isnt( $P0, $P1, '... now make sure it ne to 0' )
504 .sub test_complex_abs
505 $P0 = new ['Complex']
509 is( $P1, "5", 'abs 4+3j -> 5' )
512 .sub check_whether_interface_is_done
514 pmc1 = new ['Complex']
517 does bool1, pmc1, "scalar"
518 ok( bool1, 'Comples does scalar' )
520 does bool1, pmc1, "no_interface"
521 nok( bool1, 'Comples !does no_interface' )
524 .sub instantiate__pasm__i
525 skip( 1, 'instantiate n/y' )
535 get_class $P2, "Complex"
537 is( $P1, "10+20i", 'instantiate pasm i' )
540 .sub instantiate__pir__n
541 skip( 1, 'instantiate n/y' )
544 $P0 = get_class "Complex"
545 # $P1 = $P0."instantiate"(2.0, 3.0)
546 is( $P1, "2+3i", 'instantiate pir n' )
549 .sub instantiate__pir__p
550 skip( 1, 'instantiate n/y' )
553 $P0 = get_class "Complex"
558 # $P1 = $P0."instantiate"($P1, $P2)
559 is( $P1, "2+3i", 'instantiate pir p' )
562 .sub instantiate__pir__s
563 skip( 1, 'instantiate n/y' )
566 $P0 = get_class "Complex"
567 # $P1 = $P0."instantiate"("2 + 3i")
568 is( $P1, "2+3i", 'instantiate pir s' )
571 .sub test_complex_neg
572 $P0 = new ['Complex']
573 set $P0, "1.3 + 1.7i"
574 $P1 = new ['Integer']
578 .fp_eq_ok($N0, -1.3, 'test complex negative')
579 .fp_eq_ok($N1, -1.7, '... and the imag port')
583 $P0 = new ['Complex']
586 is( $P0, $P1, 'clone Complex PMC')
591 .fp_eq_ok($N0, 1.0, 'no change to cloned after setting orig')
592 .fp_eq_ok($N1, -3.0, '... nor to imag portion')
603 is( d, "2.8+2i", '5+2j - 2.2 = 2.8+i (using d=c-f)' )
606 is( $S0, "Complex", 'd is typeof Complex' )
609 is( d, "-2.8-2i", '2.2 - 5+2j = -2.8-2i' )
612 is( $S0, "Complex", 'typeof still Complex' )
622 is( c, '2.8+2i', 'Complex -= test' )
626 is( f, '-2.8-2i', '... and reverse it' )
629 .macro sprintf_is(fmt, number, message)
631 $S0 = sprintf .fmt, c
636 .sub sprintf_with_a_complex
639 .sprintf_is( "%d%+di", "1.35+35.1i", "1+35i" )
640 .sprintf_is( "%.3f%+.3fi", "0+3.141592653589793i", "0.000+3.142i" )
641 .sprintf_is( "%.3f%+.3fi", "0+i", "0.000+1.000i" )
644 .macro pow_test_is(base, power, message)
648 $S0 = sprintf "%.6f%+.6fi", c3
653 .sub pow_with_complex_numbers
658 .pow_test_is( "i", "i", "0.207880+0.000000i" )
659 .pow_test_is( "i", "2", "-1.000000+0.000000i" )
660 .pow_test_is( "2i", "2", "-4.000000+0.000000i" )
661 .pow_test_is( "2+2i", "2+2i", "-1.452505-0.809890i" )
662 .pow_test_is( "i", "0.5i", "0.455938+0.000000i" )
663 .pow_test_is( 2, "2i", "0.183457+0.983028i" )
665 .pow_test_is( "2i", 2, "-4.000000+0.000000i" )
666 .pow_test_is( "2", 4, "16.000000+0.000000i" )
668 .pow_test_is( "2i", 0.5, "1.000000+1.000000i" )
671 .sub e_raised_pi_time_i__plus_1_equal_0
683 .sprintf_is( "%.3f%+.3fi", c2, "0.000+0.000i" )
686 # # The inverse hyperbolic functions are broken wrt -0.0
687 # # Need to find some formal spec for when to return -0.0.
689 .macro complex_op_is( val, res, op )
690 $P1 = new ['Complex']
691 $P2 = new ['Complex']
698 #XXX: can't do $P1.'$S2'()
700 $S3 = sprintf "%f%+fi", $P2
702 concat $S4, $S2, " of "
708 .macro complex_op_todo( val, res, op, todo )
709 $P1 = new ['Complex']
710 $P2 = new ['Complex']
718 #XXX: can't do $P1.'$S2'()
720 $S3 = sprintf "%f%+fi", $P2
722 concat $S5, $S2, " of "
725 $I0 = cmp_str $S1, $S3
731 .sub ln_of_complex_numbers
732 .complex_op_is("-2+0i", "0.693147+3.141593i", 'ln' )
733 .complex_op_is("-1+0i", "0.000000+3.141593i", 'ln' )
734 .complex_op_is("-0.5+0i", "-0.693147+3.141593i", 'ln' )
735 .complex_op_is("0.5+0i", "-0.693147+0.000000i", 'ln' )
736 .complex_op_is("1+0i", "0.000000+0.000000i", 'ln' )
737 .complex_op_is("2+0i", "0.693147+0.000000i", 'ln' )
738 .complex_op_is("0-2i", "0.693147-1.570796i", 'ln' )
739 .complex_op_is("0-1i", "0.000000-1.570796i", 'ln' )
740 .complex_op_is("0-0.5i", "-0.693147-1.570796i", 'ln' )
741 .complex_op_is("0+0.5i", "-0.693147+1.570796i", 'ln' )
742 .complex_op_is("0+1i", "0.000000+1.570796i", 'ln' )
743 .complex_op_is("0+2i", "0.693147+1.570796i", 'ln' )
745 skip(1, 'inf is not platform-independent' )
747 .complex_op_is("0+0i", "-inf+0.000000i", 'ln' )
749 .complex_op_is("2+3i", "1.282475+0.982794i", 'ln' )
750 .complex_op_is("2-3i", "1.282475-0.982794i", 'ln' )
751 .complex_op_is("-2+3i", "1.282475+2.158799i", 'ln' )
752 .complex_op_is("-2-3i", "1.282475-2.158799i", 'ln' )
755 .sub exp_of_complex_numbers
756 .complex_op_is( "-2+0i", "0.135335+0.000000i", 'exp' )
757 .complex_op_is( "-1+0i", "0.367879+0.000000i", 'exp' )
758 .complex_op_is( "-0.5+0i", "0.606531+0.000000i", 'exp' )
759 .complex_op_is( "0.5+0i", "1.648721+0.000000i", 'exp' )
760 .complex_op_is( "1+0i", "2.718282+0.000000i", 'exp' )
761 .complex_op_is( "2+0i", "7.389056+0.000000i", 'exp' )
762 .complex_op_is( "0-2i", "-0.416147-0.909297i", 'exp' )
763 .complex_op_is( "0-1i", "0.540302-0.841471i", 'exp' )
764 .complex_op_is( "0-0.5i", "0.877583-0.479426i", 'exp' )
765 .complex_op_is( "0+0.5i", "0.877583+0.479426i", 'exp' )
766 .complex_op_is( "0+1i", "0.540302+0.841471i", 'exp' )
767 .complex_op_is( "0+2i", "-0.416147+0.909297i", 'exp' )
768 .complex_op_is( "0+0i", "1.000000+0.000000i", 'exp' )
769 .complex_op_is( "2+3i", "-7.315110+1.042744i", 'exp' )
770 .complex_op_is( "2-3i", "-7.315110-1.042744i", 'exp' )
771 .complex_op_is( "-2+3i", "-0.133981+0.019099i", 'exp' )
772 .complex_op_is( "-2-3i", "-0.133981-0.019099i", 'exp' )
775 .sub sqrt_of_complex_numbers
776 .complex_op_is( "4", "2.000000+0.000000i", 'sqrt' )
777 .complex_op_is( "i", "0.707107+0.707107i", 'sqrt' )
778 .complex_op_is( "2i","1.000000+1.000000i", 'sqrt' )
779 .complex_op_is( "2+2i", "1.553774+0.643594i", 'sqrt' )
780 .complex_op_is( "1+i", "1.098684+0.455090i", 'sqrt' )
781 .complex_op_is( "-2+0i", "0.000000+1.414214i", 'sqrt' )
782 .complex_op_is( "-1+0i", "0.000000+1.000000i", 'sqrt' )
783 .complex_op_is( "-0.5+0i", "0.000000+0.707107i", 'sqrt' )
784 .complex_op_is( "0.5+0i", "0.707107+0.000000i", 'sqrt' )
785 .complex_op_is( "1+0i", "1.000000+0.000000i", 'sqrt' )
786 .complex_op_is( "2+0i", "1.414214+0.000000i", 'sqrt' )
787 .complex_op_is( "0-2i", "1.000000-1.000000i", 'sqrt' )
788 .complex_op_is( "0-1i", "0.707107-0.707107i", 'sqrt' )
789 .complex_op_is( "0-0.5i", "0.500000-0.500000i", 'sqrt' )
790 .complex_op_is( "0+0.5i", "0.500000+0.500000i", 'sqrt' )
791 .complex_op_is( "0+1i", "0.707107+0.707107i", 'sqrt' )
792 .complex_op_is( "0+2i", "1.000000+1.000000i", 'sqrt' )
793 .complex_op_is( "0+0i", "0.000000+0.000000i", 'sqrt' )
794 .complex_op_is( "2+3i", "1.674149+0.895977i", 'sqrt' )
795 .complex_op_is( "2-3i", "1.674149-0.895977i", 'sqrt' )
796 .complex_op_is( "-2+3i", "0.895977+1.674149i", 'sqrt' )
797 .complex_op_is( "-2-3i", "0.895977-1.674149i", 'sqrt' )
800 .sub sin_of_complex_numbers
801 .complex_op_is("-2+0i", "-0.909297+0.000000i", 'sin' )
802 .complex_op_is("-1+0i", "-0.841471+0.000000i", 'sin' )
803 .complex_op_is("-0.5+0i", "-0.479426+0.000000i", 'sin' )
804 .complex_op_is("0.5+0i", "0.479426+0.000000i", 'sin' )
805 .complex_op_is("1+0i", "0.841471+0.000000i", 'sin' )
806 .complex_op_is("2+0i", "0.909297+0.000000i", 'sin' )
807 .complex_op_is("0-2i", "0.000000-3.626860i", 'sin' )
808 .complex_op_is("0-1i", "0.000000-1.175201i", 'sin' )
809 .complex_op_is("0-0.5i", "0.000000-0.521095i", 'sin' )
810 .complex_op_is("0+0.5i", "0.000000+0.521095i", 'sin' )
811 .complex_op_is("0+1i", "0.000000+1.175201i", 'sin' )
812 .complex_op_is("0+2i", "0.000000+3.626860i", 'sin' )
813 .complex_op_is("0+0i", "0.000000+0.000000i", 'sin' )
814 .complex_op_is("2+3i", "9.154499-4.168907i", 'sin' )
815 .complex_op_is("2-3i", "9.154499+4.168907i", 'sin' )
816 .complex_op_is("-2+3i", "-9.154499-4.168907i", 'sin' )
817 .complex_op_is("-2-3i", "-9.154499+4.168907i", 'sin' )
820 .sub cos_of_complex_numbers
821 .complex_op_is("-2+0i", "-0.416147+0.000000i", 'cos' )
822 .complex_op_is("-1+0i", "0.540302+0.000000i", 'cos' )
823 .complex_op_is("-0.5+0i", "0.877583+0.000000i", 'cos' )
824 .complex_op_is("0.5+0i", "0.877583+0.000000i", 'cos' )
825 .complex_op_is("1+0i", "0.540302+0.000000i", 'cos' )
826 .complex_op_is("2+0i", "-0.416147+0.000000i", 'cos' )
827 .complex_op_is("0-2i", "3.762196+0.000000i", 'cos' )
828 .complex_op_is("0-1i", "1.543081+0.000000i", 'cos' )
829 .complex_op_is("0-0.5i", "1.127626+0.000000i", 'cos' )
830 .complex_op_is("0+0.5i", "1.127626+0.000000i", 'cos' )
831 .complex_op_is("0+1i", "1.543081+0.000000i", 'cos' )
832 .complex_op_is("0+2i", "3.762196+0.000000i", 'cos' )
833 .complex_op_is("0+0i", "1.000000+0.000000i", 'cos' )
834 .complex_op_is("2+3i", "-4.189626-9.109228i", 'cos' )
835 .complex_op_is("2-3i", "-4.189626+9.109228i", 'cos' )
836 .complex_op_is("-2+3i", "-4.189626+9.109228i", 'cos' )
837 .complex_op_is("-2-3i", "-4.189626-9.109228i", 'cos' )
840 .sub tan_of_complex_numbers
841 .complex_op_is("-2+0i", "2.185040+0.000000i", 'tan' )
842 .complex_op_is("-1+0i", "-1.557408+0.000000i", 'tan' )
843 .complex_op_is("-0.5+0i", "-0.546302+0.000000i", 'tan' )
844 .complex_op_is("0.5+0i", "0.546302+0.000000i", 'tan' )
845 .complex_op_is("1+0i", "1.557408+0.000000i", 'tan' )
846 .complex_op_is("2+0i", "-2.185040+0.000000i", 'tan' )
847 .complex_op_is("0-2i", "0.000000-0.964028i", 'tan' )
848 .complex_op_is("0-1i", "0.000000-0.761594i", 'tan' )
849 .complex_op_is("0-0.5i", "0.000000-0.462117i", 'tan' )
850 .complex_op_is("0+0.5i", "0.000000+0.462117i", 'tan' )
851 .complex_op_is("0+1i", "0.000000+0.761594i", 'tan' )
852 .complex_op_is("0+2i", "0.000000+0.964028i", 'tan' )
853 .complex_op_is("0+0i", "0.000000+0.000000i", 'tan' )
854 .complex_op_is("2+3i", "-0.003764+1.003239i", 'tan' )
855 .complex_op_is("2-3i", "-0.003764-1.003239i", 'tan' )
856 .complex_op_is("-2+3i", "0.003764+1.003239i", 'tan' )
857 .complex_op_is("-2-3i", "0.003764-1.003239i", 'tan' )
860 .sub cot_of_complex_numbers
861 .complex_op_is("-2+0i", "0.457658+0.000000i", 'cot' )
862 .complex_op_is("-1+0i", "-0.642093+0.000000i", 'cot' )
863 .complex_op_is("-0.5+0i", "-1.830488+0.000000i", 'cot' )
864 .complex_op_is("0.5+0i", "1.830488+0.000000i", 'cot' )
865 .complex_op_is("1+0i", "0.642093+0.000000i", 'cot' )
866 .complex_op_is("2+0i", "-0.457658+0.000000i", 'cot' )
867 .complex_op_is("0-2i", "0.000000+1.037315i", 'cot' )
868 .complex_op_is("0-1i", "0.000000+1.313035i", 'cot' )
869 .complex_op_is("0-0.5i", "0.000000+2.163953i", 'cot' )
870 .complex_op_is("0+0.5i", "0.000000-2.163953i", 'cot' )
871 .complex_op_is("0+1i", "0.000000-1.313035i", 'cot' )
872 .complex_op_is("0+2i", "0.000000-1.037315i", 'cot' )
873 .complex_op_is("2+3i", "-0.003740-0.996758i", 'cot' )
874 .complex_op_is("2-3i", "-0.003740+0.996758i", 'cot' )
875 .complex_op_is("-2+3i", "0.003740-0.996758i", 'cot' )
876 .complex_op_is("-2-3i", "0.003740+0.996758i", 'cot' )
879 .sub sec_of_complex_numbers
880 .complex_op_is("-2+0i", "-2.402998+0.000000i", 'sec' )
881 .complex_op_is("-1+0i", "1.850816+0.000000i", 'sec' )
882 .complex_op_is("-0.5+0i", "1.139494+0.000000i", 'sec' )
883 .complex_op_is("0.5+0i", "1.139494+0.000000i", 'sec' )
884 .complex_op_is("1+0i", "1.850816+0.000000i", 'sec' )
885 .complex_op_is("2+0i", "-2.402998+0.000000i", 'sec' )
886 .complex_op_is("0-2i", "0.265802+0.000000i", 'sec' )
887 .complex_op_is("0-1i", "0.648054+0.000000i", 'sec' )
888 .complex_op_is("0-0.5i", "0.886819+0.000000i", 'sec' )
889 .complex_op_is("0+0.5i", "0.886819+0.000000i", 'sec' )
890 .complex_op_is("0+1i", "0.648054+0.000000i", 'sec' )
891 .complex_op_is("0+2i", "0.265802+0.000000i", 'sec' )
892 .complex_op_is("0+0i", "1.000000+0.000000i", 'sec' )
893 .complex_op_is("2+3i", "-0.041675+0.090611i", 'sec' )
894 .complex_op_is("2-3i", "-0.041675-0.090611i", 'sec' )
895 .complex_op_is("-2+3i", "-0.041675-0.090611i", 'sec' )
896 .complex_op_is("-2-3i", "-0.041675+0.090611i", 'sec' )
899 .sub csc_of_complex_numbers
900 .complex_op_is("-2+0i", "-1.099750+0.000000i", 'csc' )
901 .complex_op_is("-1+0i", "-1.188395+0.000000i", 'csc' )
902 .complex_op_is("-0.5+0i", "-2.085830+0.000000i", 'csc' )
903 .complex_op_is("0.5+0i", "2.085830+0.000000i", 'csc' )
904 .complex_op_is("1+0i", "1.188395+0.000000i", 'csc' )
905 .complex_op_is("2+0i", "1.099750+0.000000i", 'csc' )
906 .complex_op_is("0-2i", "0.000000+0.275721i", 'csc' )
907 .complex_op_is("0-1i", "0.000000+0.850918i", 'csc' )
908 .complex_op_is("0-0.5i", "0.000000+1.919035i", 'csc' )
909 .complex_op_is("0+0.5i", "0.000000-1.919035i", 'csc' )
910 .complex_op_is("0+1i", "0.000000-0.850918i", 'csc' )
911 .complex_op_is("0+2i", "0.000000-0.275721i", 'csc' )
912 .complex_op_is("2+3i", "0.090473+0.041201i", 'csc' )
913 .complex_op_is("2-3i", "0.090473-0.041201i", 'csc' )
914 .complex_op_is("-2+3i", "-0.090473+0.041201i", 'csc' )
915 .complex_op_is("-2-3i", "-0.090473-0.041201i", 'csc' )
918 .sub asin_of_complex_numbers
919 .complex_op_is("-2+0i", "-1.570796+1.316958i", 'asin' )
920 .complex_op_is("-1+0i", "-1.570796+0.000000i", 'asin' )
921 .complex_op_is("-0.5+0i", "-0.523599+0.000000i", 'asin' )
922 .complex_op_is("0.5+0i", "0.523599+0.000000i", 'asin' )
923 .complex_op_is("1+0i", "1.570796+0.000000i", 'asin' )
924 .complex_op_is("2+0i", "1.570796-1.316958i", 'asin' )
925 .complex_op_is("0-2i", "0.000000-1.443635i", 'asin' )
926 .complex_op_is("0-1i", "0.000000-0.881374i", 'asin' )
927 .complex_op_is("0-0.5i", "0.000000-0.481212i", 'asin' )
928 .complex_op_is("0+0.5i", "0.000000+0.481212i", 'asin' )
929 .complex_op_is("0+1i", "0.000000+0.881374i", 'asin' )
930 .complex_op_is("0+2i", "0.000000+1.443635i", 'asin' )
931 .complex_op_is("0+0i", "0.000000+0.000000i", 'asin' )
932 .complex_op_is("2+3i", "0.570653+1.983387i", 'asin' )
933 .complex_op_is("2-3i", "0.570653-1.983387i", 'asin' )
934 .complex_op_is("-2+3i", "-0.570653+1.983387i", 'asin' )
935 .complex_op_is("-2-3i", "-0.570653-1.983387i", 'asin' )
938 .sub acos_of_complex_numbers
939 .complex_op_is("-2+0i", "3.141593-1.316958i", 'acos' )
940 .complex_op_is("-1+0i", "3.141593+0.000000i", 'acos' )
941 .complex_op_is("-0.5+0i", "2.094395+0.000000i", 'acos' )
942 .complex_op_is("0.5+0i", "1.047198+0.000000i", 'acos' )
943 .complex_op_is("1+0i", "0.000000+0.000000i", 'acos' )
944 .complex_op_is("2+0i", "0.000000+1.316958i", 'acos' )
945 .complex_op_is("0-2i", "1.570796+1.443635i", 'acos' )
946 .complex_op_is("0-1i", "1.570796+0.881374i", 'acos' )
947 .complex_op_is("0-0.5i", "1.570796+0.481212i", 'acos' )
948 .complex_op_is("0+0.5i", "1.570796-0.481212i", 'acos' )
949 .complex_op_is("0+1i", "1.570796-0.881374i", 'acos' )
950 .complex_op_is("0+2i", "1.570796-1.443635i", 'acos' )
951 .complex_op_is("0+0i", "1.570796+0.000000i", 'acos' )
952 .complex_op_is("2+3i", "1.000144-1.983387i", 'acos' )
953 .complex_op_is("2-3i", "1.000144+1.983387i", 'acos' )
954 .complex_op_is("-2+3i", "2.141449-1.983387i", 'acos' )
955 .complex_op_is("-2-3i", "2.141449+1.983387i", 'acos' )
958 .sub atan_of_complex_numbers
959 .complex_op_is("-2+0i", "-1.107149+0.000000i", 'atan' )
960 .complex_op_is("-1+0i", "-0.785398+0.000000i", 'atan' )
961 .complex_op_is("-0.5+0i", "-0.463648+0.000000i", 'atan' )
962 .complex_op_is("0.5+0i", "0.463648+0.000000i", 'atan' )
963 .complex_op_is("1+0i", "0.785398+0.000000i", 'atan' )
964 .complex_op_is("2+0i", "1.107149+0.000000i", 'atan' )
965 .complex_op_is("0-2i", "-1.570796-0.549306i", 'atan' )
966 .complex_op_is("0-0.5i", "0.000000-0.549306i", 'atan' )
967 .complex_op_is("0+0.5i", "0.000000+0.549306i", 'atan' )
968 .complex_op_is("0+2i", "-1.570796+0.549306i", 'atan' )
969 .complex_op_is("0+0i", "0.000000+0.000000i", 'atan' )
970 .complex_op_is("2+3i", "1.409921+0.229073i", 'atan' )
971 .complex_op_is("2-3i", "1.409921-0.229073i", 'atan' )
972 .complex_op_is("-2+3i", "-1.409921+0.229073i", 'atan' )
973 .complex_op_is("-2-3i", "-1.409921-0.229073i", 'atan' )
976 .sub acot_of_complex_numbers
977 .complex_op_is("-2+0i", "-0.463648+0.000000i", 'acot' )
978 .complex_op_is("-1+0i", "-0.785398+0.000000i", 'acot' )
979 .complex_op_is("-0.5+0i", "-1.107149+0.000000i", 'acot' )
980 .complex_op_is("0.5+0i", "1.107149+0.000000i", 'acot' )
981 .complex_op_is("1+0i", "0.785398+0.000000i", 'acot' )
982 .complex_op_is("2+0i", "0.463648+0.000000i", 'acot' )
983 .complex_op_is("0-2i", "0.000000+0.549306i", 'acot' )
984 .complex_op_is("0-0.5i", "-1.570796+0.549306i", 'acot' )
985 .complex_op_is("0+0.5i", "-1.570796-0.549306i", 'acot' )
986 .complex_op_is("0+2i", "0.000000-0.549306i", 'acot' )
987 .complex_op_is("2+3i", "0.160875-0.229073i", 'acot' )
988 .complex_op_is("2-3i", "0.160875+0.229073i", 'acot' )
989 .complex_op_is("-2+3i", "-0.160875-0.229073i", 'acot' )
990 .complex_op_is("-2-3i", "-0.160875+0.229073i", 'acot' )
993 .sub asec_of_complex_numbers
994 .complex_op_is("-2+0i", "2.094395+0.000000i", 'asec' )
995 .complex_op_is("-1+0i", "3.141593+0.000000i", 'asec' )
996 .complex_op_is("-0.5+0i", "3.141593-1.316958i", 'asec' )
997 .complex_op_is("0.5+0i", "0.000000+1.316958i", 'asec' )
998 .complex_op_is("1+0i", "0.000000+0.000000i", 'asec' )
999 .complex_op_is("2+0i", "1.047198+0.000000i", 'asec' )
1000 .complex_op_is("0-2i", "1.570796-0.481212i", 'asec' )
1001 .complex_op_is("0-1i", "1.570796-0.881374i", 'asec' )
1002 .complex_op_is("0-0.5i", "1.570796-1.443635i", 'asec' )
1003 .complex_op_is("0+0.5i", "1.570796+1.443635i", 'asec' )
1004 .complex_op_is("0+1i", "1.570796+0.881374i", 'asec' )
1005 .complex_op_is("0+2i", "1.570796+0.481212i", 'asec' )
1006 .complex_op_is("2+3i", "1.420411+0.231335i", 'asec' )
1007 .complex_op_is("2-3i", "1.420411-0.231335i", 'asec' )
1008 .complex_op_is("-2+3i", "1.721182+0.231335i", 'asec' )
1009 .complex_op_is("-2-3i", "1.721182-0.231335i", 'asec' )
1012 .sub acsc_of_complex_numbers
1013 .complex_op_is("-2+0i", "-0.523599+0.000000i", 'acsc' )
1014 .complex_op_is("-1+0i", "-1.570796+0.000000i", 'acsc' )
1015 .complex_op_is("-0.5+0i", "-1.570796+1.316958i", 'acsc' )
1016 .complex_op_is("0.5+0i", "1.570796-1.316958i", 'acsc' )
1017 .complex_op_is("1+0i", "1.570796+0.000000i", 'acsc' )
1018 .complex_op_is("2+0i", "0.523599+0.000000i", 'acsc' )
1019 .complex_op_is("0-2i", "0.000000+0.481212i", 'acsc' )
1020 .complex_op_is("0-1i", "0.000000+0.881374i", 'acsc' )
1021 .complex_op_is("0-0.5i", "0.000000+1.443635i", 'acsc' )
1022 .complex_op_is("0+0.5i", "0.000000-1.443635i", 'acsc' )
1023 .complex_op_is("0+1i", "0.000000-0.881374i", 'acsc' )
1024 .complex_op_is("0+2i", "0.000000-0.481212i", 'acsc' )
1025 .complex_op_is("2+3i", "0.150386-0.231335i", 'acsc' )
1026 .complex_op_is("2-3i", "0.150386+0.231335i", 'acsc' )
1027 .complex_op_is("-2+3i", "-0.150386-0.231335i", 'acsc' )
1028 .complex_op_is("-2-3i", "-0.150386+0.231335i", 'acsc' )
1031 .sub sinh_of_complex_numbers
1032 .local pmc config_hash, interp
1033 .local string has_negative_zero
1035 config_hash = interp[.IGLOBALS_CONFIG_HASH]
1036 has_negative_zero = config_hash["has_negative_zero"]
1038 .complex_op_is("-2+0i", "-3.626860+0.000000i", 'sinh' )
1039 .complex_op_is("-1+0i", "-1.175201+0.000000i", 'sinh' )
1040 .complex_op_is("-0.5+0i", "-0.521095+0.000000i", 'sinh' )
1041 .complex_op_is("0.5+0i", "0.521095+0.000000i", 'sinh' )
1042 .complex_op_is("1+0i", "1.175201+0.000000i", 'sinh' )
1043 .complex_op_is("2+0i", "3.626860+0.000000i", 'sinh' )
1044 .complex_op_is("0-1i", "0.000000-0.841471i", 'sinh' )
1045 .complex_op_is("0-0.5i", "0.000000-0.479426i", 'sinh' )
1046 .complex_op_is("0+0.5i", "0.000000+0.479426i", 'sinh' )
1047 .complex_op_is("0+1i", "0.000000+0.841471i", 'sinh' )
1048 .complex_op_is("0+0i", "0.000000+0.000000i", 'sinh' )
1049 .complex_op_is("2+3i", "-3.590565+0.530921i", 'sinh' )
1050 .complex_op_is("2-3i", "-3.590565-0.530921i", 'sinh' )
1051 .complex_op_is("-2+3i", "3.590565+0.530921i", 'sinh' )
1052 .complex_op_is("-2-3i", "3.590565-0.530921i", 'sinh' )
1054 unless has_negative_zero goto todo
1055 .complex_op_is("0-2i", "-0.000000-0.909297i", 'sinh' )
1056 .complex_op_is("0+2i", "-0.000000+0.909297i", 'sinh' )
1060 .complex_op_todo("0-2i", "-0.000000-0.909297i", 'sinh', 'TT #313' )
1061 .complex_op_todo("0+2i", "-0.000000+0.909297i", 'sinh', 'TT #313' )
1065 .sub cosh_of_complex_numbers
1066 .complex_op_is("-2+0i", "3.762196+0.000000i", 'cosh' )
1067 .complex_op_is("-1+0i", "1.543081+0.000000i", 'cosh' )
1068 .complex_op_is("-0.5+0i", "1.127626+0.000000i", 'cosh' )
1069 .complex_op_is("0.5+0i", "1.127626+0.000000i", 'cosh' )
1070 .complex_op_is("1+0i", "1.543081+0.000000i", 'cosh' )
1071 .complex_op_is("2+0i", "3.762196+0.000000i", 'cosh' )
1072 .complex_op_is("0-2i", "-0.416147+0.000000i", 'cosh' )
1073 .complex_op_is("0-1i", "0.540302+0.000000i", 'cosh' )
1074 .complex_op_is("0-0.5i", "0.877583+0.000000i", 'cosh' )
1075 .complex_op_is("0+0.5i", "0.877583+0.000000i", 'cosh' )
1076 .complex_op_is("0+1i", "0.540302+0.000000i", 'cosh' )
1077 .complex_op_is("0+2i", "-0.416147+0.000000i", 'cosh' )
1078 .complex_op_is("0+0i", "1.000000+0.000000i", 'cosh' )
1079 .complex_op_is("2+3i", "-3.724546+0.511823i", 'cosh' )
1080 .complex_op_is("2-3i", "-3.724546-0.511823i", 'cosh' )
1081 .complex_op_is("-2+3i", "-3.724546-0.511823i", 'cosh' )
1082 .complex_op_is("-2-3i", "-3.724546+0.511823i", 'cosh' )
1085 .sub tanh_of_complex_numbers
1086 .complex_op_is("-2+0i", "-0.964028+0.000000i", 'tanh' )
1087 .complex_op_is("-1+0i", "-0.761594+0.000000i", 'tanh' )
1088 .complex_op_is("-0.5+0i", "-0.462117+0.000000i", 'tanh' )
1089 .complex_op_is("0.5+0i", "0.462117+0.000000i", 'tanh' )
1090 .complex_op_is("1+0i", "0.761594+0.000000i", 'tanh' )
1091 .complex_op_is("2+0i", "0.964028+0.000000i", 'tanh' )
1092 .complex_op_is("0-2i", "0.000000+2.185040i", 'tanh' )
1093 .complex_op_is("0-1i", "0.000000-1.557408i", 'tanh' )
1094 .complex_op_is("0-0.5i", "0.000000-0.546302i", 'tanh' )
1095 .complex_op_is("0+0.5i", "0.000000+0.546302i", 'tanh' )
1096 .complex_op_is("0+1i", "0.000000+1.557408i", 'tanh' )
1097 .complex_op_is("0+2i", "0.000000-2.185040i", 'tanh' )
1098 .complex_op_is("0+0i", "0.000000+0.000000i", 'tanh' )
1099 .complex_op_is("2+3i", "0.965386-0.009884i", 'tanh' )
1100 .complex_op_is("2-3i", "0.965386+0.009884i", 'tanh' )
1101 .complex_op_is("-2+3i", "-0.965386-0.009884i", 'tanh' )
1102 .complex_op_is("-2-3i", "-0.965386+0.009884i", 'tanh' )
1105 .sub coth_of_complex_numbers
1106 .complex_op_is("-2+0i", "-1.037315+0.000000i", 'coth' )
1107 .complex_op_is("-1+0i", "-1.313035+0.000000i", 'coth' )
1108 .complex_op_is("-0.5+0i", "-2.163953+0.000000i", 'coth' )
1109 .complex_op_is("0.5+0i", "2.163953+0.000000i", 'coth' )
1110 .complex_op_is("1+0i", "1.313035+0.000000i", 'coth' )
1111 .complex_op_is("2+0i", "1.037315+0.000000i", 'coth' )
1112 .complex_op_is("0-2i", "0.000000-0.457658i", 'coth' )
1113 .complex_op_is("0-1i", "0.000000+0.642093i", 'coth' )
1114 .complex_op_is("0-0.5i", "0.000000+1.830488i", 'coth' )
1115 .complex_op_is("0+0.5i", "0.000000-1.830488i", 'coth' )
1116 .complex_op_is("0+1i", "0.000000-0.642093i", 'coth' )
1117 .complex_op_is("0+2i", "0.000000+0.457658i", 'coth' )
1118 .complex_op_is("2+3i", "1.035747+0.010605i", 'coth' )
1119 .complex_op_is("2-3i", "1.035747-0.010605i", 'coth' )
1120 .complex_op_is("-2+3i", "-1.035747+0.010605i", 'coth' )
1121 .complex_op_is("-2-3i", "-1.035747-0.010605i", 'coth' )
1124 .sub sech_of_complex_numbers
1125 .complex_op_is("-2+0i", "0.265802+0.000000i", 'sech' )
1126 .complex_op_is("-1+0i", "0.648054+0.000000i", 'sech' )
1127 .complex_op_is("-0.5+0i", "0.886819+0.000000i", 'sech' )
1128 .complex_op_is("0.5+0i", "0.886819+0.000000i", 'sech' )
1129 .complex_op_is("1+0i", "0.648054+0.000000i", 'sech' )
1130 .complex_op_is("2+0i", "0.265802+0.000000i", 'sech' )
1131 .complex_op_is("0-2i", "-2.402998+0.000000i", 'sech' )
1132 .complex_op_is("0-1i", "1.850816+0.000000i", 'sech' )
1133 .complex_op_is("0-0.5i", "1.139494+0.000000i", 'sech' )
1134 .complex_op_is("0+0.5i", "1.139494+0.000000i", 'sech' )
1135 .complex_op_is("0+1i", "1.850816+0.000000i", 'sech' )
1136 .complex_op_is("0+2i", "-2.402998+0.000000i", 'sech' )
1137 .complex_op_is("0+0i", "1.000000+0.000000i", 'sech' )
1138 .complex_op_is("2+3i", "-0.263513-0.036212i", 'sech' )
1139 .complex_op_is("2-3i", "-0.263513+0.036212i", 'sech' )
1140 .complex_op_is("-2+3i", "-0.263513+0.036212i", 'sech' )
1141 .complex_op_is("-2-3i", "-0.263513-0.036212i", 'sech' )
1144 .sub csch_of_complex_numbers
1145 .complex_op_is("-2+0i", "-0.275721+0.000000i", 'csch' )
1146 .complex_op_is("-1+0i", "-0.850918+0.000000i", 'csch' )
1147 .complex_op_is("-0.5+0i", "-1.919035+0.000000i", 'csch' )
1148 .complex_op_is("0.5+0i", "1.919035+0.000000i", 'csch' )
1149 .complex_op_is("1+0i", "0.850918+0.000000i", 'csch' )
1150 .complex_op_is("2+0i", "0.275721+0.000000i", 'csch' )
1151 .complex_op_is("0-2i", "0.000000+1.099750i", 'csch' )
1152 .complex_op_is("0-1i", "0.000000+1.188395i", 'csch' )
1153 .complex_op_is("0-0.5i", "0.000000+2.085830i", 'csch' )
1154 .complex_op_is("0+0.5i", "0.000000-2.085830i", 'csch' )
1155 .complex_op_is("0+1i", "0.000000-1.188395i", 'csch' )
1156 .complex_op_is("0+2i", "0.000000-1.099750i", 'csch' )
1157 .complex_op_is("2+3i", "-0.272549-0.040301i", 'csch' )
1158 .complex_op_is("2-3i", "-0.272549+0.040301i", 'csch' )
1159 .complex_op_is("-2+3i", "0.272549-0.040301i", 'csch' )
1160 .complex_op_is("-2-3i", "0.272549+0.040301i", 'csch' )
1163 .sub add_using_subclass_of_complex_bug_59630
1164 skip( 3, 'add using subclass of Complex - RT #59630' )
1167 $P0 = subclass 'Complex', 'MyComplex'
1168 addattribute $P0, "re"
1169 addattribute $P0, "im"
1173 a = new ['MyComplex']
1179 b = new ['MyComplex']
1182 is( b, "3+4i" , '' )
1189 .namespace ['MyComplex']
1193 setattribute self, "re", $P1
1195 setattribute self, "im", $P2
1198 .namespace [] # revert to root for next test
1203 # cperl-indent-level: 4
1206 # vim: expandtab shiftwidth=4 filetype=pir: