1use warnings; 2use strict; 3use Math::MPC qw(:mpc); 4use Math::MPFR qw(:mpfr); 5 6print "1..3\n"; 7 8Rmpc_set_default_prec2(100, 100); 9 10my $mpc = Math::MPC->new('246' x 7, '3579' x 6); 11my $ok = ''; 12my($real, $im) = c_string($mpc, 16, 0, MPC_RNDNN); 13my $r = r_string($mpc, 16, 0, MPC_RNDNN); 14my $i = i_string($mpc, 16, 0, MPC_RNDNN); 15 16if($r eq $real) {$ok .= 'a'} 17else {print "$r ne $real\n"} 18 19if($i eq $im) {$ok .= 'b'} 20else {print "$i ne $im\n"} 21 22if($real eq 'd.595a684adcdfe766@16') {$ok .= 'c'} 23else {print "$real ne d.595a684adcdfe766\@16\n"} 24 25if($im eq '4.bcbbcfdfb50863475ab@19') {$ok .= 'd'} 26else {print "$im ne 4.bcbbcfdfb50863475ab\@19\n"} 27 28($real, $im) = c_string($mpc, 10, 0, MPC_RNDNN); 29 30if($real eq '2.46246246246246246246e20') {$ok .= 'e'} 31else {print "$real ne 2.46246246246246246246e20\n"} 32 33if($im eq '3.57935793579357935793579e23') {$ok .= 'f'} 34else {print "$im ne 3.57935793579357935793579e23\n"} 35 36my $mpc_simple = Math::MPC->new(16.03125, 15.25); 37my $complex_string = Rmpc_get_str(16, 0, $mpc_simple, MPC_RNDNN); 38if($complex_string eq '(1.0080000000000000000000000p+4 f.4000000000000000000000000)') {$ok .= 'g'} 39 40$complex_string = Rmpc_get_str(16, 5, $mpc_simple, MPC_RNDNN); 41if($complex_string eq '(1.0080p+4 f.4000)') {$ok .= 'h'} 42 43$complex_string = Rmpc_get_str(10, 0, $mpc_simple, MPC_RNDNN); 44if($complex_string eq '(1.6031250000000000000000000000000e+1 1.5250000000000000000000000000000e+1)') {$ok .= 'i'} 45 46$complex_string = Rmpc_get_str(10, 9, $mpc_simple, MPC_RNDNN); 47if($complex_string eq '(1.60312500e+1 1.52500000e+1)') {$ok .= 'j'} 48 49if($ok eq 'abcdefghij') {print "ok 1\n"} 50else {print "not ok 1 $ok\n"} 51 52$ok = ''; 53 54my $mpc2 = Math::MPC->new(0, 0); 55$mpc2 *= -1; 56if(Math::MPC::overload_string($mpc2) eq '(-0 -0)') {$ok .= 'a'} 57else {warn "\n2a: got '",Math::MPC::overload_string($mpc2), "'\nexpected '(-0 -0)'\n"} 58my $mpfr1 = Math::MPFR->new(-0.0); 59my $inf = 1 / $mpfr1; 60my $nan = Math::MPFR->new(); 61my $mpc3 = Math::MPC->new($nan, $inf); 62 63if(lc(Math::MPC::overload_string($mpc3)) eq '(@nan@ -@inf@)') {$ok .= 'b'} 64else {warn "\n2b: got '", lc(Math::MPC::overload_string($mpc3)), "'\n" } 65 66if($ok eq 'ab') {print "ok 2\n"} 67else {print "not ok 2 $ok\n"} 68 69$ok = ''; 70 71my $mpc4 = Math::MPC->new(-10, 12.5); 72my @vals = Rmpc_deref4($mpc4, 10, 5, MPC_RNDNN); 73 74$ok .= 'a' if $vals[0] eq '-10000'; 75$ok .= 'b' if $vals[1] == 2; 76$ok .= 'c' if $vals[2] eq '12500'; 77$ok .= 'd' if $vals[3] == 2; 78 79if($ok eq 'abcd') {print "ok 3\n"} 80else {print "not ok 3 $ok\n"} 81