blib/script/gmp_manual_orig.pl untested

filter: Statementstmt 0.0% 0 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 22 CC 1 SCAR 6.9
CC
1
Cov
0%
my_mul
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3 use Math::BigInt lib => 'GMP';
4  
5 use Inline C => Config =>
6 LIBS => '-lgmp',
7 USING => 'ParseRegExp',
8 BUILD_NOISY => 1;
9  
10  
11 use Inline C => <<'EOC';
12  
13 #include <gmp.h>
14  
15 mpz_t * mpz_from_sv_nofail (SV *sv)
16 {
17 MAGIC *mg;
18  
19 if (!sv_derived_from(sv, "Math::BigInt::GMP"))
20 croak("not of type Math::BigInt::GMP");
21  
22 mg = SvMAGIC(SvRV(sv));
23  
24 return (mpz_t *)mg->mg_ptr;
25 }
26  
27 void _my_mul(SV * bi_rop, SV * bi_op, SV * si, SV * rop_sign, SV * op_sign) {
28 mpz_t *t1, *t2;
29  
30 sv_setpv(rop_sign, SvPV_nolen(op_sign));
31  
32 t1 = mpz_from_sv_nofail(bi_rop);
33 t2 = mpz_from_sv_nofail(bi_op);
34  
35 mpz_abs(*t2, *t2);
36 mpz_mul_si(*t1, *t2, abs(SvIV(si)));
37  
38 if(SvIV(si) < 0) {
39 if(strEQ(SvPV_nolen(op_sign), "-")) sv_setpv(rop_sign, "+");
40 else sv_setpv(rop_sign, "-");
41 }
42 }
43  
44 EOC
45  
46 my $rop = Math::BigInt->new(0);
47 my $op = Math::BigInt->new(-123456);
48 my $x = 1103;
49  
50 my_mul($rop, $op, $x);
51 print $rop, "\n";
52  
53 my_mul($op, $op, 5);
54 print $op, "\n";
55  
56 sub my_mul {
57 _my_mul($_[0]->{value}, $_[1]->{value}, $_[2], $_[0]->{sign}, $_[1]->{sign});
58 }