Пример #1
0
int 
parsebf(char *buf)
{
   double rainrate, raintot;

   if (!sumcheck(buf, SIZEBF)) {
      errlog(8, "Checksum failure for BF block.");
      return (-1);
   }
   rainrate = (xDtoint(buf[2]) * 100) + DDtoint(buf[1]);
   raintot = (xDtoint(buf[6]) * 100) + DDtoint(buf[5]);

   correct(rainrate, current_cal.rain_rate_mul, current_cal.rain_rate_offs);
   correct(raintot, current_cal.rain_tot_mul, current_cal.rain_tot_offs);

   pthread_mutex_lock(&current_obs_lock);
   if (raintot < current_obs.rain_tot) {
      current_obs.rtot_offset += current_obs.rain_tot;
   }
   pthread_mutex_unlock(&current_obs_lock);

   update(current_obs.rain_rate, rainrate, RAINRATE);
   update(current_obs.rain_tot, raintot, RAINTOT);

   errlog2(9, "Rain rate %g mm/hr, Rain tot %g mm", rainrate, raintot);
}
Пример #2
0
int 
parseaf(char *buf)
{
   double baro, dewpt_in, dewpt_out;

   if (!sumcheck(buf, SIZEAF)) {
      errlog(8, "Checksum failure for AF block.");
      return (-1);
   }
   baro = DDtoint(buf[3]) + (DDtoint(buf[4]) * 100.0) + (xDtoint(buf[5]) * 10000.0);
   baro /= 10;

   dewpt_in = DDtoint(buf[7]);
   dewpt_out = DDtoint(buf[18]);

   correct(dewpt_in, current_cal.dp_in_mul, current_cal.dp_in_offs);
   correct(dewpt_out, current_cal.dp_out_mul, current_cal.dp_out_offs);
   correct(baro, current_cal.barometer_mul, current_cal.barometer_offs);

   update(current_obs.dp_in, dewpt_in, DEWIN);
   update(current_obs.dp_out, dewpt_out, DEWOUT);
   update(current_obs.barometer, baro, BARO);


   errlog1(9, "Barometer: %g mb", baro);
   errlog2(9, "Indoor dewpoint: %gC, Outdoor dewpoint: %gC", dewpt_in, dewpt_out);

}
Пример #3
0
//
// Extract the index'th string in the sequence
//
LPSTR NSStrSeqGet(NSstringSeq seq, LONG index)
{
  char* s;
  int N;

  if (!seq)
  {
    return NULL;
  }
  
  if (index<0)
  {
    return NULL;
  }
  
  if (!index)
    return correct(seq);
  
  for (s=seq+1,N=0; ((*s) || (*(s-1))) && (N<index); s++)
  {
    if (!(*s))
      N++;
  }
  
  if (N==index)
    return correct(s);
  
  return NULL;
}
Пример #4
0
int 
parse8f(char *buf)
{
   int hour, min, sec, day, mon;
   double hum_in, hum_out;
   if (!sumcheck(buf, SIZE8F)) {
      errlog(8, "Checksum failure for 8F block.");
      return (-1);
   }
   sec = DDtoint(buf[1]);
   min = DDtoint(buf[2]);
   hour = DDtoint(buf[3]);
   mon = xDtoint(buf[5]);
   day = DDtoint(buf[4]);
   hum_in = DDtoint(buf[8]);
   hum_out = DDtoint(buf[20]);

   current_obs.sec = sec;
   current_obs.min = min;
   current_obs.hour = hour;
   current_obs.month = mon;
   current_obs.day = day;

   correct(hum_in, current_cal.rh_in_mul, current_cal.rh_in_offs);
   correct(hum_out, current_cal.rh_out_mul, current_cal.rh_out_offs);

   update(current_obs.rh_in, hum_in, HUMIN);
   update(current_obs.rh_out, hum_out, HUMOUT);

   errlog5(9, "%s %d %.2d:%.2d:%.2d", month[mon], day, hour, min, sec);
   errlog2(9, "Indoor hum: %g%%, Outdoor hum: %g%%", hum_in, hum_out);
}
Пример #5
0
bool GameLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) {
	if (LOCAL_CONTEXT->firstRun()) { //第一次启动,点击取消帮助画面层
		this->removeHelpLayer();
		return false;
	}

	if (running) {
		disable();
		CCSprite *lastItem = items[0];
		long itemnum = (long) lastItem->getUserData();
		//CCDirector::sharedDirector()->replaceScene(FinishLayer::scene());
		CCSize winsize = CCDirector::sharedDirector()->getWinSize();
		CCPoint location = pTouch->getLocation();
		if (location.x < winsize.width / 2) {
			LOCAL_CONTEXT->playEffect("left.mp3");
			//瓶子 6-10
			if (itemnum >= 6) {
				correct(-0.32);
			} else {
				mistake(-0.32);
			}
		} else {
			LOCAL_CONTEXT->playEffect("right.mp3");
			//罐子 1-5
			if (itemnum <= 5) {
				correct(0.32);
			} else {
				mistake(0.32);
			}
		}
	}
	return false;

}
Пример #6
0
const InfInt& InfInt::operator%=(const InfInt& rhs)
{
	if (rhs == zero)
	{
#ifdef INFINT_USE_EXCEPTIONS
		throw InfIntException("division by zero");
#else
		std::cerr << "Division by zero!" << std::endl;
		return zero;
#endif
	}
	InfInt D = (rhs.pos ? rhs : -rhs), N = (pos ? *this : -*this);
	bool oldpos = pos;
	val.clear();
	for (int i = (int)N.val.size() - 1; i >= 0; --i)
	{
		val.insert(val.begin(), (ELEM_TYPE)0);
		val[0] = N.val[i];
		correct(true);
		*this -= D * dInR(*this, D);
	}
	correct();
	pos = (val.size() == 1 && val[0] == 0) ? true : oldpos;
	return *this;
}
Пример #7
0
void bmeps_setup(int psl, int col, int a85, int rl, int fl,
  int alpha, int trans, int altrig,
  int mix, int specbg, int bg_red, int bg_green, int bg_blue, int dsc_show
)
{
  is_configured = 1;
  bmeps_color = bmeps_enc_a85 = bmeps_enc_rl = bmeps_enc_fl = 0;
  bmeps_alpha = bmeps_trans = bmeps_altrig = 0;
  bmeps_mix = bmeps_specbg = 0;
  bmeps_bg_red = bmeps_bg_green = bmeps_bg_blue = 255;
  bmeps_pslevel = psl;
  bmeps_mix = (mix ? 1 : 0);
  bmeps_specbg = (specbg ? 1 : 0);
  bmeps_bg_red = bg_red;
  bmeps_bg_green = bg_green;
  bmeps_bg_blue = bg_blue;
  show_dsc_comments = dsc_show;
  correct(bmeps_bg_red);
  correct(bmeps_bg_green);
  correct(bmeps_bg_blue);
  if(bmeps_pslevel < 1) bmeps_pslevel = 1;
  if(bmeps_pslevel > MAXPSLEVEL) bmeps_pslevel = MAXPSLEVEL;
  if(bmeps_pslevel > 1) {
    bmeps_color = (col ? 1 : 0);
    bmeps_enc_a85 = (a85 ? 1 : 0);
    bmeps_enc_rl  = (rl  ? 1 : 0);
    if(bmeps_pslevel > 2) {
      bmeps_enc_fl = ( fl ? 1 : 0 );
      if(alpha) {
        bmeps_alpha = 1;
        bmeps_trans = (trans ? 1 : 0); bmeps_altrig = (altrig ? 1 : 0);
      }
    }
  }
}
Пример #8
0
int 
parse9f(char *buf)
{
   double temp_in, temp_out;

   if (!sumcheck(buf, SIZE9F)) {
      errlog(8, "Checksum failure for 9F block.");
      return (-1);
   }
   temp_in = ((xDtoint(buf[2] & 0x07) * 100) + (DDtoint(buf[1]))) / 10;
   if (buf[2] & 0x08) {
      temp_in = -1.0 * temp_in;
   }
   temp_out = ((xDtoint(buf[17] & 0x07) * 100) + (DDtoint(buf[16]))) / 10;
   if (buf[17] & 0x08) {
      temp_out = -1.0 * temp_out;
   }

   if ((temp_out < -50.0) || (temp_in < -50.0)) return; /*Bad data*/

   correct(temp_in, current_cal.temp_in_mul, current_cal.temp_in_offs);
   correct(temp_out, current_cal.temp_out_mul, current_cal.temp_out_offs);

   update(current_obs.temp_in, temp_in, TEMPIN);
   update(current_obs.temp_out, temp_out, TEMPOUT);

   errlog2(9, "Indoor temp: %gC, Outdoor temp: %gC", temp_in, temp_out);
}
int tr_fl(int q_no)
{
	char tf,ter;

	if(q_no==4)
	{
		ques(4);
		printf("\n\nAll metals are ductile.(t/f)");
		printf("\n\nType \"t\" for TRUE\tor \"f\" for FALSE");

		ter=check();

		if(ter==14)
			goto end;

		flushall();
		printf("\n\nYOUR OPINION:-\t");
		scanf("%c",&tf);
		if(tf=='f')
		{
			correct();
			return 1;
		}
		else
			printf("\n\n\a\aIT IS A FALSE STATEMENT");
		getch();
	}
	if(q_no==6)
	{
		ques(6);
		printf("\n\nUnicellular organisms have one celled body.(t/f)");
		printf("\n\nType \"t\" for TRUE\tor \"f\" for FALSE");
		ter=check();

		if(ter==14)
			goto end;

		flushall();
		printf("\n\nYOUR OPINION:-\t");
		scanf("%c",&tf);
		if(tf=='t')
		{
			correct();
			return 1;
		}
		else
			printf("\n\n\a\aIT IS A TRUE STATEMENT");
		getch();
	}
	end:
	return 0;
}
Пример #10
0
int 
parsecf(char *buf)
{
   double gust, avg, chill, hum_out;
   double avg_dir, gust_dir;

   if (!sumcheck(buf, SIZECF)) {
      errlog(9, "Checksum failure for CF block.");
      return (-1);
   }
   gust = ((xDtoint(buf[2]) * 100) + DDtoint(buf[1])) / 10;
   gust_dir = (Dxtoint(buf[2])) + (DDtoint(buf[3]) * 10);

   avg = ((xDtoint(buf[5]) * 100) + DDtoint(buf[4])) / 10;
   avg_dir = (Dxtoint(buf[5])) + (DDtoint(buf[6]) * 10);

   chill = DDtoint(buf[16]);
   if (buf[21] & 0x20) {
      chill = -1.0 * chill;
   }

#if 0
   pthread_mutex_lock(&current_obs_lock);
   if (((chill - current_obs.temp_out) > 0.5) && (avg > 0 || gust > 0)) {
      chill = -1.0 * chill;
   }
   pthread_mutex_unlock(&current_obs_lock);
#endif

   correct(chill, current_cal.chill_mul, current_cal.chill_offs);
   correct(gust, current_cal.gust_spd_mul, current_cal.gust_spd_offs);

   correct(gust_dir, current_cal.gust_dir_mul, current_cal.gust_dir_offs);
   correct(avg_dir, current_cal.wavg_dir_mul, current_cal.wavg_dir_offs);

   gust_dir = (gust_dir < 0) ? 360 + ((int) gust_dir % 360) : (int) gust_dir % 360;

   correct(avg, current_cal.wavg_spd_mul, current_cal.wavg_spd_offs);
   avg_dir = (avg_dir < 0) ? 360 + ((int) avg_dir % 360) : (int) avg_dir % 360;


   update(current_obs.gust, gust, GUST);
   update(current_obs.wavg, avg, WAVG);
   update(current_obs.gust_dir, gust_dir, GUSTDIR);
   update(current_obs.wavg_dir, avg_dir, WAVGDIR);
   update(current_obs.chill, chill, WCHILL);

   errlog2(9, "Wind gust %g m/s, direction: %g", gust, gust_dir);
   errlog2(9, "Wind avg  %g m/s, direction: %g", avg, avg_dir);
   errlog1(9, "Wind chill %g C", chill);
}
Foam::twoPhaseMixtureThermo::twoPhaseMixtureThermo
(
    const fvMesh& mesh
)
:
    psiThermo(mesh, word::null),
    twoPhaseMixture(mesh, *this),
    thermo1_(NULL),
    thermo2_(NULL)
{
    {
        volScalarField T1(IOobject::groupName("T", phase1Name()), T_);
        T1.write();
    }

    {
        volScalarField T2(IOobject::groupName("T", phase2Name()), T_);
        T2.write();
    }

    thermo1_ = rhoThermo::New(mesh, phase1Name());
    thermo2_ = rhoThermo::New(mesh, phase2Name());

    thermo1_->validate(phase1Name(), "e");
    thermo2_->validate(phase2Name(), "e");

    correct();
}
Пример #12
0
int main(int argc, const char *argv[]){
	int n, i, j, k;
	int count[20]={}, p[20]={};
	char str[16];
	word dict[SIZE], key;
	wordptr list[SIZE];

	for(n=0; gets(str), strcmp(str, "#"); ++n){
		k = strlen(str);
		++count[k];
		strcpy(dict[n].str, str);
		dict[n].len = k;
		dict[n].rank = n;
	}
	for(i=1; i<18; ++i) p[i] = p[i-1]+count[i-1];
	qsort(dict, n, sizeof(word), compar);

	while(gets(str), strcmp(str, "#")){
		strcpy(key.str, str);
		key.len = strlen(str);
		if(bsearch(&key, dict, n, sizeof(word), compar))
			printf("%s is correct\n", str);
		else{
			printf("%s:", str);
			for(i=p[key.len-1], j=0; i<p[key.len+2]; ++i)
				if(correct(str, dict[i].str, key.len-dict[i].len))
					list[j++] = (wordptr) {dict[i].str, dict[i].rank};
			qsort(list, j, sizeof(wordptr), comparRank);
			for(i=0; i<j; ++i) printf(" %s", list[i].str);
			putchar('\n');
		}
	}
	return 0;
}
Пример #13
0
ViMainCorrectionWidget::ViMainCorrectionWidget(QWidget *parent)
    : ViWidget(parent)
{
	mUi = new Ui::ViMainCorrectionWidget();
    mUi->setupUi(this);

	clear();

	mUi->projectLoader->setTypeMode(ViProjectLoader::NoTypes);
	QObject::connect(mUi->projectLoader, SIGNAL(finished()), this, SLOT(showContainer()));
	QObject::connect(mUi->projectLoader, SIGNAL(projectChanged()), this, SLOT(showContainer()));
	QObject::connect(mUi->projectLoader, SIGNAL(projectModeChanged()), this, SLOT(showContainer()));

	//Button
	QObject::connect(mUi->button, SIGNAL(clicked()), this, SLOT(correct()));
	mUi->button->setIcon(ViThemeManager::icon("startprocess"), 40);
	mUi->button->setText("Process");
	mUi->button->setSize(140, 60);

	//Label width
	QString style = "QLabel { width: 140px; min-width: 140px; }";
	mUi->projectLoader->setStyleSheet(style);
	mUi->container->setStyleSheet(style);

	// Correctors
	mUi->correctorComboBox->addItems(mUi->correctionWidget->correctors());
	QObject::connect(mUi->correctorComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCorrector()));
	changeCorrector();

	// Mode
	mUi->modeComboBox->addItems(ViCorrectionMode::modes());
	mUi->modeComboBox->setCurrentText(ViCorrectionMode::defaultMode());
	QObject::connect(mUi->modeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeMode()));
	changeMode();
}
Пример #14
0
Foam::viscosityModels::strainRateFunction::strainRateFunction
(
    const word& name,
    const dictionary& viscosityProperties,
    const volVectorField& U,
    const surfaceScalarField& phi
)
:
    viscosityModel(name, viscosityProperties, U, phi),
    strainRateFunctionCoeffs_
    (
        viscosityProperties.optionalSubDict(typeName + "Coeffs")
    ),
    strainRateFunction_
    (
        Function1<scalar>::New("function", strainRateFunctionCoeffs_)
    ),
    nu_
    (
        IOobject
        (
            name,
            U_.time().timeName(),
            U_.db(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        U_.mesh(),
        dimensionedScalar(name, dimViscosity, 0)
    )
{
    correct();
}
Пример #15
0
bool arlCore::FieldCorrector::correct( vnl_rigid_matrix &T ) const
{
    vnl_rigid_matrix T0;
    if(!correct(T, T0)) return false;
    T.copy(T0);
    return true;
}
Пример #16
0
ErrorCorrectResult ErrorCorrectProcess::process(const SequenceWorkItem& workItem)
{
    ErrorCorrectResult result = correct(workItem);
    if(!result.kmerQC && !result.overlapQC && m_params.printOverlaps)
        std::cout << workItem.read.id << " failed error correction QC\n";
    return result;
}
// Construct from components
Foam::distortionEnergyDiff::distortionEnergyDiff
(
    const tetMotionSolver& mSolver
)
:
    motionDiff(mSolver),
    motionGamma_
    (
        IOobject
        (
            "motionGamma",
            tetMesh().time().timeName(),
            tetMesh()(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        tetMesh(),
        dimensionedScalar("1.0", dimless, 1.0)
    )
{
    exponent_ = readInt(mSolver.lookup("diffusivityExponent"));

    Info << "Value of exponent for distortion energy based motion diffusivity: "
        << exponent_ << endl;


    mSolver.storeTotDisplacement();

    correct();
}
Пример #18
0
void DateFormatRegressionTest::Test5554(void)
{
  UErrorCode status = U_ZERO_ERROR;
  UnicodeString pattern("Z","");
  UnicodeString newfoundland("Canada/Newfoundland", "");
  TimeZone *zone = TimeZone::createTimeZone(newfoundland);
  Calendar *cal = new GregorianCalendar(zone, status);
  SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status);
  if (U_FAILURE(status)) {
    dataerrln("Error constructing SimpleDateFormat");
    delete cal;
    delete sdf;
    return;
  }
  cal->set(2007, 1, 14);
  UDate date = cal->getTime(status);
  if (U_FAILURE(status)) {
    errln("Error getting time to format");
    return;
  };
  sdf->adoptCalendar(cal);
  UnicodeString result;
  UnicodeString correct("-0330", "");
  sdf->format(date, result);
  if (result != correct) {
    errln("\nError: Newfoundland Z of Jan 14, 2007 gave '" + result + "', expected '" + correct + "'");
  }
  delete sdf;
}
Пример #19
0
void main()
{
	char i;
	printf("      欢迎进入电子与信息工程学院2011计算机2班通讯录系统\n");
	printf("1:添加     2:查找       3:修改     4:删除     5:统计     6:打印    7:退出\n");
    check();
	i=getch();
	while(1)
	{
		switch(i)
		{
		   case '1':creat();break;
		   case '2':search();break;
		   case '3':correct();break;
		   case '4':del();break;
		   case '5':printf("通讯录共有%d人!\n",n);	break;	
	       case '6':print();;break;
		   case '7':esc();break;
		default: printf("您的输入有误,请重新输入\n");
		}
		if(i=='7') break;
		printf("1:添加     2:查找       3:修改     4:删除     5:统计     6:打印    7:退出\n");
		i=getch();
	}
	



}
Foam::twoPhaseMixtureThermo::twoPhaseMixtureThermo
(
    const volVectorField& U,
    const surfaceScalarField& phi
)
:
    psiThermo(U.mesh(), word::null),
    twoPhaseMixture(U.mesh(), *this),
    interfaceProperties(alpha1(), U, *this),
    thermo1_(nullptr),
    thermo2_(nullptr)
{
    {
        volScalarField T1(IOobject::groupName("T", phase1Name()), T_);
        T1.write();
    }

    {
        volScalarField T2(IOobject::groupName("T", phase2Name()), T_);
        T2.write();
    }

    thermo1_ = rhoThermo::New(U.mesh(), phase1Name());
    thermo2_ = rhoThermo::New(U.mesh(), phase2Name());

    // thermo1_->validate(phase1Name(), "e");
    // thermo2_->validate(phase2Name(), "e");

    correct();
}
Пример #21
0
KalmanResult2D KalmanFilter2D::update( KalmanInput2D& input )
{
	predict();
	auto estimation = correct(input);
	lastState = estimation;
	return estimation;
}
void virtual_random_access_iteratorTest::testString()
{
	std::string source[100];
	size_t num = sizeof(source) / sizeof(source[0]);
	for (size_t i = 0; i < num; ++i)
	{
		std::ostringstream ostr;
		ostr << "stringnumber:" << i;
		source[i] = ostr.str();
	}
	std::random_shuffle(source, source + num);
	{
		std::vector<std::string> correct(source, source + num);
		std::vector<std::string> test(source, source + num);
		std::sort(correct.begin(), correct.end());
		vsorts(test.begin(), test.end());
		CPPUNIT_ASSERT(correct == test);
	}
	{
		std::string *correct = new std::string[num];
		std::string *test = new std::string[num];
		std::copy(source, source + num, correct);
		std::copy(source, source + num, test);
		std::sort(correct, correct + num);
		vsorts(test, test + num);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
		delete [] correct;
		delete [] test;
	}
}
Пример #23
0
void
EKFLocalization::setPos( float x, float y, float t, const Ice::Current& c )
{
	//cerr<<"recv ["<<x<<","<<y<<","<<toDegrees(t*M_PI)<<"]"<<endl;

	dbgx = x;
	dbgy = y;
	dbgt = t*M_PI;

	MatrixCM s(3,1), P(3,3);

	s.sete(0,0,dbgx);
	s.sete(1,0,dbgy);
	s.sete(2,0,dbgt);

	P.identity(3);
	P.sete(0,0, 1000.0*1000.0);
	P.sete(1,1, 1000.0*1000.0);
	P.sete(2,2, 10.0*10.0);
	ekf.filter->restart(s,P);


	_GoalDetector->step();
	_LineDetector->step();

	correct();
}
Пример #24
0
/******************************************************************************
 Program to test the correction module.  Reads in input params from the user
 and calucate the root using the methods in rootfinding module.
 int main(int argv, char* argv[])
 Where:
 int argv        - The number of command line parameters
 char *argv[]    - An array of pointers to the parameters
 returns: in     - 0 for success, non-zero for error
 errors:         - Error message printed to stderr and exits with an error
 code
 ******************************************************************************/
int main(int argc, char *argv[])
{
	/* local variables */
	int numItem = 0;
	int correctedValue;
	double actualVoltage;
	double actualValue;
	char *buffer;
	char *token;
	FILE *inputFIle;


	inputFIle = fopen(argv[1], "r");
	buffer = creatBuffer(BUFSIZE);
	/*read stdin line by line*/
	while(fgets(buffer, BUFSIZE, inputFIle) != NULL)
	{
		if(strcmp(buffer,"\n") && strcmp(buffer,"\r\n"))
		{
			numItem++;
			token = strtok(buffer, " ");
			/* reading token separated by spaces */
			actualVoltage = atof(token);
			token = strtok(NULL, " ");
			actualValue = atof(token);
			correctedValue = correct(actualValue);
			/* print to stdout */
			fprintf(stdout, "%f ", actualVoltage);
			fprintf(stdout, "%d\n", correctedValue);
		}
	}

	return NO_ERR;
}
Пример #25
0
/*
 * Guess a single keybyte
 */
static int doRound(PTW_tableentry sortedtable[][n], int keybyte, int fixat, uint8_t fixvalue, int * searchborders, uint8_t * key, int keylen, PTW_attackstate * state, uint8_t sum, int * strongbytes) {
	int i;
	uint8_t tmp;
	if (keybyte == keylen) {
		return correct(state, key, keylen);
	} else if (strongbytes[keybyte] == 1) {
		// printf("assuming byte %d to be strong\n", keybyte);
		tmp = 3 + keybyte;
		for (i = keybyte-1; i >= 1; i--) {
			tmp += 3 + key[i] + i;
			key[keybyte] = 256-tmp;
			if(doRound(sortedtable, keybyte+1, fixat, fixvalue, searchborders, key, keylen, state, (256-tmp+sum)%256, strongbytes) == 1) {
				printf("hit with strongbyte for keybyte %d\n", keybyte);
				return 1;
			}
		}
		return 0;
	} else if (keybyte == fixat) {
		key[keybyte] = fixvalue-sum;
		return doRound(sortedtable, keybyte+1, fixat, fixvalue, searchborders, key, keylen, state, fixvalue, strongbytes);
	} else {
		for (i = 0; i < searchborders[keybyte]; i++) {
			key[keybyte] = sortedtable[keybyte][i].b - sum;
			if (doRound(sortedtable, keybyte+1, fixat, fixvalue, searchborders, key, keylen, state, sortedtable[keybyte][i].b, strongbytes) == 1) {
				return 1;
			}
		}
		return 0;
	}
}
void virtual_random_access_iteratorTest::testInt()
{
	int source[100];
	size_t num = sizeof(source) / sizeof(source[0]);
	for (size_t i = 0; i < num; ++i)
	{
		source[i] = i;
	}
	std::random_shuffle(source, source + num);
	{
		std::vector<int> correct(source, source + num);
		std::vector<int> test(source, source + num);
		std::sort(correct.begin(), correct.end());
		vsorti(test.begin(), test.end());
		CPPUNIT_ASSERT(correct == test);
	}
	{
		int *correct = new int[num];
		int *test = new int[num];
		std::copy(source, source + num, correct);
		std::copy(source, source + num, test);
		std::sort(correct, correct + num);
		vsorti(test, test + num);
		CPPUNIT_ASSERT(std::equal(correct, correct + num, test));
		delete [] correct;
		delete [] test;
	}
}
Пример #27
0
const InfInt& InfInt::operator/=(const InfInt& rhs)
{
	if (rhs == zero)
	{
#ifdef INFINT_USE_EXCEPTIONS
		throw InfIntException("division by zero");
#else
		std::cerr << "Division by zero!" << std::endl;
		return *this;
#endif
	}
	InfInt R, D = (rhs.pos ? rhs : -rhs), N = (pos ? *this : -*this);
	bool oldpos = pos;
	val.clear();
	val.resize(N.val.size(), 0);
	for (int i = (int)N.val.size() - 1; i >= 0; --i)
	{
		R.val.insert(R.val.begin(), (ELEM_TYPE)0);
		R.val[0] = N.val[i];
		R.correct(true);
		ELEM_TYPE cnt = dInR(R, D);
		R -= D * cnt;
		val[i] += cnt;
	}
	correct();
	pos = (val.size() == 1 && val[0] == 0) ? true : (oldpos == rhs.pos);
	return *this;
}
Пример #28
0
	void
	TextOutput::finished(int tests, const Time& time)
	{
		_stream	<< "Total: " << tests << " tests, "
				<< correct(tests, _total_errors) << "% correct"
				<< " in " << time << " seconds" << endl;
	}
Пример #29
0
void InfInt::fromString(const std::string& s)
{//PROFILED_SCOPE
	pos = true;
	val.clear();
	// TODO use resize
	val.reserve(s.size() / DIGIT_COUNT + 1);
	int i = (int)s.size() - DIGIT_COUNT;
	for (; i >= 0; i -= DIGIT_COUNT)
	{
		val.push_back(atoi(s.substr(i, DIGIT_COUNT).c_str()));
	}
	if (i > -DIGIT_COUNT)
	{
		std::string ss = s.substr(0, i + DIGIT_COUNT);
		if (ss.size() == 1 && ss[0] == '-')
		{
			pos = false;
		}
		else
		{
			val.push_back(atoi(ss.c_str()));
		}
	}
	if (val.back() < 0)
	{
		val.back() = -val.back();
		pos = false;
	}
	correct(true);
}
Пример #30
-1
void ui::line(int x0, int y0, int x1, int y1, unsigned char color)
{
	if(y0==y1)
	{
		if(!correct(x0, y0, x1, y1, clipping))
			return;
		rmset(ptr(x0, y0), color, x1-x0+1);
	}
	else if(x0==x1)
	{
		if(!correct(x0, y0, x1, y1, clipping))
			return;
		linev(ptr(x0, y0), scanline, y1-y0+1, color);
	}
	else
	{
		int dx = iabs(x1-x0), sx = x0<x1 ? 1 : -1;
		int dy = -iabs(y1-y0), sy = y0<y1 ? 1 : -1;
		int err = dx+dy, e2;
		for(;;)
		{
			pixel(x0, y0, color);
			if(x0==x1 && y0==y1)
				break;
			e2 = 2*err;
			if(e2 >= dy) { err += dy; x0 += sx; }
			if(e2 <= dx) { err += dx; y0 += sy; }
		}
	}
}