为任何解决问题的人提供赏金。在发布解决方案以讨论金额之前先 PM 我。
我想做的是有一个循环检查param.result。正在对 stepping_isProbablePrime 进行异步调用。这将返回一个接近我的值,我在 checkPrime 函数的返回中使用它。但是,我不确定调用此函数后如何访问结果,我想保留它以在循环期间检查素数。每次我尝试访问结果时,它要么为空,要么身份不明。
var findPrime = function(checkPrime, result)
{
var inParam = null;
var prime = new BigInteger("7", 10);
checkPrime(prime, result);
alert(inParam);
}
var result = function(param1)
{
inParam = param1
return param1;
}
var checkPrime = function(p2,result)
{
var inParam = null;
var closure= p2.stepping_isProbablePrime(5);
var receiver = function(scope,param,subparam)
{
result( param.result );
return BREAK;
};
return ( [ closure, receiver, EXIT ] ).ready().frequency(1).timeout(1).go();
};
var timerID = findPrime(checkPrime, result);
}
下面包括方法调用 stepping_isProbablePrime(t):
BigInteger.prototype.stepping_isProbablePrime = function (t) {
BigInteger.log( "stepping_isProbablePrime:create" );
var self = this;
var x = self.abs();
var et1 = ElapsedTime.create();
var et2 = ElapsedTime.create();
return [
function(scope,param,subparam) {
BigInteger.log("stepping_isProbablePrime No.1: " );
et1.start( "stepping_isProbablePrime" );
var i;
if( x.t == 1 && x[0] <= lowprimes[ lowprimes.length-1 ] ) {
for ( i = 0; i < lowprimes.length; ++i )
if ( x[0] == lowprimes[i] ) {
BigInteger.log( "stepping_isProbablePrime.1 EXIT" );
//return true;
param.result = true;
return EXIT;
}
BigInteger.log( "stepping_isProbablePrime.2 EXIT" );
// return false;
param.result = false;
return EXIT;
}
if ( x.isEven() ) {
BigInteger.log( "stepping_isProbablePrime.3 EXIT" );
// return false;
param.result = false;
return EXIT;
}
i = 1;
while ( i < lowprimes.length ) {
var m = lowprimes[i];
var j = i+1;
while( j < lowprimes.length && m < lplim ) {
m *= lowprimes[j++];
}
m = x.modInt(m);
while( i < j ) {
if( m % lowprimes[i++] == 0 ) {
BigInteger.log( "stepping_isProbablePrime:4 EXIT" );
// return false;
param.result = false;
return EXIT;
}
}
}
BigInteger.log( "stepping_isProbablePrime:5 BREAK" );
return BREAK;
},
// // ver1>>
// function(scope,param,subparam) {
// BigInteger.log("stepping_isProbablePrime No.2:called:" + param.result );
// // return x.millerRabin(t);
// et2.start("isProbablePrime.millerRabin");
// var result = x.millerRabin(t);
// et2.stop();
// et1.stop();
// param.result = result;
// return BREAK;
// },
// // ver1<<
// ver2>>
function(scope,param,subparam) {
BigInteger.log( "stepping_isProbablePrime No.2: calling millerRabin : subparam.result=" + subparam.result );
et2.start("isProbablePrime.millerRabin");
subparam.result=null;
return x.stepping_millerRabin(t).BREAK();
},
function(scope,param,subparam) {
BigInteger.log( "stepping_isProbablePrime No.3: returning millerRabin : subparam.result=" + subparam.result );
et2.stop();
et1.stop();
param.result = subparam.result;
BigInteger.log( "stepping_isProbablePrime No.3: param.result=" + param.result );
return BREAK;
},
// ver2<<
EXIT
].NAME("stepping_isProbablePrime");
};