Rb_big_pow


#1

e$B$U$He(B test_integer.rb e$B$N<B9T$re(B callgrind
e$B$r$+$1$F!"e(Bbignum.c
e$B$rD/$a$F$$$k$H!“e(Brb_big_pow e$B$NCf$K<B9T$5$l$J$$ItJ,$,$”$k$N$Ke(B
e$B5$$,$D$-$^$7$?!#$=$7$F$7$P$i$/D/$a$?7k2L!“e(Bn e$B$H$$$&JQ?t$O$:$Ce(B
e$B$He(B 1 e$B$J$3$H$K5$$,$D$$$F$7$^$$$^$7$?!#$J$K$+JQ$@$H;W$&$s$G$9e(B
e$B$,!”$I$&$J$s$G$7$g$&e(B?


case T_FIXNUM:
yy = FIX2LONG(y);
if (yy > 0) {
VALUE z = 0;
SIGNED_VALUE mask, n = 1; // e$B$3$3$Ge(B 1 e$B$r@_Dje(B

for (mask = FIXNUM_MAX + 1; mask; mask >>= 1) {
if (!z) {
SIGNED_VALUE n2 = n * n; // 1 * 1 e$B$Oe(B 1
if (!POSFIXABLE(n2) || (n2 / n != n)) { //
e$B>r7o$O@.N)$7$J$$e(B
z = bigtrunc(bigsqr(rb_int2big(n))); //
e$B$3$3$O<B9T$5$l$J$$e(B
}
else {
n = n2; // e$B$3$3$Ge(B 1 e$B$rBeF~e(B
}
}
else {
z = bigtrunc(bigsqr(z));
}
if (yy & mask) {
if (!z) z = rb_int2big(n); //
rb_int2bige$B$K$O>o$Ke(B 1 e$B$rEO$9e(B
z = bigtrunc(rb_big_mul0(z, x));
}
}
return bignorm(z);
}
d = (double)yy;
break;


#2

e$B$J$+$@$G$9!#e(B

At Sun, 15 Jul 2007 23:37:08 +0900,
Tanaka A. wrote in [ruby-dev:31236]:

e$B$U$He(B test_integer.rb e$B$N<B9T$re(B callgrind e$B$r$+$1$F!"e(Bbignum.c
e$B$rD/$a$F$$$k$H!“e(Brb_big_pow e$B$NCf$K<B9T$5$l$J$$ItJ,$,$”$k$N$Ke(B
e$B5$$,$D$-$^$7$?!#$=$7$F$7$P$i$/D/$a$?7k2L!“e(Bn e$B$H$$$&JQ?t$O$:$Ce(B
e$B$He(B 1 e$B$J$3$H$K5$$,$D$$$F$7$^$$$^$7$?!#$J$K$+JQ$@$H;W$&$s$G$9e(B
e$B$,!”$I$&$J$s$G$7$g$&e(B?

e$B$?$7$+$KITMW$N$h$&$G$9!#e(B

                z = bigtrunc(bigsqr(z));
            }
            if (yy & mask) {
                if (!z) z = rb_int2big(n); // rb_int2bige$B$K$O>o$Ke(B 1 e$B$rEO$9e(B
                z = bigtrunc(rb_big_mul0(z, x));

e$BK\Mh$J$i$3$3$Ge(Bne$B$Ke(Bxe$B$r3]$1$k$O$:$J$N$G$9$,!“e(Bxe$B$Oe(BBignume$B$J$N$Ge(BBignum
e$B$G$”$ke(Bze$B$r:G=i$+$i;H$&$3$H$K$J$j!“e(BFixnume$BAjEv$Ne(Bne$B$O;H$o$l$k$3$H$,e(B
e$B$J$/$J$C$F$7$^$C$?!”$H$$$&$3$H$+$H;W$$$^$9!#e(B