@@ -26,6 +26,12 @@ function intishBool(b) {
26
26
return b ? 1 : 0 ;
27
27
}
28
28
29
+ function makeNum ( type , num ) {
30
+ var instance = type . _STable . REPR . allocate ( type . _STable ) ;
31
+ instance . $$setNum ( num ) ;
32
+ return instance ;
33
+ }
34
+
29
35
function makeBI ( type , num ) {
30
36
var instance = type . _STable . REPR . allocate ( type . _STable ) ;
31
37
instance . $$setBignum ( num ) ;
@@ -93,8 +99,22 @@ op.div_I = function(a, b, type) {
93
99
return makeBI ( type , getBI ( a ) . div ( getBI ( b ) ) ) ;
94
100
} ;
95
101
96
- op . pow_I = function ( a , b , type ) {
97
- return makeBI ( type , getBI ( a ) . pow ( getBI ( b ) ) ) ;
102
+ op . pow_I = function ( a , b , numType , biType ) {
103
+ var base = getBI ( a ) ;
104
+ var exponent = getBI ( b ) ;
105
+ if ( exponent . lt ( 0 ) ) {
106
+ return makeNum ( numType , Math . pow ( base . toNumber ( ) , exponent . toNumber ( ) ) ) ;
107
+ } else {
108
+ if ( exponent . gt ( 4294967296 ) && ! base . eq ( 1 ) && ! base . eq ( 0 ) ) {
109
+ if ( base . eq ( - 1 ) ) {
110
+ // workaround a bug in bignum
111
+ return makeBI ( biType , bignum ( exponent . mod ( 2 ) . eq ( 0 ) ? 1 : - 1 ) ) ;
112
+ } else {
113
+ return makeNum ( numType , base . lt ( 0 ) && exponent . mod ( 2 ) . eq ( 1 ) ? Number . NEGATIVE_INFINITY : Number . POSITIVE_INFINITY ) ;
114
+ }
115
+ }
116
+ return makeBI ( biType , base . pow ( exponent ) ) ;
117
+ }
98
118
} ;
99
119
100
120
op . mod_I = function ( n , m , type ) {
0 commit comments