2 # Copyright (C) 2001-2010, 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()
56 sprintf_with_a_complex()
57 ln_of_complex_numbers()
58 exp_of_complex_numbers()
59 sqrt_of_complex_numbers()
60 sin_of_complex_numbers()
61 cos_of_complex_numbers()
62 tan_of_complex_numbers()
63 cot_of_complex_numbers()
64 sec_of_complex_numbers()
65 csc_of_complex_numbers()
66 asin_of_complex_numbers()
67 acos_of_complex_numbers()
68 atan_of_complex_numbers()
69 acot_of_complex_numbers()
70 asec_of_complex_numbers()
71 acsc_of_complex_numbers()
72 sinh_of_complex_numbers()
73 cosh_of_complex_numbers()
74 tanh_of_complex_numbers()
75 coth_of_complex_numbers()
76 sech_of_complex_numbers()
77 csch_of_complex_numbers()
78 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, 'Complex does scalar' )
520 does bool1, pmc1, "no_interface"
521 nok( bool1, 'Complex !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')
595 .sub test_freeze_thaw
596 $P0 = new ['Complex']
600 is($P0, $P1, 'roundtrip serialize Complex PMC')
611 is( d, "2.8+2i", '5+2j - 2.2 = 2.8+i (using d=c-f)' )
614 is( $S0, "Complex", 'd is typeof Complex' )
617 is( d, "-2.8-2i", '2.2 - 5+2j = -2.8-2i' )
620 is( $S0, "Complex", 'typeof still Complex' )
630 is( c, '2.8+2i', 'Complex -= test' )
634 is( f, '-2.8-2i', '... and reverse it' )
637 .macro sprintf_is(fmt, number, message)
639 $S0 = sprintf .fmt, c
644 .sub sprintf_with_a_complex
647 .sprintf_is( "%d%+di", "1.35+35.1i", "1+35i" )
648 .sprintf_is( "%.3f%+.3fi", "0+3.141592653589793i", "0.000+3.142i" )
649 .sprintf_is( "%.3f%+.3fi", "0+i", "0.000+1.000i" )
652 # # The inverse hyperbolic functions are broken wrt -0.0
653 # # Need to find some formal spec for when to return -0.0.
655 .macro complex_op_is( val, res, op )
656 $P1 = new ['Complex']
657 $P2 = new ['Complex']
664 #XXX: can't do $P1.'$S2'()
666 $S3 = sprintf "%f%+fi", $P2
668 concat $S4, $S2, " of "
674 .macro complex_op_todo( val, res, op, todo )
675 $P1 = new ['Complex']
676 $P2 = new ['Complex']
684 #XXX: can't do $P1.'$S2'()
686 $S3 = sprintf "%f%+fi", $P2
688 concat $S5, $S2, " of "
695 .sub ln_of_complex_numbers
696 .complex_op_is("-2+0i", "0.693147+3.141593i", 'ln' )
697 .complex_op_is("-1+0i", "0.000000+3.141593i", 'ln' )
698 .complex_op_is("-0.5+0i", "-0.693147+3.141593i", 'ln' )
699 .complex_op_is("0.5+0i", "-0.693147+0.000000i", 'ln' )
700 .complex_op_is("1+0i", "0.000000+0.000000i", 'ln' )
701 .complex_op_is("2+0i", "0.693147+0.000000i", 'ln' )
702 .complex_op_is("0-2i", "0.693147-1.570796i", 'ln' )
703 .complex_op_is("0-1i", "0.000000-1.570796i", 'ln' )
704 .complex_op_is("0-0.5i", "-0.693147-1.570796i", 'ln' )
705 .complex_op_is("0+0.5i", "-0.693147+1.570796i", 'ln' )
706 .complex_op_is("0+1i", "0.000000+1.570796i", 'ln' )
707 .complex_op_is("0+2i", "0.693147+1.570796i", 'ln' )
709 skip(1, 'inf is not platform-independent' )
711 .complex_op_is("0+0i", "-inf+0.000000i", 'ln' )
713 .complex_op_is("2+3i", "1.282475+0.982794i", 'ln' )
714 .complex_op_is("2-3i", "1.282475-0.982794i", 'ln' )
715 .complex_op_is("-2+3i", "1.282475+2.158799i", 'ln' )
716 .complex_op_is("-2-3i", "1.282475-2.158799i", 'ln' )
719 .sub exp_of_complex_numbers
720 .complex_op_is( "-2+0i", "0.135335+0.000000i", 'exp' )
721 .complex_op_is( "-1+0i", "0.367879+0.000000i", 'exp' )
722 .complex_op_is( "-0.5+0i", "0.606531+0.000000i", 'exp' )
723 .complex_op_is( "0.5+0i", "1.648721+0.000000i", 'exp' )
724 .complex_op_is( "1+0i", "2.718282+0.000000i", 'exp' )
725 .complex_op_is( "2+0i", "7.389056+0.000000i", 'exp' )
726 .complex_op_is( "0-2i", "-0.416147-0.909297i", 'exp' )
727 .complex_op_is( "0-1i", "0.540302-0.841471i", 'exp' )
728 .complex_op_is( "0-0.5i", "0.877583-0.479426i", 'exp' )
729 .complex_op_is( "0+0.5i", "0.877583+0.479426i", 'exp' )
730 .complex_op_is( "0+1i", "0.540302+0.841471i", 'exp' )
731 .complex_op_is( "0+2i", "-0.416147+0.909297i", 'exp' )
732 .complex_op_is( "0+0i", "1.000000+0.000000i", 'exp' )
733 .complex_op_is( "2+3i", "-7.315110+1.042744i", 'exp' )
734 .complex_op_is( "2-3i", "-7.315110-1.042744i", 'exp' )
735 .complex_op_is( "-2+3i", "-0.133981+0.019099i", 'exp' )
736 .complex_op_is( "-2-3i", "-0.133981-0.019099i", 'exp' )
739 .sub sqrt_of_complex_numbers
740 .complex_op_is( "4", "2.000000+0.000000i", 'sqrt' )
741 .complex_op_is( "i", "0.707107+0.707107i", 'sqrt' )
742 .complex_op_is( "2i","1.000000+1.000000i", 'sqrt' )
743 .complex_op_is( "2+2i", "1.553774+0.643594i", 'sqrt' )
744 .complex_op_is( "1+i", "1.098684+0.455090i", 'sqrt' )
745 .complex_op_is( "-2+0i", "0.000000+1.414214i", 'sqrt' )
746 .complex_op_is( "-1+0i", "0.000000+1.000000i", 'sqrt' )
747 .complex_op_is( "-0.5+0i", "0.000000+0.707107i", 'sqrt' )
748 .complex_op_is( "0.5+0i", "0.707107+0.000000i", 'sqrt' )
749 .complex_op_is( "1+0i", "1.000000+0.000000i", 'sqrt' )
750 .complex_op_is( "2+0i", "1.414214+0.000000i", 'sqrt' )
751 .complex_op_is( "0-2i", "1.000000-1.000000i", 'sqrt' )
752 .complex_op_is( "0-1i", "0.707107-0.707107i", 'sqrt' )
753 .complex_op_is( "0-0.5i", "0.500000-0.500000i", 'sqrt' )
754 .complex_op_is( "0+0.5i", "0.500000+0.500000i", 'sqrt' )
755 .complex_op_is( "0+1i", "0.707107+0.707107i", 'sqrt' )
756 .complex_op_is( "0+2i", "1.000000+1.000000i", 'sqrt' )
757 .complex_op_is( "0+0i", "0.000000+0.000000i", 'sqrt' )
758 .complex_op_is( "2+3i", "1.674149+0.895977i", 'sqrt' )
759 .complex_op_is( "2-3i", "1.674149-0.895977i", 'sqrt' )
760 .complex_op_is( "-2+3i", "0.895977+1.674149i", 'sqrt' )
761 .complex_op_is( "-2-3i", "0.895977-1.674149i", 'sqrt' )
764 .sub sin_of_complex_numbers
765 .complex_op_is("-2+0i", "-0.909297+0.000000i", 'sin' )
766 .complex_op_is("-1+0i", "-0.841471+0.000000i", 'sin' )
767 .complex_op_is("-0.5+0i", "-0.479426+0.000000i", 'sin' )
768 .complex_op_is("0.5+0i", "0.479426+0.000000i", 'sin' )
769 .complex_op_is("1+0i", "0.841471+0.000000i", 'sin' )
770 .complex_op_is("2+0i", "0.909297+0.000000i", 'sin' )
771 .complex_op_is("0-2i", "0.000000-3.626860i", 'sin' )
772 .complex_op_is("0-1i", "0.000000-1.175201i", 'sin' )
773 .complex_op_is("0-0.5i", "0.000000-0.521095i", 'sin' )
774 .complex_op_is("0+0.5i", "0.000000+0.521095i", 'sin' )
775 .complex_op_is("0+1i", "0.000000+1.175201i", 'sin' )
776 .complex_op_is("0+2i", "0.000000+3.626860i", 'sin' )
777 .complex_op_is("0+0i", "0.000000+0.000000i", 'sin' )
778 .complex_op_is("2+3i", "9.154499-4.168907i", 'sin' )
779 .complex_op_is("2-3i", "9.154499+4.168907i", 'sin' )
780 .complex_op_is("-2+3i", "-9.154499-4.168907i", 'sin' )
781 .complex_op_is("-2-3i", "-9.154499+4.168907i", 'sin' )
784 .sub cos_of_complex_numbers
785 .complex_op_is("-2+0i", "-0.416147+0.000000i", 'cos' )
786 .complex_op_is("-1+0i", "0.540302+0.000000i", 'cos' )
787 .complex_op_is("-0.5+0i", "0.877583+0.000000i", 'cos' )
788 .complex_op_is("0.5+0i", "0.877583+0.000000i", 'cos' )
789 .complex_op_is("1+0i", "0.540302+0.000000i", 'cos' )
790 .complex_op_is("2+0i", "-0.416147+0.000000i", 'cos' )
791 .complex_op_is("0-2i", "3.762196+0.000000i", 'cos' )
792 .complex_op_is("0-1i", "1.543081+0.000000i", 'cos' )
793 .complex_op_is("0-0.5i", "1.127626+0.000000i", 'cos' )
794 .complex_op_is("0+0.5i", "1.127626+0.000000i", 'cos' )
795 .complex_op_is("0+1i", "1.543081+0.000000i", 'cos' )
796 .complex_op_is("0+2i", "3.762196+0.000000i", 'cos' )
797 .complex_op_is("0+0i", "1.000000+0.000000i", 'cos' )
798 .complex_op_is("2+3i", "-4.189626-9.109228i", 'cos' )
799 .complex_op_is("2-3i", "-4.189626+9.109228i", 'cos' )
800 .complex_op_is("-2+3i", "-4.189626+9.109228i", 'cos' )
801 .complex_op_is("-2-3i", "-4.189626-9.109228i", 'cos' )
804 .sub tan_of_complex_numbers
805 .complex_op_is("-2+0i", "2.185040+0.000000i", 'tan' )
806 .complex_op_is("-1+0i", "-1.557408+0.000000i", 'tan' )
807 .complex_op_is("-0.5+0i", "-0.546302+0.000000i", 'tan' )
808 .complex_op_is("0.5+0i", "0.546302+0.000000i", 'tan' )
809 .complex_op_is("1+0i", "1.557408+0.000000i", 'tan' )
810 .complex_op_is("2+0i", "-2.185040+0.000000i", 'tan' )
811 .complex_op_is("0-2i", "0.000000-0.964028i", 'tan' )
812 .complex_op_is("0-1i", "0.000000-0.761594i", 'tan' )
813 .complex_op_is("0-0.5i", "0.000000-0.462117i", 'tan' )
814 .complex_op_is("0+0.5i", "0.000000+0.462117i", 'tan' )
815 .complex_op_is("0+1i", "0.000000+0.761594i", 'tan' )
816 .complex_op_is("0+2i", "0.000000+0.964028i", 'tan' )
817 .complex_op_is("0+0i", "0.000000+0.000000i", 'tan' )
818 .complex_op_is("2+3i", "-0.003764+1.003239i", 'tan' )
819 .complex_op_is("2-3i", "-0.003764-1.003239i", 'tan' )
820 .complex_op_is("-2+3i", "0.003764+1.003239i", 'tan' )
821 .complex_op_is("-2-3i", "0.003764-1.003239i", 'tan' )
824 .sub cot_of_complex_numbers
825 .complex_op_is("-2+0i", "0.457658+0.000000i", 'cot' )
826 .complex_op_is("-1+0i", "-0.642093+0.000000i", 'cot' )
827 .complex_op_is("-0.5+0i", "-1.830488+0.000000i", 'cot' )
828 .complex_op_is("0.5+0i", "1.830488+0.000000i", 'cot' )
829 .complex_op_is("1+0i", "0.642093+0.000000i", 'cot' )
830 .complex_op_is("2+0i", "-0.457658+0.000000i", 'cot' )
831 .complex_op_is("0-2i", "0.000000+1.037315i", 'cot' )
832 .complex_op_is("0-1i", "0.000000+1.313035i", 'cot' )
833 .complex_op_is("0-0.5i", "0.000000+2.163953i", 'cot' )
834 .complex_op_is("0+0.5i", "0.000000-2.163953i", 'cot' )
835 .complex_op_is("0+1i", "0.000000-1.313035i", 'cot' )
836 .complex_op_is("0+2i", "0.000000-1.037315i", 'cot' )
837 .complex_op_is("2+3i", "-0.003740-0.996758i", 'cot' )
838 .complex_op_is("2-3i", "-0.003740+0.996758i", 'cot' )
839 .complex_op_is("-2+3i", "0.003740-0.996758i", 'cot' )
840 .complex_op_is("-2-3i", "0.003740+0.996758i", 'cot' )
843 .sub sec_of_complex_numbers
844 .complex_op_is("-2+0i", "-2.402998+0.000000i", 'sec' )
845 .complex_op_is("-1+0i", "1.850816+0.000000i", 'sec' )
846 .complex_op_is("-0.5+0i", "1.139494+0.000000i", 'sec' )
847 .complex_op_is("0.5+0i", "1.139494+0.000000i", 'sec' )
848 .complex_op_is("1+0i", "1.850816+0.000000i", 'sec' )
849 .complex_op_is("2+0i", "-2.402998+0.000000i", 'sec' )
850 .complex_op_is("0-2i", "0.265802+0.000000i", 'sec' )
851 .complex_op_is("0-1i", "0.648054+0.000000i", 'sec' )
852 .complex_op_is("0-0.5i", "0.886819+0.000000i", 'sec' )
853 .complex_op_is("0+0.5i", "0.886819+0.000000i", 'sec' )
854 .complex_op_is("0+1i", "0.648054+0.000000i", 'sec' )
855 .complex_op_is("0+2i", "0.265802+0.000000i", 'sec' )
856 .complex_op_is("0+0i", "1.000000+0.000000i", 'sec' )
857 .complex_op_is("2+3i", "-0.041675+0.090611i", 'sec' )
858 .complex_op_is("2-3i", "-0.041675-0.090611i", 'sec' )
859 .complex_op_is("-2+3i", "-0.041675-0.090611i", 'sec' )
860 .complex_op_is("-2-3i", "-0.041675+0.090611i", 'sec' )
863 .sub csc_of_complex_numbers
864 .complex_op_is("-2+0i", "-1.099750+0.000000i", 'csc' )
865 .complex_op_is("-1+0i", "-1.188395+0.000000i", 'csc' )
866 .complex_op_is("-0.5+0i", "-2.085830+0.000000i", 'csc' )
867 .complex_op_is("0.5+0i", "2.085830+0.000000i", 'csc' )
868 .complex_op_is("1+0i", "1.188395+0.000000i", 'csc' )
869 .complex_op_is("2+0i", "1.099750+0.000000i", 'csc' )
870 .complex_op_is("0-2i", "0.000000+0.275721i", 'csc' )
871 .complex_op_is("0-1i", "0.000000+0.850918i", 'csc' )
872 .complex_op_is("0-0.5i", "0.000000+1.919035i", 'csc' )
873 .complex_op_is("0+0.5i", "0.000000-1.919035i", 'csc' )
874 .complex_op_is("0+1i", "0.000000-0.850918i", 'csc' )
875 .complex_op_is("0+2i", "0.000000-0.275721i", 'csc' )
876 .complex_op_is("2+3i", "0.090473+0.041201i", 'csc' )
877 .complex_op_is("2-3i", "0.090473-0.041201i", 'csc' )
878 .complex_op_is("-2+3i", "-0.090473+0.041201i", 'csc' )
879 .complex_op_is("-2-3i", "-0.090473-0.041201i", 'csc' )
882 .sub asin_of_complex_numbers
883 .complex_op_is("-2+0i", "-1.570796+1.316958i", 'asin' )
884 .complex_op_is("-1+0i", "-1.570796+0.000000i", 'asin' )
885 .complex_op_is("-0.5+0i", "-0.523599+0.000000i", 'asin' )
886 .complex_op_is("0.5+0i", "0.523599+0.000000i", 'asin' )
887 .complex_op_is("1+0i", "1.570796+0.000000i", 'asin' )
888 .complex_op_is("2+0i", "1.570796-1.316958i", 'asin' )
889 .complex_op_is("0-2i", "0.000000-1.443635i", 'asin' )
890 .complex_op_is("0-1i", "0.000000-0.881374i", 'asin' )
891 .complex_op_is("0-0.5i", "0.000000-0.481212i", 'asin' )
892 .complex_op_is("0+0.5i", "0.000000+0.481212i", 'asin' )
893 .complex_op_is("0+1i", "0.000000+0.881374i", 'asin' )
894 .complex_op_is("0+2i", "0.000000+1.443635i", 'asin' )
895 .complex_op_is("0+0i", "0.000000+0.000000i", 'asin' )
896 .complex_op_is("2+3i", "0.570653+1.983387i", 'asin' )
897 .complex_op_is("2-3i", "0.570653-1.983387i", 'asin' )
898 .complex_op_is("-2+3i", "-0.570653+1.983387i", 'asin' )
899 .complex_op_is("-2-3i", "-0.570653-1.983387i", 'asin' )
902 .sub acos_of_complex_numbers
903 .complex_op_is("-2+0i", "3.141593-1.316958i", 'acos' )
904 .complex_op_is("-1+0i", "3.141593+0.000000i", 'acos' )
905 .complex_op_is("-0.5+0i", "2.094395+0.000000i", 'acos' )
906 .complex_op_is("0.5+0i", "1.047198+0.000000i", 'acos' )
907 .complex_op_is("1+0i", "0.000000+0.000000i", 'acos' )
908 .complex_op_is("2+0i", "0.000000+1.316958i", 'acos' )
909 .complex_op_is("0-2i", "1.570796+1.443635i", 'acos' )
910 .complex_op_is("0-1i", "1.570796+0.881374i", 'acos' )
911 .complex_op_is("0-0.5i", "1.570796+0.481212i", 'acos' )
912 .complex_op_is("0+0.5i", "1.570796-0.481212i", 'acos' )
913 .complex_op_is("0+1i", "1.570796-0.881374i", 'acos' )
914 .complex_op_is("0+2i", "1.570796-1.443635i", 'acos' )
915 .complex_op_is("0+0i", "1.570796+0.000000i", 'acos' )
916 .complex_op_is("2+3i", "1.000144-1.983387i", 'acos' )
917 .complex_op_is("2-3i", "1.000144+1.983387i", 'acos' )
918 .complex_op_is("-2+3i", "2.141449-1.983387i", 'acos' )
919 .complex_op_is("-2-3i", "2.141449+1.983387i", 'acos' )
922 .sub atan_of_complex_numbers
923 .complex_op_is("-2+0i", "-1.107149+0.000000i", 'atan' )
924 .complex_op_is("-1+0i", "-0.785398+0.000000i", 'atan' )
925 .complex_op_is("-0.5+0i", "-0.463648+0.000000i", 'atan' )
926 .complex_op_is("0.5+0i", "0.463648+0.000000i", 'atan' )
927 .complex_op_is("1+0i", "0.785398+0.000000i", 'atan' )
928 .complex_op_is("2+0i", "1.107149+0.000000i", 'atan' )
929 .complex_op_is("0-2i", "-1.570796-0.549306i", 'atan' )
930 .complex_op_is("0-0.5i", "0.000000-0.549306i", 'atan' )
931 .complex_op_is("0+0.5i", "0.000000+0.549306i", 'atan' )
932 .complex_op_is("0+2i", "-1.570796+0.549306i", 'atan' )
933 .complex_op_is("0+0i", "0.000000+0.000000i", 'atan' )
934 .complex_op_is("2+3i", "1.409921+0.229073i", 'atan' )
935 .complex_op_is("2-3i", "1.409921-0.229073i", 'atan' )
936 .complex_op_is("-2+3i", "-1.409921+0.229073i", 'atan' )
937 .complex_op_is("-2-3i", "-1.409921-0.229073i", 'atan' )
940 .sub acot_of_complex_numbers
941 .complex_op_is("-2+0i", "-0.463648+0.000000i", 'acot' )
942 .complex_op_is("-1+0i", "-0.785398+0.000000i", 'acot' )
943 .complex_op_is("-0.5+0i", "-1.107149+0.000000i", 'acot' )
944 .complex_op_is("0.5+0i", "1.107149+0.000000i", 'acot' )
945 .complex_op_is("1+0i", "0.785398+0.000000i", 'acot' )
946 .complex_op_is("2+0i", "0.463648+0.000000i", 'acot' )
947 .complex_op_is("0-2i", "0.000000+0.549306i", 'acot' )
948 .complex_op_is("0-0.5i", "-1.570796+0.549306i", 'acot' )
949 .complex_op_is("0+0.5i", "-1.570796-0.549306i", 'acot' )
950 .complex_op_is("0+2i", "0.000000-0.549306i", 'acot' )
951 .complex_op_is("2+3i", "0.160875-0.229073i", 'acot' )
952 .complex_op_is("2-3i", "0.160875+0.229073i", 'acot' )
953 .complex_op_is("-2+3i", "-0.160875-0.229073i", 'acot' )
954 .complex_op_is("-2-3i", "-0.160875+0.229073i", 'acot' )
957 .sub asec_of_complex_numbers
958 .complex_op_is("-2+0i", "2.094395+0.000000i", 'asec' )
959 .complex_op_is("-1+0i", "3.141593+0.000000i", 'asec' )
960 .complex_op_is("-0.5+0i", "3.141593-1.316958i", 'asec' )
961 .complex_op_is("0.5+0i", "0.000000+1.316958i", 'asec' )
962 .complex_op_is("1+0i", "0.000000+0.000000i", 'asec' )
963 .complex_op_is("2+0i", "1.047198+0.000000i", 'asec' )
964 .complex_op_is("0-2i", "1.570796-0.481212i", 'asec' )
965 .complex_op_is("0-1i", "1.570796-0.881374i", 'asec' )
966 .complex_op_is("0-0.5i", "1.570796-1.443635i", 'asec' )
967 .complex_op_is("0+0.5i", "1.570796+1.443635i", 'asec' )
968 .complex_op_is("0+1i", "1.570796+0.881374i", 'asec' )
969 .complex_op_is("0+2i", "1.570796+0.481212i", 'asec' )
970 .complex_op_is("2+3i", "1.420411+0.231335i", 'asec' )
971 .complex_op_is("2-3i", "1.420411-0.231335i", 'asec' )
972 .complex_op_is("-2+3i", "1.721182+0.231335i", 'asec' )
973 .complex_op_is("-2-3i", "1.721182-0.231335i", 'asec' )
976 .sub acsc_of_complex_numbers
977 .complex_op_is("-2+0i", "-0.523599+0.000000i", 'acsc' )
978 .complex_op_is("-1+0i", "-1.570796+0.000000i", 'acsc' )
979 .complex_op_is("-0.5+0i", "-1.570796+1.316958i", 'acsc' )
980 .complex_op_is("0.5+0i", "1.570796-1.316958i", 'acsc' )
981 .complex_op_is("1+0i", "1.570796+0.000000i", 'acsc' )
982 .complex_op_is("2+0i", "0.523599+0.000000i", 'acsc' )
983 .complex_op_is("0-2i", "0.000000+0.481212i", 'acsc' )
984 .complex_op_is("0-1i", "0.000000+0.881374i", 'acsc' )
985 .complex_op_is("0-0.5i", "0.000000+1.443635i", 'acsc' )
986 .complex_op_is("0+0.5i", "0.000000-1.443635i", 'acsc' )
987 .complex_op_is("0+1i", "0.000000-0.881374i", 'acsc' )
988 .complex_op_is("0+2i", "0.000000-0.481212i", 'acsc' )
989 .complex_op_is("2+3i", "0.150386-0.231335i", 'acsc' )
990 .complex_op_is("2-3i", "0.150386+0.231335i", 'acsc' )
991 .complex_op_is("-2+3i", "-0.150386-0.231335i", 'acsc' )
992 .complex_op_is("-2-3i", "-0.150386+0.231335i", 'acsc' )
995 .sub sinh_of_complex_numbers
996 .local pmc config_hash, interp
997 .local string has_negative_zero
999 config_hash = interp[.IGLOBALS_CONFIG_HASH]
1000 has_negative_zero = config_hash["has_negative_zero"]
1002 .complex_op_is("-2+0i", "-3.626860+0.000000i", 'sinh' )
1003 .complex_op_is("-1+0i", "-1.175201+0.000000i", 'sinh' )
1004 .complex_op_is("-0.5+0i", "-0.521095+0.000000i", 'sinh' )
1005 .complex_op_is("0.5+0i", "0.521095+0.000000i", 'sinh' )
1006 .complex_op_is("1+0i", "1.175201+0.000000i", 'sinh' )
1007 .complex_op_is("2+0i", "3.626860+0.000000i", 'sinh' )
1008 .complex_op_is("0-1i", "0.000000-0.841471i", 'sinh' )
1009 .complex_op_is("0-0.5i", "0.000000-0.479426i", 'sinh' )
1010 .complex_op_is("0+0.5i", "0.000000+0.479426i", 'sinh' )
1011 .complex_op_is("0+1i", "0.000000+0.841471i", 'sinh' )
1012 .complex_op_is("0+0i", "0.000000+0.000000i", 'sinh' )
1013 .complex_op_is("2+3i", "-3.590565+0.530921i", 'sinh' )
1014 .complex_op_is("2-3i", "-3.590565-0.530921i", 'sinh' )
1015 .complex_op_is("-2+3i", "3.590565+0.530921i", 'sinh' )
1016 .complex_op_is("-2-3i", "3.590565-0.530921i", 'sinh' )
1018 unless has_negative_zero goto todo
1019 .complex_op_is("0-2i", "-0.000000-0.909297i", 'sinh' )
1020 .complex_op_is("0+2i", "-0.000000+0.909297i", 'sinh' )
1024 .complex_op_todo("0-2i", "-0.000000-0.909297i", 'sinh', 'TT #313' )
1025 .complex_op_todo("0+2i", "-0.000000+0.909297i", 'sinh', 'TT #313' )
1029 .sub cosh_of_complex_numbers
1030 .complex_op_is("-2+0i", "3.762196+0.000000i", 'cosh' )
1031 .complex_op_is("-1+0i", "1.543081+0.000000i", 'cosh' )
1032 .complex_op_is("-0.5+0i", "1.127626+0.000000i", 'cosh' )
1033 .complex_op_is("0.5+0i", "1.127626+0.000000i", 'cosh' )
1034 .complex_op_is("1+0i", "1.543081+0.000000i", 'cosh' )
1035 .complex_op_is("2+0i", "3.762196+0.000000i", 'cosh' )
1036 .complex_op_is("0-2i", "-0.416147+0.000000i", 'cosh' )
1037 .complex_op_is("0-1i", "0.540302+0.000000i", 'cosh' )
1038 .complex_op_is("0-0.5i", "0.877583+0.000000i", 'cosh' )
1039 .complex_op_is("0+0.5i", "0.877583+0.000000i", 'cosh' )
1040 .complex_op_is("0+1i", "0.540302+0.000000i", 'cosh' )
1041 .complex_op_is("0+2i", "-0.416147+0.000000i", 'cosh' )
1042 .complex_op_is("0+0i", "1.000000+0.000000i", 'cosh' )
1043 .complex_op_is("2+3i", "-3.724546+0.511823i", 'cosh' )
1044 .complex_op_is("2-3i", "-3.724546-0.511823i", 'cosh' )
1045 .complex_op_is("-2+3i", "-3.724546-0.511823i", 'cosh' )
1046 .complex_op_is("-2-3i", "-3.724546+0.511823i", 'cosh' )
1049 .sub tanh_of_complex_numbers
1050 .complex_op_is("-2+0i", "-0.964028+0.000000i", 'tanh' )
1051 .complex_op_is("-1+0i", "-0.761594+0.000000i", 'tanh' )
1052 .complex_op_is("-0.5+0i", "-0.462117+0.000000i", 'tanh' )
1053 .complex_op_is("0.5+0i", "0.462117+0.000000i", 'tanh' )
1054 .complex_op_is("1+0i", "0.761594+0.000000i", 'tanh' )
1055 .complex_op_is("2+0i", "0.964028+0.000000i", 'tanh' )
1056 .complex_op_is("0-2i", "0.000000+2.185040i", 'tanh' )
1057 .complex_op_is("0-1i", "0.000000-1.557408i", 'tanh' )
1058 .complex_op_is("0-0.5i", "0.000000-0.546302i", 'tanh' )
1059 .complex_op_is("0+0.5i", "0.000000+0.546302i", 'tanh' )
1060 .complex_op_is("0+1i", "0.000000+1.557408i", 'tanh' )
1061 .complex_op_is("0+2i", "0.000000-2.185040i", 'tanh' )
1062 .complex_op_is("0+0i", "0.000000+0.000000i", 'tanh' )
1063 .complex_op_is("2+3i", "0.965386-0.009884i", 'tanh' )
1064 .complex_op_is("2-3i", "0.965386+0.009884i", 'tanh' )
1065 .complex_op_is("-2+3i", "-0.965386-0.009884i", 'tanh' )
1066 .complex_op_is("-2-3i", "-0.965386+0.009884i", 'tanh' )
1069 .sub coth_of_complex_numbers
1070 .complex_op_is("-2+0i", "-1.037315+0.000000i", 'coth' )
1071 .complex_op_is("-1+0i", "-1.313035+0.000000i", 'coth' )
1072 .complex_op_is("-0.5+0i", "-2.163953+0.000000i", 'coth' )
1073 .complex_op_is("0.5+0i", "2.163953+0.000000i", 'coth' )
1074 .complex_op_is("1+0i", "1.313035+0.000000i", 'coth' )
1075 .complex_op_is("2+0i", "1.037315+0.000000i", 'coth' )
1076 .complex_op_is("0-2i", "0.000000-0.457658i", 'coth' )
1077 .complex_op_is("0-1i", "0.000000+0.642093i", 'coth' )
1078 .complex_op_is("0-0.5i", "0.000000+1.830488i", 'coth' )
1079 .complex_op_is("0+0.5i", "0.000000-1.830488i", 'coth' )
1080 .complex_op_is("0+1i", "0.000000-0.642093i", 'coth' )
1081 .complex_op_is("0+2i", "0.000000+0.457658i", 'coth' )
1082 .complex_op_is("2+3i", "1.035747+0.010605i", 'coth' )
1083 .complex_op_is("2-3i", "1.035747-0.010605i", 'coth' )
1084 .complex_op_is("-2+3i", "-1.035747+0.010605i", 'coth' )
1085 .complex_op_is("-2-3i", "-1.035747-0.010605i", 'coth' )
1088 .sub sech_of_complex_numbers
1089 .complex_op_is("-2+0i", "0.265802+0.000000i", 'sech' )
1090 .complex_op_is("-1+0i", "0.648054+0.000000i", 'sech' )
1091 .complex_op_is("-0.5+0i", "0.886819+0.000000i", 'sech' )
1092 .complex_op_is("0.5+0i", "0.886819+0.000000i", 'sech' )
1093 .complex_op_is("1+0i", "0.648054+0.000000i", 'sech' )
1094 .complex_op_is("2+0i", "0.265802+0.000000i", 'sech' )
1095 .complex_op_is("0-2i", "-2.402998+0.000000i", 'sech' )
1096 .complex_op_is("0-1i", "1.850816+0.000000i", 'sech' )
1097 .complex_op_is("0-0.5i", "1.139494+0.000000i", 'sech' )
1098 .complex_op_is("0+0.5i", "1.139494+0.000000i", 'sech' )
1099 .complex_op_is("0+1i", "1.850816+0.000000i", 'sech' )
1100 .complex_op_is("0+2i", "-2.402998+0.000000i", 'sech' )
1101 .complex_op_is("0+0i", "1.000000+0.000000i", 'sech' )
1102 .complex_op_is("2+3i", "-0.263513-0.036212i", 'sech' )
1103 .complex_op_is("2-3i", "-0.263513+0.036212i", 'sech' )
1104 .complex_op_is("-2+3i", "-0.263513+0.036212i", 'sech' )
1105 .complex_op_is("-2-3i", "-0.263513-0.036212i", 'sech' )
1108 .sub csch_of_complex_numbers
1109 .complex_op_is("-2+0i", "-0.275721+0.000000i", 'csch' )
1110 .complex_op_is("-1+0i", "-0.850918+0.000000i", 'csch' )
1111 .complex_op_is("-0.5+0i", "-1.919035+0.000000i", 'csch' )
1112 .complex_op_is("0.5+0i", "1.919035+0.000000i", 'csch' )
1113 .complex_op_is("1+0i", "0.850918+0.000000i", 'csch' )
1114 .complex_op_is("2+0i", "0.275721+0.000000i", 'csch' )
1115 .complex_op_is("0-2i", "0.000000+1.099750i", 'csch' )
1116 .complex_op_is("0-1i", "0.000000+1.188395i", 'csch' )
1117 .complex_op_is("0-0.5i", "0.000000+2.085830i", 'csch' )
1118 .complex_op_is("0+0.5i", "0.000000-2.085830i", 'csch' )
1119 .complex_op_is("0+1i", "0.000000-1.188395i", 'csch' )
1120 .complex_op_is("0+2i", "0.000000-1.099750i", 'csch' )
1121 .complex_op_is("2+3i", "-0.272549-0.040301i", 'csch' )
1122 .complex_op_is("2-3i", "-0.272549+0.040301i", 'csch' )
1123 .complex_op_is("-2+3i", "0.272549-0.040301i", 'csch' )
1124 .complex_op_is("-2-3i", "0.272549+0.040301i", 'csch' )
1127 .sub add_using_subclass_of_complex_bug_59630
1128 $P0 = subclass 'Complex', 'MyComplex'
1129 addattribute $P0, "re"
1130 addattribute $P0, "im"
1132 .local pmc a, b, c, expected
1134 a = new ['MyComplex']
1137 is( a, "1+2i", 'a created' )
1140 b = new ['MyComplex']
1143 is( b, "3+4i" , 'b created' )
1147 expected = new ['MyComplex']
1148 expected['real'] = 4
1149 expected['imag'] = 6
1152 $S0 = concat $S1, ' != '
1154 $S0 = concat $S0, $S1
1155 $S0 = concat $S0, ' - subclassing Complex add returns 0+0i - TT #562'
1156 $I0 = not $I0 # invert $I0 so todo does not pass
1160 .sub provides_complex
1162 $I0 = does $P0, 'complex'
1165 # ...And test a subclass, for good measure
1166 $P0 = new 'MyComplex'
1167 $I0 = does $P0, 'complex'
1171 .namespace ['MyComplex']
1175 setattribute self, "re", $P1
1177 setattribute self, "im", $P2
1180 .namespace [] # revert to root for next test
1187 # vim: expandtab shiftwidth=4 ft=pir: