Exemplo n.º 1
0
Arquivo: LSSS.c Projeto: pigeon119/ABE
int makeMSP_v3(MSP* msp, attr_tree_node* node){
   int** matrix = msp -> matrix;
   char** label = msp -> label;
   int cols = msp -> cols;
   int rows = msp -> rows;

   attr_tree_node* queue[100] = {0};
   int* vectors [100] = {0};
   int write_i = -1;
   int read_i = -1;
   int* v = calloc(cols, sizeof(int));
   v[0] = 1;

   queue[++write_i] = node;
   vectors[write_i] = v;

   int count = 1;
   int index = 0;

   while( read_i < write_i ){

      attr_tree_node* node = queue[++read_i];
      int* v = vectors[read_i];

      if( node -> node_type == ATTR_NODE_OR ){
	 int i = 0;
         for( i; i < 2; i++){
	    queue[++write_i] = (node -> subnode)[i];
	    vectors[write_i] = v;
	 }
      }
      else if( node -> node_type == ATTR_NODE_AND ){
         int* l_v = calloc(cols, sizeof(int));
         int* r_v = calloc(cols, sizeof(int));
	 memcpy(l_v, v, cols*sizeof(int));
	 l_v[count] = 1;
	 {
	    int i = 0;
	    for(i; i < cols; i++)
	       r_v[i] = v[i] - l_v[i];
	 }
	 count++;

	 queue[++write_i] = (node -> subnode)[0];
	 vectors[write_i] = l_v;

	 queue[++write_i] = (node -> subnode)[1];
	 vectors[write_i] = r_v;
      }
      else if( node -> node_type == ATTR_NODE_THRESHOLD ){
	 int i = 0;
	 for( i; i < node->num_subnodes; i++ ){
            int* l_v = calloc(cols, sizeof(int));
	    memcpy(l_v, v, cols*sizeof(int));
            int j = 0;
	    for( j; j < node->threshold_k - 1; j++){
	       l_v[count+j] = power(i+1, j+1);
	       //printf("power:%d\n", power(i+1, j+1));
	    }

	    queue[++write_i] = (node -> subnode)[i];
	    vectors[write_i] = l_v;
            //free(l_v);
	 }
	 count = count + (node->threshold_k) - 1;

      }
      else if( node -> node_type == ATTR_NODE_LEAF){
         memcpy( matrix[index], v, cols*sizeof(int) );
         label[index] = node->attribute;
         index++;
      }

   }
}
Exemplo n.º 2
0
inline
time_duration
str_from_delimited_time_duration(const std::basic_string<char_type>& s)
{
    unsigned short min=0, sec =0;
    int hour =0;
    bool is_neg = (s.at(0) == '-');
    lslboost::int64_t fs=0;
    int pos = 0;

    typedef typename std::basic_string<char_type>::traits_type traits_type;
    typedef lslboost::char_separator<char_type, traits_type> char_separator_type;
    typedef lslboost::tokenizer<char_separator_type,
            typename std::basic_string<char_type>::const_iterator,
            std::basic_string<char_type> > tokenizer;
    typedef typename lslboost::tokenizer<char_separator_type,
            typename std::basic_string<char_type>::const_iterator,
            typename std::basic_string<char_type> >::iterator tokenizer_iterator;

    char_type sep_chars[5] = {'-',':',',','.'};
    char_separator_type sep(sep_chars);
    tokenizer tok(s,sep);
    for(tokenizer_iterator beg=tok.begin(); beg!=tok.end(); ++beg) {
        switch(pos) {
        case 0: {
            hour = lslboost::lexical_cast<int>(*beg);
            break;
        }
        case 1: {
            min = lslboost::lexical_cast<unsigned short>(*beg);
            break;
        }
        case 2: {
            sec = lslboost::lexical_cast<unsigned short>(*beg);
            break;
        };
        case 3: {
            int digits = static_cast<int>(beg->length());
            //Works around a bug in MSVC 6 library that does not support
            //operator>> thus meaning lexical_cast will fail to compile.
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
            // msvc wouldn't compile 'time_duration::num_fractional_digits()'
            // (required template argument list) as a workaround a temp
            // time_duration object was used
            time_duration td(hour,min,sec,fs);
            int precision = td.num_fractional_digits();
            // _atoi64 is an MS specific function
            if(digits >= precision) {
                // drop excess digits
                fs = _atoi64(beg->substr(0, precision).c_str());
            }
            else {
                fs = _atoi64(beg->c_str());
            }
#else
            int precision = time_duration::num_fractional_digits();
            if(digits >= precision) {
                // drop excess digits
                fs = lslboost::lexical_cast<lslboost::int64_t>(beg->substr(0, precision));
            }
            else {
                fs = lslboost::lexical_cast<lslboost::int64_t>(*beg);
            }
#endif
            if(digits < precision) {
                // trailing zeros get dropped from the string,
                // "1:01:01.1" would yield .000001 instead of .100000
                // the power() compensates for the missing decimal places
                fs *= power(10, precision - digits);
            }

            break;
        }
        default:
            break;
        }//switch
        pos++;
    }
    if(is_neg) {
        return -time_duration(hour, min, sec, fs);
    }
    else {
        return time_duration(hour, min, sec, fs);
    }
}
Exemplo n.º 3
0
mp_integer bv_arithmetict::pack() const
{
  if(value>=0) return value;
  return value+power(2, spec.width);
}
Exemplo n.º 4
0
void main()
{
	int x=5,y=2;
	printf("%d\n",power(x,y));
	printf("%d\n",poweropti(5,4));
}
Exemplo n.º 5
0
// returns a pointer to the loaded bitmap
// only supports 24-bit (and 32-bit?) images
wBitmap* wLoadBitmap(char *filename)
{
	FILE *bmpFile;
	wBitmap *bmp;
	int i;
	int fileLineSize, memLineSize, fileScanLines, memScanLines, dataSize;
	int pad, generic;
	BYTE *line;

	bmp = (wBitmap*)malloc(sizeof(wBitmap));
	memset(bmp, 0, sizeof(wBitmap));
	bmp->name = filename;

	bmpFile = fopen(filename, "rb");
	if (bmpFile)
	{
		printf("Loading bitmap %s\n", filename);

		fread(&bmp->Header, sizeof(bmp->Header), 1, bmpFile);
		fread(&bmp->Info, sizeof(bmp->Info), 1, bmpFile);

		// only supports 24-bit+ color bitmaps
		if (bmp->Info.biBitCount < 24)
		{
			printf("cannot load %s:  bitmap is less than 24-bit color\n", filename);
			free(bmp);
			return NULL;
		}
		if (bmp->Info.biCompression)
		{
			printf("cannot load %s:  bitmap is compressed\n", filename);
			free(bmp);
			return NULL;
		}

		fileLineSize = bmp->Info.biWidth*bmp->Info.biBitCount / 8;
		pad = 4 - fileLineSize % 4;
		if (pad == 4)
			pad = 0;
		fileScanLines = bmp->Info.biHeight;

		// check to make sure that image is 2^x * 2^y
		// image in memory can be 2^x * 2^y even if disk file isn't, but there will be blank pixels
		for (i = 1; i <= MAX_EXP; i++)
		{
			generic = (int)power(2, i);
			if (generic >= bmp->Info.biWidth)
			{
				bmp->Info.biWidth = generic;
				break;
			}
		}
		if (i > MAX_EXP)
		{
			printf("cannot load %s:  bitmap is too large\n", filename);
			free(bmp);
			return NULL;
		}
		for (i = 1; i <= MAX_EXP; i++)
		{
			generic = power(2, i);
			if (generic >= bmp->Info.biHeight)
			{
				bmp->Info.biHeight = generic;
				break;
			}
		}
		if (i > MAX_EXP)
		{
			printf("cannot load %s:  bitmap is too large\n", filename);
			free(bmp);
			return NULL;
		}

		memLineSize = bmp->Info.biWidth*bmp->Info.biBitCount / 8;
		memScanLines = bmp->Info.biHeight;
		dataSize = memLineSize*memScanLines;
		bmp->pixels = (BYTE*)malloc(dataSize);
		memset(bmp->pixels, 0, dataSize);

		// end 2^n check
		/*		printf("image is %i by %i", fileLineSize*8/bmp->Info.biBitCount, fileScanLines);
		if ( fileLineSize != memLineSize || fileScanLines != memScanLines )
		printf(", expanded to %i by %i", memLineSize*8/bmp->Info.biBitCount, memScanLines);
		printf("\n");
		*/

		// bmps are stored last line first
		fseek(bmpFile, bmp->Header.bfOffBits, 0);
		line = bmp->pixels + (fileScanLines - 1)*memLineSize;
		for (i = 0; i < fileScanLines; i++)
		{
			fread(line, fileLineSize, 1, bmpFile);
			// lines are padded to be 32-bit divisible
			if (pad)
				fread(&generic, pad, 1, bmpFile);
			line -= memLineSize;
		}

		// need to switch red and blue for opengl
		if (TRUE)
		{
			for (i = 0; i < fileScanLines*memLineSize; i += 3)
			{
				generic = bmp->pixels[i];
				bmp->pixels[i] = bmp->pixels[i + 2];
				bmp->pixels[i + 2] = generic;
			}
		}
		return bmp;
	}
	else
	{
		printf("cannot load %s:  no such file or file I/O error\n", filename);
		return NULL;
	}
}
Exemplo n.º 6
0
BaseIF* makeGeometry(Box&      a_domain,
                     RealVect& a_origin,
                     Real&     a_dx)
{
    RealVect center;
    RealVect radii;
    bool     insideRegular;

    // parse input file
    ParmParse pp;

    Vector<int> n_cell(SpaceDim);
    pp.getarr("n_cell",n_cell,0,SpaceDim);

    CH_assert(n_cell.size() == SpaceDim);

    IntVect lo = IntVect::Zero;
    IntVect hi;

    for (int ivec = 0; ivec < SpaceDim; ivec++)
    {
        if (n_cell[ivec] <= 0)
        {
            pout() << "Bogus number of cells input = " << n_cell[ivec];
            exit(1);
        }

        hi[ivec] = n_cell[ivec] - 1;
    }

    a_domain.setSmall(lo);
    a_domain.setBig(hi);

    Vector<Real> prob_lo(SpaceDim,1.0);
    Real prob_hi;

    pp.getarr("prob_lo",prob_lo,0,SpaceDim);
    pp.get("prob_hi",prob_hi);

    a_dx = (prob_hi-prob_lo[0])/n_cell[0];

    for (int idir = 0; idir < SpaceDim; idir++)
    {
        a_origin[idir] = prob_lo[idir];
    }

    // ParmParse doesn't get RealVects, so work-around with Vector<Real>
    Vector<Real> vectorCenter;
    pp.getarr("center",vectorCenter,0,SpaceDim);

    for (int idir = 0; idir < SpaceDim; idir++)
    {
        center[idir] = vectorCenter[idir];
    }

    Vector<Real> vectorRadii;
    pp.getarr("radii",vectorRadii,0,SpaceDim);

    for (int idir = 0; idir < SpaceDim; idir++)
    {
        radii[idir] = vectorRadii[idir];
    }

    int halfTurns;
    pp.get("halfturns",halfTurns);

    // Parm Parse doesn't get bools, so work-around with int
    int intInsideRegular;
    pp.get("insideRegular",intInsideRegular);

    if (intInsideRegular != 0) insideRegular = true;
    if (intInsideRegular == 0) insideRegular = false;

    IntVect zero=IntVect::Zero;
    bool inside = true;
    EllipsoidIF ellipsoid(radii,center,inside);

    Real coef = halfTurns / 2.0;
    IntVect power(D_DECL(1,0,0));

    Vector<PolyTerm> term;
    term.resize(1);
    term[0].coef   = coef;
    term[0].powers = power;

    PolynomialIF rotate(term,inside);

    LatheIF implicit(ellipsoid,rotate,center,insideRegular);

    RealVect vectDx = RealVect::Unit;
    vectDx *= a_dx;

    GeometryShop workshop(implicit,0,vectDx);

    // This generates the new EBIS
    EBIndexSpace* ebisPtr = Chombo_EBIS::instance();
    ebisPtr->define(a_domain,a_origin,a_dx,workshop);

    return implicit.newImplicitFunction();
}
Exemplo n.º 7
0
static ex Li2_series(const ex &x, const relational &rel, int order, unsigned options)
{
	const ex x_pt = x.subs(rel, subs_options::no_pattern);
	if (x_pt.info(info_flags::numeric)) {
		// First special case: x==0 (derivatives have poles)
		if (x_pt.is_zero()) {
			// method:
			// The problem is that in d/dx Li2(x==0) == -log(1-x)/x we cannot 
			// simply substitute x==0.  The limit, however, exists: it is 1.
			// We also know all higher derivatives' limits:
			// (d/dx)^n Li2(x) == n!/n^2.
			// So the primitive series expansion is
			// Li2(x==0) == x + x^2/4 + x^3/9 + ...
			// and so on.
			// We first construct such a primitive series expansion manually in
			// a dummy symbol s and then insert the argument's series expansion
			// for s.  Reexpanding the resulting series returns the desired
			// result.
			const symbol s;
			ex ser;
			// manually construct the primitive expansion
			for (int i=1; i<order; ++i)
				ser += pow(s,i) / pow(numeric(i), *_num2_p);
			// substitute the argument's series expansion
			ser = ser.subs(s==x.series(rel, order), subs_options::no_pattern);
			// maybe that was terminating, so add a proper order term
			epvector nseq { expair(Order(_ex1), order) };
			ser += pseries(rel, std::move(nseq));
			// reexpanding it will collapse the series again
			return ser.series(rel, order);
			// NB: Of course, this still does not allow us to compute anything
			// like sin(Li2(x)).series(x==0,2), since then this code here is
			// not reached and the derivative of sin(Li2(x)) doesn't allow the
			// substitution x==0.  Probably limits *are* needed for the general
			// cases.  In case L'Hospital's rule is implemented for limits and
			// basic::series() takes care of this, this whole block is probably
			// obsolete!
		}
		// second special case: x==1 (branch point)
		if (x_pt.is_equal(_ex1)) {
			// method:
			// construct series manually in a dummy symbol s
			const symbol s;
			ex ser = zeta(_ex2);
			// manually construct the primitive expansion
			for (int i=1; i<order; ++i)
				ser += pow(1-s,i) * (numeric(1,i)*(I*Pi+log(s-1)) - numeric(1,i*i));
			// substitute the argument's series expansion
			ser = ser.subs(s==x.series(rel, order), subs_options::no_pattern);
			// maybe that was terminating, so add a proper order term
			epvector nseq { expair(Order(_ex1), order) };
			ser += pseries(rel, std::move(nseq));
			// reexpanding it will collapse the series again
			return ser.series(rel, order);
		}
		// third special case: x real, >=1 (branch cut)
		if (!(options & series_options::suppress_branchcut) &&
			ex_to<numeric>(x_pt).is_real() && ex_to<numeric>(x_pt)>1) {
			// method:
			// This is the branch cut: assemble the primitive series manually
			// and then add the corresponding complex step function.
			const symbol &s = ex_to<symbol>(rel.lhs());
			const ex point = rel.rhs();
			const symbol foo;
			epvector seq;
			// zeroth order term:
			seq.push_back(expair(Li2(x_pt), _ex0));
			// compute the intermediate terms:
			ex replarg = series(Li2(x), s==foo, order);
			for (size_t i=1; i<replarg.nops()-1; ++i)
				seq.push_back(expair((replarg.op(i)/power(s-foo,i)).series(foo==point,1,options).op(0).subs(foo==s, subs_options::no_pattern),i));
			// append an order term:
			seq.push_back(expair(Order(_ex1), replarg.nops()-1));
			return pseries(rel, std::move(seq));
		}
	}
	// all other cases should be safe, by now:
	throw do_taylor();  // caught by function::series()
}
Exemplo n.º 8
0
unsigned long long int power(unsigned long long int a,unsigned long long int b) { if(b==0) return 1; unsigned long long int x=power(a,b/2);
return (((x*x)%mod)*((b&1)?a:1))%mod;}
Exemplo n.º 9
0
//TODO remove pModel
CEvaluationNode* CDerive::deriveBranch(const CEvaluationNode* node, const CCopasiObject * pObject,
                                       std::vector<const CEvaluationNode*>& env,
                                       //std::vector<const CCopasiObject*>& objenv,
                                       const CEvaluationTree* pTree,
                                       bool simplify)
{
  CEvaluationNode * newNode = NULL;

  const CEvaluationNodeOperator * pENO = dynamic_cast<const CEvaluationNodeOperator*>(node);

  if (pENO)
    {
      if (!pENO->getLeft() || !pENO->getRight()) return NULL;

      CEvaluationNode * pLeftDeriv = deriveBranch(pENO->getLeft(), pObject, env, pTree, simplify);

      if (!pLeftDeriv) return NULL;

      CEvaluationNode * pRightDeriv = deriveBranch(pENO->getRight(), pObject, env, pTree, simplify);

      if (!pRightDeriv) {delete pLeftDeriv; return NULL;}

      // we now know that derivations of the left and right branch exist

      switch ((CEvaluationNodeOperator::SubType) CEvaluationNode::subType(pENO->getType()))
        {
          case CEvaluationNodeOperator::MULTIPLY:
          {
            CEvaluationNode * pLeftCopy = copyBranch_var2obj(pENO->getLeft(), env);
            CEvaluationNode * pRightCopy = copyBranch_var2obj(pENO->getRight(), env);

            CEvaluationNode * tmpNode1 = multiply(pRightCopy, pLeftDeriv, simplify);
            CEvaluationNode * tmpNode2 = multiply(pRightDeriv, pLeftCopy, simplify);

            return add(tmpNode1, tmpNode2, simplify);
          }
          break;

          case CEvaluationNodeOperator::DIVIDE:
          {
            CEvaluationNode * pLeftCopy = copyBranch_var2obj(pENO->getLeft(), env);
            CEvaluationNode * pRightCopy = copyBranch_var2obj(pENO->getRight(), env);

            //numerator
            CEvaluationNode * tmpNode1 = multiply(pRightCopy, pLeftDeriv, simplify);
            CEvaluationNode * tmpNode2 = multiply(pRightDeriv, pLeftCopy, simplify);

            CEvaluationNode * minusNode = subtract(tmpNode1, tmpNode2, simplify);

            minusNode->compile(NULL);

            //denominator
            CEvaluationNode * powerNode = power(copyBranch_var2obj(pENO->getRight(), env),
                                                new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "2"),
                                                simplify);

            return divide(minusNode, powerNode, simplify);
          }
          break;

          case CEvaluationNodeOperator::PLUS:

            return add(pLeftDeriv, pRightDeriv, simplify);
            break;

          case CEvaluationNodeOperator::MINUS:

            return subtract(pLeftDeriv, pRightDeriv, simplify);
            break;

          case CEvaluationNodeOperator::POWER:
          {
            // b-1
            CEvaluationNode * tmpNode = subtract(copyBranch_var2obj(pENO->getRight(), env),
                                                 new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "1"),
                                                 simplify);

            // a^(b-1)
            CEvaluationNode * powerNode = power(copyBranch_var2obj(pENO->getLeft(), env), tmpNode, simplify);

            // b*a'
            tmpNode = multiply(copyBranch_var2obj(pENO->getRight(), env),
                               pLeftDeriv, simplify);

            // ln a
            CEvaluationNodeFunction * funcNode = new CEvaluationNodeFunction(CEvaluationNodeFunction::LOG, "ln");
            funcNode->addChild(copyBranch_var2obj(pENO->getLeft(), env)); // add a

            // a * b' * ln a
            CEvaluationNode * tmpNode2 = multiply(copyBranch_var2obj(pENO->getLeft(), env),
                                                  multiply(pRightDeriv, funcNode, simplify),
                                                  simplify);

            // b*a + a*b * ln a
            CEvaluationNode * plusNode = add(tmpNode, tmpNode2, simplify);

            // a^(b-1)*(b*a + a*b * ln a)
            return multiply(powerNode, plusNode, simplify);
          }
          break;

          default:
            break;
        }
    }

  const CEvaluationNodeVariable * pENV = dynamic_cast<const CEvaluationNodeVariable*>(node);

  if (pENV)
    {
      if (!env[pENV->getIndex()])
        return NULL;

      //basically just expand the tree.
      return deriveBranch(env[pENV->getIndex()], pObject, env, pTree, simplify);
    }

  const CEvaluationNodeNumber * pENN = dynamic_cast<const CEvaluationNodeNumber*>(node);

  if (pENN)
    {
      newNode = new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "0");
      return newNode;
    }

  const CEvaluationNodeObject *pENObj = dynamic_cast<const CEvaluationNodeObject*>(node);

  if (pENObj)
    {
      //first check whether the object is the derivation variable
      if (pObject->getCN() == pENObj->getObjectCN())
        {
          //std::cout << "*";
          return new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "1");
        }

      //now we need to check if we know something about the object so that it needs to be expanded
      const CCopasiObject * tmpObj = (const CCopasiObject *)pENObj->getObjectInterfacePtr();

      if (!tmpObj)
        return NULL;

      //object is a concentration?
      if (tmpObj->getObjectName() == "Concentration")
        {
          //std::cout << "Concentration found" << std::endl;
          //In this context, the concentration is expanded as "amount of substance/volume"
          std::string tmpstr = tmpObj->getObjectParent() ? "<" + tmpObj->getObjectParent()->getCN() + ",Reference=ParticleNumber>" : "<>";
          CEvaluationNodeObject* amount = new CEvaluationNodeObject(CEvaluationNodeObject::CN, tmpstr);
          amount->compile(pTree);

          tmpstr = tmpObj->getObjectAncestor("Compartment") ? "<" + tmpObj->getObjectAncestor("Compartment")->getCN() + ",Reference=Volume>"  : "<>";
          CEvaluationNodeObject* volume = new CEvaluationNodeObject(CEvaluationNodeObject::CN, tmpstr);
          volume->compile(pTree);
          CEvaluationNodeObject* volume2 = new CEvaluationNodeObject(CEvaluationNodeObject::CN, tmpstr); //we need this node twice
          volume2->compile(pTree);

          CEvaluationNode* damount = deriveBranch(amount, pObject, env, pTree, simplify);
          CEvaluationNode* dvolume = deriveBranch(volume, pObject, env, pTree, simplify);

          // A / V - A*V /V^2
          return
            subtract(divide(damount, volume, simplify),
                     divide(multiply(amount, dvolume, simplify),
                            power(volume2, new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "2"), simplify),
                            simplify),
                     simplify);
        }

      //TODO:
      //object is an object with an assignment
      //object is dependent species
      //object is a reaction rate

      // otherwise return 0.
      return new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "0");
    }

  const CEvaluationNodeCall  *pENCall = dynamic_cast<const CEvaluationNodeCall*>(node);

  if (pENCall)
    {

      //is it a function?
      const CFunction * tmpFunction = dynamic_cast<const CFunction*>(pENCall->getCalledTree());

//     const std::vector<CEvaluationNode *> getListOfChildNodes() const {return mCallNodes;}

      //create call environment for the called function
      std::vector<const CEvaluationNode*> subenv;
      size_t i, imax = pENCall->getListOfChildNodes().size();
      subenv.resize(imax);

      for (i = 0; i < imax; ++i)
        {
          CEvaluationNode* tmpnode = copyBranch_var2obj(pENCall->getListOfChildNodes()[i], env);
          compileTree(tmpnode, pTree);
          subenv[i] = tmpnode;
        }

      return deriveBranch(pENCall->getCalledTree()->getRoot(), pObject,
                          subenv,
                          pTree, simplify);
    }

  return newNode;
}
Exemplo n.º 10
0
int load_bmp(char *file, struct image **res_image)
{
    FILE *fp;
    struct bitmap_file_header hdr;
    struct bitmap_info_header infohdr;
    struct image *img;
    int num_pixels;
    int j, pad;


    if (!res_image) {
        printf("**res_image pointer to pointer is not initialized!!!\n");
        errno = -EAGAIN;
        return -EAGAIN;
    }
    
    img = (struct image *) malloc(sizeof(*img));
    if (!img)
        return errno;

    *res_image = img;

    /* open the file */
    if ((fp = fopen(file,"r")) == NULL)
        return errno;

    /* Read bitmap header */
    if (fread(&hdr, sizeof(hdr), 1, fp) != 1)
        goto error;

    /* Check format */
    if (hdr.id[0] != 'B' || hdr.id[1] != 'M') {
        printf("%s is not a bitmap file in windows-format.\n", file);
        errno = -EAGAIN;
        goto error;
    }

    /* Read bitmap info header */
    if (fread(&infohdr, sizeof(infohdr), 1, fp) != 1)
        goto error;

    if (infohdr.color_planes != 1 || infohdr.bits_per_pixel != 24 ||
        infohdr.compression != 0 || infohdr.num_colors != 0 ||
        infohdr.important_colors != 0) {
        printf("The bmp image is not in a supported format!\n");
        printf("The supported format requires: colorplanes == 0, 24 bits per "
               "pixel, no compression, num-colors == 0 and important-colors == 0\n");
        printf("But we got: colorplanes %u bits per pixel %u compression %u "
               "num-colors %u important-colors %u\n", infohdr.color_planes,
               infohdr.bits_per_pixel, infohdr.compression, infohdr.num_colors,
               infohdr.important_colors);
        errno = -EAGAIN;
        goto error;
    }

    if (infohdr.num_colors == 0)
        /* This means, the number of colors in the color-pallette is 2**bits_per_pixel */
        infohdr.num_colors = power(2, infohdr.bits_per_pixel);

    img->width = infohdr.width;
    img->height = infohdr.height;
    img->hor_res = infohdr.hor_res;
    img->ver_res = infohdr.ver_res;

    /* Now, move the pointer to the pixel-array */
    if (fseek(fp, infohdr.hdrsize - sizeof(infohdr), SEEK_CUR))
        goto error;

    num_pixels = img->width * img->height;
    img->pixels = (struct pixel *) malloc(sizeof(struct pixel)*num_pixels);

    if (!img->pixels)
        goto error;

    pad = (4 - (img->width * 3) % 4) % 4;
    for (j = 0; j < img->height; j++) {
        if (fread(&img->pixels[j*img->width], 3, img->width, fp) != img->width)
            goto error;

        if (fseek(fp, pad, SEEK_CUR))
            goto error;
    }

    fclose(fp);
    return 0;

error:
    fclose(fp);
    return errno;
}
Exemplo n.º 11
0
 void power_mpz(elem &result, elem a, mpz_ptr n) const
 {
   int n1 = static_cast<int>(mpz_fdiv_ui(n, p1));
   power(result,a,n1);
 }
Exemplo n.º 12
0
void Tester_68k::testSbcd() {
    u16 opcode;

    //MOVE.L    #$12345689, D1
    //MOVE.L    #$f745ff78, D2
    //MOVE #$4, CCR
    //SBCD D2, D1
    setUp();
    opcode = 0x8100 | (1 << 9) | 2;
    addWord(opcode);
    addWord(0xffff);
    power();
    setCCR(0x4);
    setRegD(1, 0x12345689);
    setRegD(2, 0xf745ff78);
    process();
    check("SBCD D2, D1");

    //MOVE.L    #$12345605, D1
    //MOVE.L    #$f745ff05, D2
    //MOVE #$4, CCR
    //SBCD D2, D1
    setUp();
    opcode = 0x8100 | (1 << 9) | 2;
    addWord(opcode);
    addWord(0xffff);
    power();
    setCCR(0x4);
    setRegD(1, 0x123456ff);
    setRegD(2, 0xf745ffff);
    process();
    check("SBCD D2, D1 zero");

    //MOVE.L    #$12345634, D1
    //MOVE.L    #$f745ff45, D2
    //MOVE #$10, CCR
    //SBCD D2, D1
    setUp();
    opcode = 0x8100 | (1 << 9) | 2;
    addWord(opcode);
    addWord(0xffff);
    power();
    setCCR(0x10);
    setRegD(1, 0x12345634);
    setRegD(2, 0xf745ff45);
    process();
    check("SBCD D2, D1 neg");

    //MOVE.L    #$12345634, D1
    //MOVE.L    #$f745ff45, D2
    //MOVE #$10, CCR
    //SBCD D2, D1
    setUp();
    opcode = 0x8100 | (1 << 9) | 2;
    addWord(opcode);
    addWord(0xffff);
    power();
    setCCR(0x10);
    setRegD(1, 0x123456a9);
    setRegD(2, 0xf745ffff);
    process();
    check("SBCD D2, D1 overflow");

    //MOVE.L    #$3001, A1
    //MOVE.L    #$4001, A2
    //MOVE.B    #$a2, $3000
    //MOVE.B    #$19, $4000
    //MOVE #$10, CCR
    //SBCD -(A2), -(A1)
    //MOVE.B    $3000, D1
    //MOVE.B    $4000, D2
    setUp();
    opcode = 0x8100 | (1 << 9) | (1 << 3) | 2;
    addWord(opcode);
    addWord(0xffff);
    power();
    memoryblock.write(0x3000, 0xa2);
    memoryblock.write(0x4000, 0x19);
    setCCR(0x10);
    setRegA(1, 0x3001);
    setRegA(2, 0x4001);
    process();
    check("SBCD -(A2), -(A1)");
}
Exemplo n.º 13
0
ui get_head_num(ull n, ui d)
{
    return n / power(10, d - 2);
}
Exemplo n.º 14
0
void
absval(void)
{
	int h;
	save();
	p1 = pop();

	if (istensor(p1)) {
		absval_tensor();
		restore();
		return;
	}

	if (isnum(p1)) {
		push(p1);
		if (isnegativenumber(p1))
			negate();
		restore();
		return;
	}

	if (iscomplexnumber(p1)) {
		push(p1);
		push(p1);
		conjugate();
		multiply();
		push_rational(1, 2);
		power();
		restore();
		return;
	}

	// abs(1/a) evaluates to 1/abs(a)

	if (car(p1) == symbol(POWER) && isnegativeterm(caddr(p1))) {
		push(p1);
		reciprocate();
		absval();
		reciprocate();
		restore();
		return;
	}

	// abs(a*b) evaluates to abs(a)*abs(b)

	if (car(p1) == symbol(MULTIPLY)) {
		h = tos;
		p1 = cdr(p1);
		while (iscons(p1)) {
			push(car(p1));
			absval();
			p1 = cdr(p1);
		}
		multiply_all(tos - h);
		restore();
		return;
	}

	if (isnegativeterm(p1) || (car(p1) == symbol(ADD) && isnegativeterm(cadr(p1)))) {
		push(p1);
		negate();
		p1 = pop();
	}

	push_symbol(ABS);
	push(p1);
	list(2);

	restore();
}
Exemplo n.º 15
0
double calculate(int numInputTokens, char **inputString){
	int i;
	double result = 0.0;
	char *s;
	struct DynArr *stack;
	double num;
	//set up the stack
	stack = createDynArr(20);

	// start at 1 to skip the name of the calculator calc
	for(i=1;i < numInputTokens;i++)
	{
		s = inputString[i];

		// Hint: General algorithm:
		// (1) Check if the string s is in the list of operators.
		//   (1a) If it is, perform corresponding operations.
		//   (1b) Otherwise, check if s is a number.
		//     (1b - I) If s is not a number, produce an error.
		//     (1b - II) If s is a number, push it onto the stack

		if(strcmp(s, "+") == 0){
			add(stack);
			printf("Adding\n");
		}
		else if(strcmp(s,"-") == 0){
			subtract(stack);
			printf("Subtracting\n");
		}
		else if(strcmp(s, "/") == 0){
			divide(stack);
			printf("Dividing\n");
		}
		else if(strcmp(s, "x") == 0){
			multiply(stack);
			printf("Multiplying\n");
		}
        else if(strcmp(s,"^") == 0){
			power(stack);
			printf("Power\n");
        }
		else if(strcmp(s, "^2") == 0){
			squared(stack);
			printf("Squaring\n");
		}
		else if(strcmp(s, "^3") == 0){
			cubed(stack);
			printf("Cubing\n");
		}
		else if(strcmp(s, "abs") == 0){
			absoluteValue(stack);
			printf("Absolute value\n");
		}
		else if(strcmp(s, "sqrt") == 0){
			squareRoot(stack);
			printf("Square root\n");
		}
		else if(strcmp(s, "exp") == 0){
			exponential(stack);
			printf("Exponential\n");
		}
		else if(strcmp(s, "ln") == 0){
			naturalLog(stack);
			printf("Natural Log\n");
		}
		else if(strcmp(s, "log") == 0){
			logBase10(stack);
			printf("Log\n");
		}

        else{
    // FIXME: You need to develop the code here (when s is not an operator)
    // Remember to deal with special values ("pi" and "e")
    //check if not a number
            if (isNumber(s, &num) == 0){
                if (strcmp(s, "pi") == 0){
                    num = 3.14159265;
                }
                else if (strcmp(s, "e") == 0){
                    num = 2.7182818;
                }
                else{	//wrong
                    printf("%s is not valid (number or operator) \n", s);
                    break;
                }
            }
            pushDynArr(stack, num);
        }
    }	//end for
/* FIXME: You will write this part of the function (2 steps below)
* (1) Check if everything looks OK and produce an error if needed.
* (2) Store the final value in result and print it out.
*/
    if (sizeDynArr(stack) != 1) {
        printf("Incorrect count of numbers is detected! Calculations CANNOT be preformed. ");
        return 0;
    }
    else {
        result = topDynArr(stack);
    }
    return result;
}
Exemplo n.º 16
0
void
yybesselj(void)
{
	double d;
	int n;

	N = pop();
	X = pop();

	push(N);
	n = pop_integer();

	// numerical result

	if (isdouble(X) && n != (int) 0x80000000) {
		//d = jn(n, X->u.d);
		push_double(d);
		return;
	}

	// bessej(0,0) = 1

	if (iszero(X) && iszero(N)) {
		push_integer(1);
		return;
	}

	// besselj(0,n) = 0

	if (iszero(X) && n != (int) 0x80000000) {
		push_integer(0);
		return;
	}

	// half arguments

	if (N->k == NUM && MEQUAL(N->u.q.b, 2)) {

		// n = 1/2

		if (MEQUAL(N->u.q.a, 1)) {
			push_integer(2);
			push_symbol(PI);
			divide();
			push(X);
			divide();
			push_rational(1, 2);
			power();
			push(X);
			sine();
			multiply();
			return;
		}

		// n = -1/2

		if (MEQUAL(N->u.q.a, -1)) {
			push_integer(2);
			push_symbol(PI);
			divide();
			push(X);
			divide();
			push_rational(1, 2);
			power();
			push(X);
			cosine();
			multiply();
			return;
		}

		// besselj(x,n) = (2/x) (n-sgn(n)) besselj(x,n-sgn(n)) - besselj(x,n-2*sgn(n))

		push_integer(MSIGN(N->u.q.a));
		SGN = pop();

		push_integer(2);
		push(X);
		divide();
		push(N);
		push(SGN);
		subtract();
		multiply();
		push(X);
		push(N);
		push(SGN);
		subtract();
		besselj();
		multiply();
		push(X);
		push(N);
		push_integer(2);
		push(SGN);
		multiply();
		subtract();
		besselj();
		subtract();

		return;
	}


	push(symbol(BESSELJ));
	push(X);
	push(N);
	list(3);
}
Exemplo n.º 17
0
 bool get_num_branches(contains_app& x, expr* fml, rational& nb) override {
     unsigned sz = m_bv.get_bv_size(x.x());
     nb = power(rational(2), sz);
     return true;
 }
Exemplo n.º 18
0
//------------------------------------------------------------------------------
// Printing functions
//------------------------------------------------------------------------------
void Navaid::printRecord(std::ostream& sout) const
{
   char icas[32];
   icaoCode(icas);

   char ikey[32];
   key(ikey);

   char id[12];
   ident(id);

   char ccode[4];
   countryCode(ccode);

   char rc[8];
   radioClass(rc);

   sout << icas << ", ";

   sout << "\"";
   sout << ikey;
   sout << "\", ";

   sout << id;
   sout << "-";
   sout << static_cast<char>(navaidType());
   sout << "-";
   sout << ccode;
   sout << "-";
   sout << keyCode();
   sout << ":";

   std::streamoff old = sout.precision();
   sout.precision(12);

   sout << "  ";
   sout << latitude();
   sout << ", ";
   sout << longitude();

   sout.precision(old);
   sout << ", ";
   sout << elevation();

   sout << "  ";
   sout << frequency();
   sout << "-";
   sout << channel();

   sout << "  ( ";
   sout << magVariance();
   sout << ", ";
   sout << slaveVariance();
   sout << " )";

   sout << " (";
   sout << power();
   sout << "-";
   sout << rc;
   sout << "-";
   sout << range();
   sout << ")";

}
Exemplo n.º 19
0
/* Am folosit Fibonacci generalizat */
int main(int args, char** argv) {
	
	int n, m, k, i, j;
	long long **a, *initial;
	
	FILE *fr, *fw;

	fr = fopen("date.in", "r");	
	fw = fopen("date.out", "w");
	
	fscanf(fr, "%d", &n);
	fscanf(fr, "%d", &m);
	fscanf(fr, "%d", &k);
	
	a = (long long**)calloc((k + 1), sizeof(long long*));
	
	for(i = 0; i <= k; i++) {
		a[i] = (long long *)calloc((k + 1), sizeof(long long));
	}
	
	initial = (long long *)calloc((k + 1), sizeof(long long));
	
	/* Pe vectorul termenilor initiali se pun puteri ale lui 2 */
	for(i = 0; i <= k; i++) {
		initial[i] = pow(2, i);
	}

	/* In matrice se pune 1 pe diagonala de deasupra celei principale (pentru a
	se avansa cu cate un termen la fiecare inmultire si a se lua in considerare
	doar ultimi k) si 1 pe ultima linie (al k + 1 termen se calculeaza ca suma 
	celor k + 1 termeni de la pasul anterior) */
	for(i = 0; i < k + 1; i++) {
		for(j = 0; j < k + 1; j++) {
			if(j == i + 1) {
				a[i][j] = 1;
			}
			if(i == k) {
				a[i][j] = 1;
			}
		}
	}

	/* Se ridica a la n - k in vederea calculului celui de-al n-lea termen */
	a = logPowMatrix(a, n - k, k);

	
	/* Se inmulteste vectorul intial cu matricea a */
	long long result = 0;
	for(i = 0; i <= k; i++) {
		result += ((a[k][i] * initial[i]) % MOD);
	}
	
	/* Rezultatul se ridica la puterea numarul de coloane pt numarul total de
	cadre */
	result = power(result, m);
	

	fprintf(fw, "%lli", result);
	
	/* Se elibereaza memoria */
	for(i = 0; i <= k; i++) {
		free(a[i]);
	}
	free(a);
	free(initial);
	fclose(fr);
	fclose(fw);	

	return 0;
}
Exemplo n.º 20
0
int main(void)
{
    printf("2 ^ 4 = %.2f\n", power(2, 4));
    return 0;
}
Exemplo n.º 21
0
double power(double x, long n)
{
   if(n == 0) return 1;
   if(n < 0) return power ( 1 / x, -n);
   return x * power(x, n - 1);
}
Exemplo n.º 22
0
MainWindow::MainWindow() {
  setObjectName("main-window");
  setWindowTitle(string() << SNES::Info::Name << " v" << SNES::Info::Version);
  setCloseOnEscape(false);
  setGeometryString(&config().geometry.mainWindow);
  application.windowList.append(this);

  //menu bar
  #if defined(PLATFORM_OSX)
  menuBar = new QMenuBar(0);
  #else
  menuBar = new QMenuBar;
  #endif

  system = menuBar->addMenu("&System");

  system_load = system->addAction("Load &Cartridge ...");

  system_loadSpecial = system->addMenu("Load &Special");

  system_loadSpecial_bsx = system_loadSpecial->addAction("Load &BS-X Cartridge ...");
  
  system_loadSpecial_bsxSlotted = system_loadSpecial->addAction("Load BS-X &Slotted Cartridge ...");

  system_loadSpecial_sufamiTurbo = system_loadSpecial->addAction("Load Sufami &Turbo Cartridge ...");

  system_loadSpecial_superGameBoy = system_loadSpecial->addAction("Load Super &Game Boy Cartridge ...");

  system_saveMemoryPack = system->addAction("Save Memory Pack ...");
  system_saveMemoryPack->setVisible(false);

  system_reload = system->addAction("Re&load");

  system->addSeparator();

  system->addAction(system_power = new CheckAction("&Power", 0));

  system_reset = system->addAction("&Reset");

  system->addSeparator();

  system_port1 = system->addMenu("Controller Port &1");
  system_port1->addAction(system_port1_none = new RadioAction("&None", 0));
  system_port1->addAction(system_port1_gamepad = new RadioAction("&Gamepad", 0));
  system_port1->addAction(system_port1_asciipad = new RadioAction("&asciiPad", 0));
  system_port1->addAction(system_port1_multitap = new RadioAction("&Multitap", 0));
  system_port1->addAction(system_port1_mouse = new RadioAction("&Mouse", 0));
  system_port1->addAction(system_port1_nttdatakeypad = new RadioAction("NTT Data &Keypad", 0));

  system_port2 = system->addMenu("Controller Port &2");
  system_port2->addAction(system_port2_none = new RadioAction("&None", 0));
  system_port2->addAction(system_port2_gamepad = new RadioAction("&Gamepad", 0));
  system_port2->addAction(system_port2_asciipad = new RadioAction("&asciiPad", 0));
  system_port2->addAction(system_port2_multitap = new RadioAction("&Multitap", 0));
  system_port2->addAction(system_port2_mouse = new RadioAction("&Mouse", 0));
  system_port2->addAction(system_port2_superscope = new RadioAction("&Super Scope", 0));
  system_port2->addAction(system_port2_justifier = new RadioAction("&Justifier", 0));
  system_port2->addAction(system_port2_justifiers = new RadioAction("Two &Justifiers", 0));

  #if !defined(PLATFORM_OSX)
  system->addSeparator();
  #endif

  system_exit = system->addAction("E&xit");
  system_exit->setMenuRole(QAction::QuitRole);

  settings = menuBar->addMenu("S&ettings");

  settings_videoMode = settings->addMenu("Video &Mode");

  settings_videoMode->addAction(settings_videoMode_1x = new RadioAction("Scale &1x", 0));

  settings_videoMode->addAction(settings_videoMode_2x = new RadioAction("Scale &2x", 0));

  settings_videoMode->addAction(settings_videoMode_3x = new RadioAction("Scale &3x", 0));

  settings_videoMode->addAction(settings_videoMode_4x = new RadioAction("Scale &4x", 0));

  settings_videoMode->addAction(settings_videoMode_5x = new RadioAction("Scale &5x", 0));

  settings_videoMode->addAction(settings_videoMode_max_normal = new RadioAction("Scale Max - &Normal", 0));

  settings_videoMode->addAction(settings_videoMode_max_wide = new RadioAction("Scale Max - &Wide", 0));

  settings_videoMode->addAction(settings_videoMode_max_wideZoom = new RadioAction("Scale Max - Wide &Zoom", 0));

  settings_videoMode->addSeparator();

  settings_videoMode->addAction(settings_videoMode_correctAspectRatio = new CheckAction("Correct &Aspect Ratio", 0));

  settings_videoMode->addSeparator();

  settings_videoMode->addAction(settings_videoMode_ntsc = new RadioAction("&NTSC", 0));
  settings_videoMode->addAction(settings_videoMode_pal = new RadioAction("&PAL", 0));

  if(filter.opened()) {
    settings_videoFilter = settings->addMenu("Video &Filter");

    settings_videoFilter_configure = settings_videoFilter->addAction("&Configure Active Filter ...");
    settings_videoFilter->addSeparator();

    settings_videoFilter->addAction(settings_videoFilter_none = new RadioAction("&None", 0));
    settings_videoFilter_list.append(settings_videoFilter_none);

    lstring filterlist;
    filterlist.split(";", filter.dl_supported());
    for(unsigned i = 0; i < filterlist.size(); i++) {
      RadioAction *action = new RadioAction(filterlist[i], 0);
      settings_videoFilter->addAction(action);
      settings_videoFilter_list.append(action);
    }
  }

  settings->addAction(settings_smoothVideo = new CheckAction("&Smooth Video Output", 0));

  settings->addSeparator();

  settings->addAction(settings_muteAudio = new CheckAction("&Mute Audio Output", 0));

  settings->addSeparator();

  settings_emulationSpeed = settings->addMenu("Emulation &Speed");

  settings_emulationSpeed->addAction(settings_emulationSpeed_slowest = new RadioAction("Slowest", 0));

  settings_emulationSpeed->addAction(settings_emulationSpeed_slow = new RadioAction("Slow", 0));

  settings_emulationSpeed->addAction(settings_emulationSpeed_normal = new RadioAction("Normal", 0));

  settings_emulationSpeed->addAction(settings_emulationSpeed_fast = new RadioAction("Fast", 0));

  settings_emulationSpeed->addAction(settings_emulationSpeed_fastest = new RadioAction("Fastest", 0));

  settings_emulationSpeed->addSeparator();

  settings_emulationSpeed->addAction(settings_emulationSpeed_syncVideo = new CheckAction("Sync &Video", 0));

  settings_emulationSpeed->addAction(settings_emulationSpeed_syncAudio = new CheckAction("Sync &Audio", 0));

  settings_configuration = settings->addAction("&Configuration ...");
  settings_configuration->setMenuRole(QAction::PreferencesRole);

  tools = menuBar->addMenu("&Tools");

  tools_movies = tools->addMenu("&Movies");

  tools_movies_play = tools_movies->addAction("Play Movie ...");

  tools_movies_stop = tools_movies->addAction("Stop");

  tools_movies_recordFromPowerOn = tools_movies->addAction("Record Movie (and restart system)");

  tools_movies_recordFromHere = tools_movies->addAction("Record Movie (starting from here)");

  tools_captureScreenshot = tools->addAction("&Capture Screenshot");
  
  tools_captureSPC = tools->addAction("Capture &SPC Dump");

  tools->addSeparator();

  tools_loadState = tools->addMenu("&Load Quick State");
  for(unsigned i = 0; i < 10; i++) {
    QAction *loadAction = new QAction(string("Slot ", i + 1), 0);
    loadAction->setData(i);
    connect(loadAction, SIGNAL(triggered()), this, SLOT(loadState()));
    tools_loadState->addAction(loadAction);
  }

  tools_saveState = tools->addMenu("&Save Quick State");
  for(unsigned i = 0; i < 10; i++) {
    QAction *saveAction = new QAction(string("Slot ", i + 1), 0);
    saveAction->setData(i);
    connect(saveAction, SIGNAL(triggered()), this, SLOT(saveState()));
    tools_saveState->addAction(saveAction);
  }

  tools->addSeparator();

  tools_cheatEditor = tools->addAction("Cheat &Editor ...");

  tools_cheatFinder = tools->addAction("Cheat &Finder ...");

  tools_stateManager = tools->addAction("&State Manager ...");

  tools_effectToggle = tools->addAction("Effect &Toggle ...");
  if(!SNES::PPU::SupportsLayerEnable && !SNES::DSP::SupportsChannelEnable)
    tools_effectToggle->setVisible(false);
  
  tools_manifestViewer = tools->addAction("&Manifest Viewer ...");
  
  tools_soundViewer = tools->addAction("Sound &Viewer ...");

  tools_debugger = tools->addAction("&Debugger ...");
  #if !defined(DEBUGGER)
  tools_debugger->setVisible(false);
  #endif

  help = menuBar->addMenu("&Help");

  help_documentation = help->addAction("&Documentation ...");

  help_license = help->addAction("&License ...");

  #if !defined(PLATFORM_OSX)
  help->addSeparator();
  #endif

  help_about = help->addAction("&About ...");
  help_about->setMenuRole(QAction::AboutRole);

  //canvas
  canvasContainer = new CanvasObject;
  canvasContainer->setAcceptDrops(true); {
    canvasContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    canvasContainer->setObjectName("backdrop");

    canvasLayout = new QVBoxLayout; {
      canvasLayout->setMargin(0);
      canvasLayout->setAlignment(Qt::AlignCenter);

      canvas = new CanvasWidget;
      canvas->setAcceptDrops(true);
      canvas->setFocusPolicy(Qt::StrongFocus);
      canvas->setAttribute(Qt::WA_PaintOnScreen, true);  //disable Qt painting on focus / resize
      canvas->setAttribute(Qt::WA_NoSystemBackground, true);
    }
    canvasLayout->addWidget(canvas);
  }
  canvasContainer->setLayout(canvasLayout);

  //status bar
  statusBar = new QStatusBar;
  statusBar->setSizeGripEnabled(false);
  statusBar->showMessage("");
  systemState = new QLabel;
  statusBar->addPermanentWidget(systemState);

  //layout
  layout = new QVBoxLayout;
  layout->setMargin(0);
  layout->setSpacing(0);
  #if !defined(PLATFORM_OSX)
  layout->addWidget(menuBar);
  #endif
  layout->addWidget(canvasContainer);
  layout->addWidget(statusBar);
  setLayout(layout);

  //cursor hide timer
  cursorTimer = new QTimer(this);
  cursorTimer->setSingleShot(true);
  cursorTimer->setInterval(5*1000);

  //slots
  connect(system_load, SIGNAL(triggered()), this, SLOT(loadCartridge()));
  connect(system_reload, SIGNAL(triggered()), this, SLOT(reloadCartridge()));
  connect(system_loadSpecial_bsxSlotted, SIGNAL(triggered()), this, SLOT(loadBsxSlottedCartridge()));
  connect(system_loadSpecial_bsx, SIGNAL(triggered()), this, SLOT(loadBsxCartridge()));
  connect(system_loadSpecial_sufamiTurbo, SIGNAL(triggered()), this, SLOT(loadSufamiTurboCartridge()));
  connect(system_loadSpecial_superGameBoy, SIGNAL(triggered()), this, SLOT(loadSuperGameBoyCartridge()));
  connect(system_saveMemoryPack, SIGNAL(triggered()), this, SLOT(saveMemoryPack()));
  connect(system_power, SIGNAL(triggered()), this, SLOT(power()));
  connect(system_reset, SIGNAL(triggered()), this, SLOT(reset()));
  connect(system_port1_none, SIGNAL(triggered()), this, SLOT(setPort1None()));
  connect(system_port1_gamepad, SIGNAL(triggered()), this, SLOT(setPort1Gamepad()));
  connect(system_port1_asciipad, SIGNAL(triggered()), this, SLOT(setPort1Asciipad()));
  connect(system_port1_multitap, SIGNAL(triggered()), this, SLOT(setPort1Multitap()));
  connect(system_port1_mouse, SIGNAL(triggered()), this, SLOT(setPort1Mouse()));
  connect(system_port1_nttdatakeypad, SIGNAL(triggered()), this, SLOT(setPort1NTTDataKeypad()));
  connect(system_port2_none, SIGNAL(triggered()), this, SLOT(setPort2None()));
  connect(system_port2_gamepad, SIGNAL(triggered()), this, SLOT(setPort2Gamepad()));
  connect(system_port2_asciipad, SIGNAL(triggered()), this, SLOT(setPort2Asciipad()));
  connect(system_port2_multitap, SIGNAL(triggered()), this, SLOT(setPort2Multitap()));
  connect(system_port2_mouse, SIGNAL(triggered()), this, SLOT(setPort2Mouse()));
  connect(system_port2_superscope, SIGNAL(triggered()), this, SLOT(setPort2SuperScope()));
  connect(system_port2_justifier, SIGNAL(triggered()), this, SLOT(setPort2Justifier()));
  connect(system_port2_justifiers, SIGNAL(triggered()), this, SLOT(setPort2Justifiers()));
  connect(system_exit, SIGNAL(triggered()), this, SLOT(quit()));
  connect(settings_videoMode_1x, SIGNAL(triggered()), this, SLOT(setVideoMode1x()));
  connect(settings_videoMode_2x, SIGNAL(triggered()), this, SLOT(setVideoMode2x()));
  connect(settings_videoMode_3x, SIGNAL(triggered()), this, SLOT(setVideoMode3x()));
  connect(settings_videoMode_4x, SIGNAL(triggered()), this, SLOT(setVideoMode4x()));
  connect(settings_videoMode_5x, SIGNAL(triggered()), this, SLOT(setVideoMode5x()));
  connect(settings_videoMode_max_normal, SIGNAL(triggered()), this, SLOT(setVideoModeMaxNormal()));
  connect(settings_videoMode_max_wide, SIGNAL(triggered()), this, SLOT(setVideoModeMaxWide()));
  connect(settings_videoMode_max_wideZoom, SIGNAL(triggered()), this, SLOT(setVideoModeMaxWideZoom()));
  connect(settings_videoMode_correctAspectRatio, SIGNAL(triggered()), this, SLOT(toggleAspectCorrection()));
  connect(settings_videoMode_ntsc, SIGNAL(triggered()), this, SLOT(setVideoNtsc()));
  connect(settings_videoMode_pal, SIGNAL(triggered()), this, SLOT(setVideoPal()));
  if(filter.opened()) {
    connect(settings_videoFilter_configure, SIGNAL(triggered()), this, SLOT(configureFilter()));
    for(unsigned i = 0; i < settings_videoFilter_list.size(); i++) {
      connect(settings_videoFilter_list[i], SIGNAL(triggered()), this, SLOT(setFilter()));
    }
  }
  connect(settings_smoothVideo, SIGNAL(triggered()), this, SLOT(toggleSmoothVideo()));
  connect(settings_muteAudio, SIGNAL(triggered()), this, SLOT(muteAudio()));
  connect(settings_emulationSpeed_slowest, SIGNAL(triggered()), this, SLOT(setSpeedSlowest()));
  connect(settings_emulationSpeed_slow, SIGNAL(triggered()), this, SLOT(setSpeedSlow()));
  connect(settings_emulationSpeed_normal, SIGNAL(triggered()), this, SLOT(setSpeedNormal()));
  connect(settings_emulationSpeed_fast, SIGNAL(triggered()), this, SLOT(setSpeedFast()));
  connect(settings_emulationSpeed_fastest, SIGNAL(triggered()), this, SLOT(setSpeedFastest()));
  connect(settings_emulationSpeed_syncVideo, SIGNAL(triggered()), this, SLOT(syncVideo()));
  connect(settings_emulationSpeed_syncAudio, SIGNAL(triggered()), this, SLOT(syncAudio()));
  connect(settings_configuration, SIGNAL(triggered()), this, SLOT(showConfigWindow()));
  connect(tools_movies_play, SIGNAL(triggered()), this, SLOT(playMovie()));
  connect(tools_movies_stop, SIGNAL(triggered()), this, SLOT(stopMovie()));
  connect(tools_movies_recordFromPowerOn, SIGNAL(triggered()), this, SLOT(recordMovieFromPowerOn()));
  connect(tools_movies_recordFromHere, SIGNAL(triggered()), this, SLOT(recordMovieFromHere()));
  connect(tools_captureScreenshot, SIGNAL(triggered()), this, SLOT(saveScreenshot()));
  connect(tools_captureSPC, SIGNAL(triggered()), this, SLOT(saveSPC()));
  connect(tools_cheatEditor, SIGNAL(triggered()), this, SLOT(showCheatEditor()));
  connect(tools_cheatFinder, SIGNAL(triggered()), this, SLOT(showCheatFinder()));
  connect(tools_stateManager, SIGNAL(triggered()), this, SLOT(showStateManager()));
  connect(tools_effectToggle, SIGNAL(triggered()), this, SLOT(showEffectToggle()));
  connect(tools_manifestViewer, SIGNAL(triggered()), this, SLOT(showManifestViewer()));
  connect(tools_soundViewer, SIGNAL(triggered()), this, SLOT(showSoundViewer()));
  connect(tools_debugger, SIGNAL(triggered()), this, SLOT(showDebugger()));
  connect(help_documentation, SIGNAL(triggered()), this, SLOT(showDocumentation()));
  connect(help_license, SIGNAL(triggered()), this, SLOT(showLicense()));
  connect(help_about, SIGNAL(triggered()), this, SLOT(showAbout()));

  syncUi();
}
exprt convert_float_literal(const std::string &src)
{
  mp_integer significand;
  mp_integer exponent;
  bool is_float, is_long, is_fixed, is_accum;
  unsigned base;
  
  parse_float(src, significand, exponent, base, is_float, is_long, is_fixed, is_accum);

  exprt result=exprt(ID_constant);
  
  result.set(ID_C_cformat, src);
  
  // In ANSI-C, float literals are double by default
  // unless marked with 'f'.

  if(is_float)
  {
    result.type()=float_type();
    result.type().set(ID_C_cpp_type, ID_float);
  }
  else if(is_long)
  {
    result.type()=long_double_type();
    result.type().set(ID_C_cpp_type, ID_long_double);
  }
  else if(is_fixed)
  {
    result.type()=fixed_type();
    result.type().set(ID_C_cpp_type, ID_fixed);
  }
  else if(is_accum)
  {
    result.type()=accum_type();
    result.type().set(ID_C_cpp_type, ID_accum);
  }
  else
  {
    result.type()=double_type(); // default
    result.type().set(ID_C_cpp_type, ID_double);
  }


  if(config.ansi_c.use_fixed_for_float || is_fixed || is_accum)
  {
    unsigned width=result.type().get_int(ID_width);
    unsigned fraction_bits;
    const irep_idt integer_bits=result.type().get(ID_integer_bits);
    
    assert(width!=0);

    if(is_fixed)
    {
      fraction_bits = width - 1;
    }
    else if(is_accum)
    {
      fraction_bits = width - 9;
    }
    else if(integer_bits==irep_idt())
      fraction_bits=width/2; // default
    else
      fraction_bits=width-safe_string2int(id2string(integer_bits));

    mp_integer factor=mp_integer(1)<<fraction_bits;
    mp_integer value=significand*factor;
    
    if(value!=0)
    {
      if(exponent<0)
        value/=power(base, -exponent);
      else
      {
        value*=power(base, exponent);    

        if(value>=power(2, width-1))
        {
          // saturate: use "biggest value"
          value=power(2, width-1)-1;
        }
        else if(value<=-power(2, width-1)-1)
        {
          // saturate: use "smallest value"
          value=-power(2, width-1);
        }
      }
    }

    result.set(ID_value, integer2binary(value, width));  
  }
  else
  {
    ieee_floatt a;

    a.spec=to_floatbv_type(result.type());
    
    if(base==10)
      a.from_base10(significand, exponent);
    else if(base==2) // hex
      a.build(significand, exponent);
    else
      assert(false);

    result.set(ID_value,
      integer2binary(a.pack(), a.spec.width()));  
  }
  
  return result;
}
Exemplo n.º 24
0
void
yypower(void)
{
	int n;

	p2 = pop();
	p1 = pop();

	// both base and exponent are rational numbers?

	if (isrational(p1) && isrational(p2)) {
		push(p1);
		push(p2);
		qpow();
		return;
	}

	// both base and exponent are either rational or double?

	if (isnum(p1) && isnum(p2)) {
		push(p1);
		push(p2);
		dpow();
		return;
	}

	if (istensor(p1)) {
		power_tensor();
		return;
	}

	if (p1 == symbol(E) && car(p2) == symbol(LOG)) {
		push(cadr(p2));
		return;
	}

	if ((p1 == symbol(MINFTY) || p1 == symbol(INFTY)) && isnegativeterm(p2)) {
		push_integer(0);
		return;
	}

	if (iszero(p1) && isnegativeterm(p2)) {
		push_symbol(INFTY);
		return;
	}

	if (p1 == symbol(E) && p2 == symbol(MINFTY)) {		
		push_integer(0);
		return;
	}

	if (p1 == symbol(E) && isdouble(p2)) {
		push_double(exp(p2->u.d));
		return;
	}

	//	1 ^ a		->	1

	//	a ^ 0		->	1

	if (equal(p1, one) || iszero(p2)) {
		push(one);
		return;
	}

	//	a ^ 1		->	a

	if (equal(p2, one)) {
		push(p1);
		return;
	}

	//	(a * b) ^ c	->	(a ^ c) * (b ^ c)

	if (car(p1) == symbol(MULTIPLY)) {
		p1 = cdr(p1);
		push(car(p1));
		push(p2);
		power();
		p1 = cdr(p1);
		while (iscons(p1)) {
			push(car(p1));
			push(p2);
			power();
			multiply();
			p1 = cdr(p1);
		}
		return;
	}

	//	(a ^ b) ^ c	->	a ^ (b * c)

	if (car(p1) == symbol(POWER)) {
		push(cadr(p1));
		push(caddr(p1));
		push(p2);
		multiply();
		power();
		return;
	}

	//	(a + b) ^ n	->	(a + b) * (a + b) ...

	if (expanding && isadd(p1) && isnum(p2)) {
		push(p2);
		n = pop_integer();
		if (n > 1) {
			power_sum(n);
			return;
		}
	}

	//	sin(x) ^ 2n -> (1 - cos(x) ^ 2) ^ n

	if (trigmode == 1 && car(p1) == symbol(SIN) && iseveninteger(p2)) {
		push_integer(1);
		push(cadr(p1));
		cosine();
		push_integer(2);
		power();
		subtract();
		push(p2);
		push_rational(1, 2);
		multiply();
		power();
		return;
	}

	//	cos(x) ^ 2n -> (1 - sin(x) ^ 2) ^ n

	if (trigmode == 2 && car(p1) == symbol(COS) && iseveninteger(p2)) {
		push_integer(1);
		push(cadr(p1));
		sine();
		push_integer(2);
		power();
		subtract();
		push(p2);
		push_rational(1, 2);
		multiply();
		power();
		return;
	}

	// complex number? (just number, not expression)

	if (iscomplexnumber(p1)) {

		// integer power?

		// n will be negative here, positive n already handled

		if (isinteger(p2)) {

			//               /        \  n
			//         -n   |  a - ib  |
			// (a + ib)   = | -------- |
			//              |   2   2  |
			//               \ a + b  /

			push(p1);
			conjugate();
			p3 = pop();
			push(p3);
			push(p3);
			push(p1);
			multiply();
			divide();
			push(p2);
			negate();
			power();
			return;
		}

		// noninteger or floating power?

		if (isnum(p2)) {

#if 1			// use polar form
			push(p1);
			mag();
			push(p2);
			power();
			push_integer(-1);
			push(p1);
			arg();
			push(p2);
			multiply();
			push(symbol(PI));
			divide();
			power();
			multiply();

#else			// use exponential form
			push(p1);
			mag();
			push(p2);
			power();
			push(symbol(E));
			push(p1);
			arg();
			push(p2);
			multiply();
			push(imaginaryunit);
			multiply();
			power();
			multiply();
#endif
			return;
		}
	}

	if (simplify_polar())
		return;

	push_symbol(POWER);
	push(p1);
	push(p2);
	list(3);
}
Exemplo n.º 25
0
inline
time_duration
parse_undelimited_time_duration(const std::string& s)
{
    int precision = 0;
    {
        // msvc wouldn't compile 'time_duration::num_fractional_digits()'
        // (required template argument list) as a workaround, a temp
        // time_duration object was used
        time_duration tmp(0,0,0,1);
        precision = tmp.num_fractional_digits();
    }
    // 'precision+1' is so we grab all digits, plus the decimal
    int offsets[] = {2,2,2, precision+1};
    int pos = 0, sign = 0;
    int hours = 0;
    short min=0, sec=0;
    lslboost::int64_t fs=0;
    // increment one position if the string was "signed"
    if(s.at(sign) == '-')
    {
        ++sign;
    }
    // stlport choked when passing s.substr() to tokenizer
    // using a new string fixed the error
    std::string remain = s.substr(sign);
    /* We do not want the offset_separator to wrap the offsets, we
     * will never want to  process more than:
     * 2 char, 2 char, 2 char, frac_sec length.
     * We *do* want the offset_separator to give us a partial for the
     * last characters if there were not enough provided in the input string. */
    bool wrap_off = false;
    bool ret_part = true;
    lslboost::offset_separator osf(offsets, offsets+4, wrap_off, ret_part);
    typedef lslboost::tokenizer<lslboost::offset_separator,
            std::basic_string<char>::const_iterator,
            std::basic_string<char> > tokenizer;
    typedef lslboost::tokenizer<lslboost::offset_separator,
            std::basic_string<char>::const_iterator,
            std::basic_string<char> >::iterator tokenizer_iterator;
    tokenizer tok(remain, osf);
    for(tokenizer_iterator ti=tok.begin(); ti!=tok.end(); ++ti) {
        switch(pos) {
        case 0:
        {
            hours = lslboost::lexical_cast<int>(*ti);
            break;
        }
        case 1:
        {
            min = lslboost::lexical_cast<short>(*ti);
            break;
        }
        case 2:
        {
            sec = lslboost::lexical_cast<short>(*ti);
            break;
        }
        case 3:
        {
            std::string char_digits(ti->substr(1)); // digits w/no decimal
            int digits = static_cast<int>(char_digits.length());

            //Works around a bug in MSVC 6 library that does not support
            //operator>> thus meaning lexical_cast will fail to compile.
#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200))  // 1200 == VC++ 6.0
            // _atoi64 is an MS specific function
            if(digits >= precision) {
                // drop excess digits
                fs = _atoi64(char_digits.substr(0, precision).c_str());
            }
            else if(digits == 0) {
                fs = 0; // just in case _atoi64 doesn't like an empty string
            }
            else {
                fs = _atoi64(char_digits.c_str());
            }
#else
            if(digits >= precision) {
                // drop excess digits
                fs = lslboost::lexical_cast<lslboost::int64_t>(char_digits.substr(0, precision));
            }
            else if(digits == 0) {
                fs = 0; // lexical_cast doesn't like empty strings
            }
            else {
                fs = lslboost::lexical_cast<lslboost::int64_t>(char_digits);
            }
#endif
            if(digits < precision) {
                // trailing zeros get dropped from the string,
                // "1:01:01.1" would yield .000001 instead of .100000
                // the power() compensates for the missing decimal places
                fs *= power(10, precision - digits);
            }

            break;
        }
        default:
            break;
        };
        pos++;
    }
    if(sign) {
        return -time_duration(hours, min, sec, fs);
    }
    else {
        return time_duration(hours, min, sec, fs);
    }
}
Exemplo n.º 26
0
static void euclid(const emxArray_real_T *x, const emxArray_real_T *y,
                   emxArray_real_T *d)
{
  emxArray_real_T *a;
  emxArray_real_T *b;
  emxArray_real_T *b_b;
  emxArray_real_T *r0;
  int32_T i2;
  int32_T unnamed_idx_1;
  int32_T ar;
  int32_T i3;
  emxArray_real_T *b_y;
  int32_T cr;
  int32_T br;
  uint32_T unnamed_idx_0;
  uint32_T b_unnamed_idx_1;
  int32_T ic;
  int32_T ib;
  int32_T ia;
  emxArray_real_T *b_a;
  emxArray_real_T *r1;
  b_emxInit_real_T(&a, 1);
  emxInit_real_T(&b, 2);
  emxInit_real_T(&b_b, 2);
  b_emxInit_real_T(&r0, 1);

  /*  all done */
  power(x, b_b);
  sum(b_b, a);
  power(y, b_b);
  sum(b_b, r0);
  i2 = b->size[0] * b->size[1];
  b->size[0] = 1;
  emxEnsureCapacity((emxArray__common *)b, i2, (int32_T)sizeof(real_T));
  unnamed_idx_1 = r0->size[0];
  i2 = b->size[0] * b->size[1];
  b->size[1] = unnamed_idx_1;
  emxEnsureCapacity((emxArray__common *)b, i2, (int32_T)sizeof(real_T));
  ar = r0->size[0];
  for (i2 = 0; i2 < ar; i2++) {
    b->data[i2] = r0->data[i2];
  }

  emxFree_real_T(&r0);
  i2 = b_b->size[0] * b_b->size[1];
  b_b->size[0] = y->size[1];
  b_b->size[1] = y->size[0];
  emxEnsureCapacity((emxArray__common *)b_b, i2, (int32_T)sizeof(real_T));
  ar = y->size[0];
  for (i2 = 0; i2 < ar; i2++) {
    unnamed_idx_1 = y->size[1];
    for (i3 = 0; i3 < unnamed_idx_1; i3++) {
      b_b->data[i3 + b_b->size[0] * i2] = y->data[i2 + y->size[0] * i3];
    }
  }

  emxInit_real_T(&b_y, 2);
  if ((x->size[1] == 1) || (b_b->size[0] == 1)) {
    i2 = b_y->size[0] * b_y->size[1];
    b_y->size[0] = x->size[0];
    b_y->size[1] = b_b->size[1];
    emxEnsureCapacity((emxArray__common *)b_y, i2, (int32_T)sizeof(real_T));
    ar = x->size[0];
    for (i2 = 0; i2 < ar; i2++) {
      unnamed_idx_1 = b_b->size[1];
      for (i3 = 0; i3 < unnamed_idx_1; i3++) {
        b_y->data[i2 + b_y->size[0] * i3] = 0.0;
        cr = x->size[1];
        for (br = 0; br < cr; br++) {
          b_y->data[i2 + b_y->size[0] * i3] += x->data[i2 + x->size[0] * br] *
            b_b->data[br + b_b->size[0] * i3];
        }
      }
    }
  } else {
    unnamed_idx_0 = (uint32_T)x->size[0];
    b_unnamed_idx_1 = (uint32_T)b_b->size[1];
    i2 = b_y->size[0] * b_y->size[1];
    b_y->size[0] = (int32_T)unnamed_idx_0;
    emxEnsureCapacity((emxArray__common *)b_y, i2, (int32_T)sizeof(real_T));
    i2 = b_y->size[0] * b_y->size[1];
    b_y->size[1] = (int32_T)b_unnamed_idx_1;
    emxEnsureCapacity((emxArray__common *)b_y, i2, (int32_T)sizeof(real_T));
    ar = (int32_T)unnamed_idx_0 * (int32_T)b_unnamed_idx_1;
    for (i2 = 0; i2 < ar; i2++) {
      b_y->data[i2] = 0.0;
    }

    if ((x->size[0] == 0) || (b_b->size[1] == 0)) {
    } else {
      unnamed_idx_1 = x->size[0] * (b_b->size[1] - 1);
      cr = 0;
      while ((x->size[0] > 0) && (cr <= unnamed_idx_1)) {
        i2 = cr + x->size[0];
        for (ic = cr; ic + 1 <= i2; ic++) {
          b_y->data[ic] = 0.0;
        }

        cr += x->size[0];
      }

      br = 0;
      cr = 0;
      while ((x->size[0] > 0) && (cr <= unnamed_idx_1)) {
        ar = -1;
        i2 = br + x->size[1];
        for (ib = br; ib + 1 <= i2; ib++) {
          if (b_b->data[ib] != 0.0) {
            ia = ar;
            i3 = cr + x->size[0];
            for (ic = cr; ic + 1 <= i3; ic++) {
              ia++;
              b_y->data[ic] += b_b->data[ib] * x->data[ia];
            }
          }

          ar += x->size[0];
        }

        br += x->size[1];
        cr += x->size[0];
      }
    }
  }

  emxFree_real_T(&b_b);
  emxInit_real_T(&b_a, 2);
  emxInit_real_T(&r1, 2);
  unnamed_idx_1 = y->size[0];
  cr = x->size[0];
  i2 = b_a->size[0] * b_a->size[1];
  b_a->size[0] = a->size[0];
  b_a->size[1] = unnamed_idx_1;
  emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T));
  ar = a->size[0];
  for (i2 = 0; i2 < ar; i2++) {
    for (i3 = 0; i3 < unnamed_idx_1; i3++) {
      b_a->data[i2 + b_a->size[0] * i3] = a->data[i2];
    }
  }

  emxFree_real_T(&a);
  i2 = r1->size[0] * r1->size[1];
  r1->size[0] = cr;
  r1->size[1] = b->size[1];
  emxEnsureCapacity((emxArray__common *)r1, i2, (int32_T)sizeof(real_T));
  for (i2 = 0; i2 < cr; i2++) {
    ar = b->size[1];
    for (i3 = 0; i3 < ar; i3++) {
      r1->data[i2 + r1->size[0] * i3] = b->data[b->size[0] * i3];
    }
  }

  emxFree_real_T(&b);
  i2 = d->size[0] * d->size[1];
  d->size[0] = b_a->size[0];
  d->size[1] = b_a->size[1];
  emxEnsureCapacity((emxArray__common *)d, i2, (int32_T)sizeof(real_T));
  ar = b_a->size[1];
  for (i2 = 0; i2 < ar; i2++) {
    unnamed_idx_1 = b_a->size[0];
    for (i3 = 0; i3 < unnamed_idx_1; i3++) {
      d->data[i3 + d->size[0] * i2] = (b_a->data[i3 + b_a->size[0] * i2] +
        r1->data[i3 + r1->size[0] * i2]) - 2.0 * b_y->data[i3 + b_y->size[0] *
        i2];
    }
  }

  emxFree_real_T(&r1);
  emxFree_real_T(&b_a);
  emxFree_real_T(&b_y);
  b_sqrt(d);
}
Exemplo n.º 27
0
void
divpoly_void(void)
{
	int h, i, m, n, x;
	U **dividend, **divisor;

	save();

	X = pop();
	DIVISOR = pop();
	DIVIDEND = pop();

	h = tos;

	dividend = stack + tos;

	push(DIVIDEND);
	push(X);
	m = coeff() - 1;	// m is dividend's power

	divisor = stack + tos;

	push(DIVISOR);
	push(X);
	n = coeff() - 1;	// n is divisor's power

	x = m - n;

	push_integer(0);
	QUOTIENT = pop();

	while (x >= 0) {

		push(dividend[m]);
		push(divisor[n]);
		divide();
		Q = pop();

		for (i = 0; i <= n; i++) {
			push(dividend[x + i]);
			push(divisor[i]);
			push(Q);
			multiply();
			subtract();
			dividend[x + i] = pop();
		}

		push(QUOTIENT);
		push(Q);
		push(X);
		push_integer(x);
		power();
		multiply();
		add();
		QUOTIENT = pop();

		m--;
		x--;
	}

	tos = h;

	push(QUOTIENT);

	restore();
}
Exemplo n.º 28
0
void sammon(const emxArray_real_T *x, emxArray_real_T *y)
{
  emxArray_real_T *D;
  emxArray_real_T *delta;
  int32_T i0;
  int32_T b_D;
  int32_T br;
  emxArray_real_T *Dinv;
  emxArray_real_T *d;
  emxArray_real_T *dinv;
  emxArray_real_T *c_D;
  emxArray_real_T *b_delta;
  emxArray_real_T *b_x;
  real_T E;
  int32_T i;
  emxArray_real_T *deltaone;
  emxArray_real_T *g;
  emxArray_real_T *y2;
  emxArray_real_T *H;
  emxArray_real_T *s;
  emxArray_real_T *C;
  emxArray_real_T *b_C;
  emxArray_real_T *c_delta;
  emxArray_real_T *d_D;
  emxArray_real_T *b_deltaone;
  boolean_T exitg1;
  boolean_T guard2 = FALSE;
  uint32_T unnamed_idx_0;
  int32_T ic;
  int32_T ar;
  int32_T ib;
  int32_T ia;
  int32_T i1;
  boolean_T guard1 = FALSE;
  int32_T exitg3;
  boolean_T exitg2;
  int32_T b_y[2];
  real_T E_new;
  real_T u1;
  emxInit_real_T(&D, 2);
  emxInit_real_T(&delta, 2);

  /* #codgen */
  /*  */
  /*  SAMMON - apply Sammon's nonlinear mapping  */
  /*  */
  /*     Y = SAMMON(X) applies Sammon's nonlinear mapping procedure on */
  /*     multivariate data X, where each row represents a pattern and each column */
  /*     represents a feature.  On completion, Y contains the corresponding */
  /*     co-ordinates of each point on the map.  By default, a two-dimensional */
  /*     map is created.  Note if X contains any duplicated rows, SAMMON will */
  /*     fail (ungracefully).  */
  /*  */
  /*     [Y,E] = SAMMON(X) also returns the value of the cost function in E (i.e. */
  /*     the stress of the mapping). */
  /*  */
  /*     An N-dimensional output map is generated by Y = SAMMON(X,N) . */
  /*  */
  /*     A set of optimisation options can also be specified using a third */
  /*     argument, Y = SAMMON(X,N,OPTS) , where OPTS is a structure with fields: */
  /*  */
  /*        MaxIter        - maximum number of iterations */
  /*        TolFun         - relative tolerance on objective function */
  /*        MaxHalves      - maximum number of step halvings */
  /*        Input          - {'raw','distance'} if set to 'distance', X is  */
  /*                         interpreted as a matrix of pairwise distances. */
  /*        Display        - {'off', 'on', 'iter'} */
  /*        Initialisation - {'pca', 'random'} */
  /*  */
  /*     The default options structure can be retrieved by calling SAMMON with */
  /*     no parameters. */
  /*  */
  /*     References : */
  /*  */
  /*        [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data Structure */
  /*            Analysis", IEEE Transactions on Computers, vol. C-18, no. 5, */
  /*            pp 401-409, May 1969. */
  /*  */
  /*     See also : SAMMON_TEST */
  /*  */
  /*  File        : sammon.m */
  /*  */
  /*  Date        : Monday 12th November 2007. */
  /*  */
  /*  Author      : Gavin C. Cawley and Nicola L. C. Talbot */
  /*  */
  /*  Description : Simple vectorised MATLAB implementation of Sammon's non-linear */
  /*                mapping algorithm [1]. */
  /*  */
  /*  References  : [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data */
  /*                    Structure Analysis", IEEE Transactions on Computers, */
  /*                    vol. C-18, no. 5, pp 401-409, May 1969. */
  /*  */
  /*  History     : 10/08/2004 - v1.00 */
  /*                11/08/2004 - v1.10 Hessian made positive semidefinite */
  /*                13/08/2004 - v1.11 minor optimisation */
  /*                12/11/2007 - v1.20 initialisation using the first n principal */
  /*                                   components. */
  /*  */
  /*  Thanks      : Dr Nick Hamilton ([email protected]) for supplying the */
  /*                code for implementing initialisation using the first n */
  /*                principal components (introduced in v1.20). */
  /*  */
  /*  To do       : The current version does not take advantage of the symmetry */
  /*                of the distance matrix in order to allow for easy */
  /*                vectorisation.  This may not be a good choice for very large */
  /*                datasets, so perhaps one day I'll get around to doing a MEX */
  /*                version using the BLAS library etc. for very large datasets. */
  /*  */
  /*  Copyright   : (c) Dr Gavin C. Cawley, November 2007. */
  /*  */
  /*     This program is free software; you can redistribute it and/or modify */
  /*     it under the terms of the GNU General Public License as published by */
  /*     the Free Software Foundation; either version 2 of the License, or */
  /*     (at your option) any later version. */
  /*  */
  /*     This program is distributed in the hope that it will be useful, */
  /*     but WITHOUT ANY WARRANTY; without even the implied warranty of */
  /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
  /*     GNU General Public License for more details. */
  /*  */
  /*     You should have received a copy of the GNU General Public License */
  /*     along with this program; if not, write to the Free Software */
  /*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  /*  */
  /*  use the default options structure */
  /*  create distance matrix unless given by parameters */
  euclid(x, x, D);

  /*  remaining initialisation */
  eye(x->size[0], delta);
  i0 = D->size[0] * D->size[1];
  emxEnsureCapacity((emxArray__common *)D, i0, (int32_T)sizeof(real_T));
  b_D = D->size[0];
  br = D->size[1];
  br *= b_D;
  for (i0 = 0; i0 < br; i0++) {
    D->data[i0] += delta->data[i0];
  }

  emxInit_real_T(&Dinv, 2);
  emxInit_real_T(&d, 2);
  rdivide(D, Dinv);
  randn(x->size[0], y);
  b_euclid(y, y, d);
  eye(x->size[0], delta);
  i0 = d->size[0] * d->size[1];
  emxEnsureCapacity((emxArray__common *)d, i0, (int32_T)sizeof(real_T));
  b_D = d->size[0];
  br = d->size[1];
  br *= b_D;
  for (i0 = 0; i0 < br; i0++) {
    d->data[i0] += delta->data[i0];
  }

  emxInit_real_T(&dinv, 2);
  emxInit_real_T(&c_D, 2);
  rdivide(d, dinv);
  i0 = c_D->size[0] * c_D->size[1];
  c_D->size[0] = D->size[0];
  c_D->size[1] = D->size[1];
  emxEnsureCapacity((emxArray__common *)c_D, i0, (int32_T)sizeof(real_T));
  br = D->size[0] * D->size[1];
  for (i0 = 0; i0 < br; i0++) {
    c_D->data[i0] = D->data[i0] - d->data[i0];
  }

  emxInit_real_T(&b_delta, 2);
  power(c_D, delta);
  i0 = b_delta->size[0] * b_delta->size[1];
  b_delta->size[0] = delta->size[0];
  b_delta->size[1] = delta->size[1];
  emxEnsureCapacity((emxArray__common *)b_delta, i0, (int32_T)sizeof(real_T));
  br = delta->size[0] * delta->size[1];
  emxFree_real_T(&c_D);
  for (i0 = 0; i0 < br; i0++) {
    b_delta->data[i0] = delta->data[i0] * Dinv->data[i0];
  }

  emxInit_real_T(&b_x, 2);
  c_sum(b_delta, b_x);
  E = d_sum(b_x);

  /*  get on with it */
  i = 0;
  emxFree_real_T(&b_delta);
  emxInit_real_T(&deltaone, 2);
  emxInit_real_T(&g, 2);
  emxInit_real_T(&y2, 2);
  emxInit_real_T(&H, 2);
  b_emxInit_real_T(&s, 1);
  emxInit_real_T(&C, 2);
  emxInit_real_T(&b_C, 2);
  emxInit_real_T(&c_delta, 2);
  emxInit_real_T(&d_D, 2);
  b_emxInit_real_T(&b_deltaone, 1);
  exitg1 = FALSE;
  while ((exitg1 == FALSE) && (i < 500)) {
    /*  compute gradient, Hessian and search direction (note it is actually */
    /*  1/4 of the gradient and Hessian, but the step size is just the ratio */
    /*  of the gradient and the diagonal of the Hessian so it doesn't matter). */
    i0 = delta->size[0] * delta->size[1];
    delta->size[0] = dinv->size[0];
    delta->size[1] = dinv->size[1];
    emxEnsureCapacity((emxArray__common *)delta, i0, (int32_T)sizeof(real_T));
    br = dinv->size[0] * dinv->size[1];
    for (i0 = 0; i0 < br; i0++) {
      delta->data[i0] = dinv->data[i0] - Dinv->data[i0];
    }

    guard2 = FALSE;
    if (delta->size[1] == 1) {
      guard2 = TRUE;
    } else {
      b_D = x->size[0];
      if (b_D == 1) {
        guard2 = TRUE;
      } else {
        unnamed_idx_0 = (uint32_T)delta->size[0];
        i0 = deltaone->size[0] * deltaone->size[1];
        deltaone->size[0] = (int32_T)unnamed_idx_0;
        deltaone->size[1] = 2;
        emxEnsureCapacity((emxArray__common *)deltaone, i0, (int32_T)sizeof
                          (real_T));
        br = (int32_T)unnamed_idx_0 << 1;
        for (i0 = 0; i0 < br; i0++) {
          deltaone->data[i0] = 0.0;
        }

        if (delta->size[0] == 0) {
        } else {
          b_D = 0;
          while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
            i0 = b_D + delta->size[0];
            for (ic = b_D; ic + 1 <= i0; ic++) {
              deltaone->data[ic] = 0.0;
            }

            b_D += delta->size[0];
          }

          br = 0;
          b_D = 0;
          while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
            ar = 0;
            i0 = br + delta->size[1];
            for (ib = br + 1; ib <= i0; ib++) {
              ia = ar;
              i1 = b_D + delta->size[0];
              for (ic = b_D; ic + 1 <= i1; ic++) {
                ia++;
                deltaone->data[ic] += delta->data[ia - 1];
              }

              ar += delta->size[0];
            }

            br += delta->size[1];
            b_D += delta->size[0];
          }
        }
      }
    }

    if (guard2 == TRUE) {
      i0 = deltaone->size[0] * deltaone->size[1];
      deltaone->size[0] = delta->size[0];
      deltaone->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)deltaone, i0, (int32_T)sizeof(real_T));
      br = delta->size[0];
      for (i0 = 0; i0 < br; i0++) {
        for (i1 = 0; i1 < 2; i1++) {
          deltaone->data[i0 + deltaone->size[0] * i1] = 0.0;
          ar = delta->size[1];
          for (b_D = 0; b_D < ar; b_D++) {
            deltaone->data[i0 + deltaone->size[0] * i1] += delta->data[i0 +
              delta->size[0] * b_D];
          }
        }
      }
    }

    if ((delta->size[1] == 1) || (y->size[0] == 1)) {
      i0 = g->size[0] * g->size[1];
      g->size[0] = delta->size[0];
      g->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)g, i0, (int32_T)sizeof(real_T));
      br = delta->size[0];
      for (i0 = 0; i0 < br; i0++) {
        for (i1 = 0; i1 < 2; i1++) {
          g->data[i0 + g->size[0] * i1] = 0.0;
          ar = delta->size[1];
          for (b_D = 0; b_D < ar; b_D++) {
            g->data[i0 + g->size[0] * i1] += delta->data[i0 + delta->size[0] *
              b_D] * y->data[b_D + y->size[0] * i1];
          }
        }
      }
    } else {
      unnamed_idx_0 = (uint32_T)delta->size[0];
      i0 = g->size[0] * g->size[1];
      g->size[0] = (int32_T)unnamed_idx_0;
      g->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)g, i0, (int32_T)sizeof(real_T));
      br = (int32_T)unnamed_idx_0 << 1;
      for (i0 = 0; i0 < br; i0++) {
        g->data[i0] = 0.0;
      }

      if (delta->size[0] == 0) {
      } else {
        b_D = 0;
        while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
          i0 = b_D + delta->size[0];
          for (ic = b_D; ic + 1 <= i0; ic++) {
            g->data[ic] = 0.0;
          }

          b_D += delta->size[0];
        }

        br = 0;
        b_D = 0;
        while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
          ar = 0;
          i0 = br + delta->size[1];
          for (ib = br; ib + 1 <= i0; ib++) {
            if (y->data[ib] != 0.0) {
              ia = ar;
              i1 = b_D + delta->size[0];
              for (ic = b_D; ic + 1 <= i1; ic++) {
                ia++;
                g->data[ic] += y->data[ib] * delta->data[ia - 1];
              }
            }

            ar += delta->size[0];
          }

          br += delta->size[1];
          b_D += delta->size[0];
        }
      }
    }

    i0 = g->size[0] * g->size[1];
    g->size[1] = 2;
    emxEnsureCapacity((emxArray__common *)g, i0, (int32_T)sizeof(real_T));
    b_D = g->size[0];
    br = g->size[1];
    br *= b_D;
    for (i0 = 0; i0 < br; i0++) {
      g->data[i0] -= y->data[i0] * deltaone->data[i0];
    }

    c_power(dinv, delta);
    b_power(y, y2);
    if ((delta->size[1] == 1) || (y2->size[0] == 1)) {
      i0 = H->size[0] * H->size[1];
      H->size[0] = delta->size[0];
      H->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)H, i0, (int32_T)sizeof(real_T));
      br = delta->size[0];
      for (i0 = 0; i0 < br; i0++) {
        for (i1 = 0; i1 < 2; i1++) {
          H->data[i0 + H->size[0] * i1] = 0.0;
          ar = delta->size[1];
          for (b_D = 0; b_D < ar; b_D++) {
            H->data[i0 + H->size[0] * i1] += delta->data[i0 + delta->size[0] *
              b_D] * y2->data[b_D + y2->size[0] * i1];
          }
        }
      }
    } else {
      unnamed_idx_0 = (uint32_T)delta->size[0];
      i0 = H->size[0] * H->size[1];
      H->size[0] = (int32_T)unnamed_idx_0;
      H->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)H, i0, (int32_T)sizeof(real_T));
      br = (int32_T)unnamed_idx_0 << 1;
      for (i0 = 0; i0 < br; i0++) {
        H->data[i0] = 0.0;
      }

      if (delta->size[0] == 0) {
      } else {
        b_D = 0;
        while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
          i0 = b_D + delta->size[0];
          for (ic = b_D; ic + 1 <= i0; ic++) {
            H->data[ic] = 0.0;
          }

          b_D += delta->size[0];
        }

        br = 0;
        b_D = 0;
        while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
          ar = 0;
          i0 = br + delta->size[1];
          for (ib = br; ib + 1 <= i0; ib++) {
            if (y2->data[ib] != 0.0) {
              ia = ar;
              i1 = b_D + delta->size[0];
              for (ic = b_D; ic + 1 <= i1; ic++) {
                ia++;
                H->data[ic] += y2->data[ib] * delta->data[ia - 1];
              }
            }

            ar += delta->size[0];
          }

          br += delta->size[1];
          b_D += delta->size[0];
        }
      }
    }

    if ((delta->size[1] == 1) || (y->size[0] == 1)) {
      i0 = C->size[0] * C->size[1];
      C->size[0] = delta->size[0];
      C->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)C, i0, (int32_T)sizeof(real_T));
      br = delta->size[0];
      for (i0 = 0; i0 < br; i0++) {
        for (i1 = 0; i1 < 2; i1++) {
          C->data[i0 + C->size[0] * i1] = 0.0;
          ar = delta->size[1];
          for (b_D = 0; b_D < ar; b_D++) {
            C->data[i0 + C->size[0] * i1] += delta->data[i0 + delta->size[0] *
              b_D] * y->data[b_D + y->size[0] * i1];
          }
        }
      }
    } else {
      unnamed_idx_0 = (uint32_T)delta->size[0];
      i0 = C->size[0] * C->size[1];
      C->size[0] = (int32_T)unnamed_idx_0;
      C->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)C, i0, (int32_T)sizeof(real_T));
      br = (int32_T)unnamed_idx_0 << 1;
      for (i0 = 0; i0 < br; i0++) {
        C->data[i0] = 0.0;
      }

      if (delta->size[0] == 0) {
      } else {
        b_D = 0;
        while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
          i0 = b_D + delta->size[0];
          for (ic = b_D; ic + 1 <= i0; ic++) {
            C->data[ic] = 0.0;
          }

          b_D += delta->size[0];
        }

        br = 0;
        b_D = 0;
        while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
          ar = 0;
          i0 = br + delta->size[1];
          for (ib = br; ib + 1 <= i0; ib++) {
            if (y->data[ib] != 0.0) {
              ia = ar;
              i1 = b_D + delta->size[0];
              for (ic = b_D; ic + 1 <= i1; ic++) {
                ia++;
                C->data[ic] += y->data[ib] * delta->data[ia - 1];
              }
            }

            ar += delta->size[0];
          }

          br += delta->size[1];
          b_D += delta->size[0];
        }
      }
    }

    guard1 = FALSE;
    if (delta->size[1] == 1) {
      guard1 = TRUE;
    } else {
      b_D = x->size[0];
      if (b_D == 1) {
        guard1 = TRUE;
      } else {
        unnamed_idx_0 = (uint32_T)delta->size[0];
        i0 = b_C->size[0] * b_C->size[1];
        b_C->size[0] = (int32_T)unnamed_idx_0;
        b_C->size[1] = 2;
        emxEnsureCapacity((emxArray__common *)b_C, i0, (int32_T)sizeof(real_T));
        br = (int32_T)unnamed_idx_0 << 1;
        for (i0 = 0; i0 < br; i0++) {
          b_C->data[i0] = 0.0;
        }

        if (delta->size[0] == 0) {
        } else {
          b_D = 0;
          while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
            i0 = b_D + delta->size[0];
            for (ic = b_D; ic + 1 <= i0; ic++) {
              b_C->data[ic] = 0.0;
            }

            b_D += delta->size[0];
          }

          br = 0;
          b_D = 0;
          while ((delta->size[0] > 0) && (b_D <= delta->size[0])) {
            ar = 0;
            i0 = br + delta->size[1];
            for (ib = br + 1; ib <= i0; ib++) {
              ia = ar;
              i1 = b_D + delta->size[0];
              for (ic = b_D; ic + 1 <= i1; ic++) {
                ia++;
                b_C->data[ic] += delta->data[ia - 1];
              }

              ar += delta->size[0];
            }

            br += delta->size[1];
            b_D += delta->size[0];
          }
        }
      }
    }

    if (guard1 == TRUE) {
      i0 = b_C->size[0] * b_C->size[1];
      b_C->size[0] = delta->size[0];
      b_C->size[1] = 2;
      emxEnsureCapacity((emxArray__common *)b_C, i0, (int32_T)sizeof(real_T));
      br = delta->size[0];
      for (i0 = 0; i0 < br; i0++) {
        for (i1 = 0; i1 < 2; i1++) {
          b_C->data[i0 + b_C->size[0] * i1] = 0.0;
          ar = delta->size[1];
          for (b_D = 0; b_D < ar; b_D++) {
            b_C->data[i0 + b_C->size[0] * i1] += delta->data[i0 + delta->size[0]
              * b_D];
          }
        }
      }
    }

    i0 = H->size[0] * H->size[1];
    H->size[1] = 2;
    emxEnsureCapacity((emxArray__common *)H, i0, (int32_T)sizeof(real_T));
    b_D = H->size[0];
    br = H->size[1];
    br *= b_D;
    for (i0 = 0; i0 < br; i0++) {
      H->data[i0] = ((H->data[i0] - deltaone->data[i0]) - 2.0 * y->data[i0] *
                     C->data[i0]) + y2->data[i0] * b_C->data[i0];
    }

    b_D = H->size[0] << 1;
    i0 = s->size[0];
    s->size[0] = b_D;
    emxEnsureCapacity((emxArray__common *)s, i0, (int32_T)sizeof(real_T));
    br = 0;
    do {
      exitg3 = 0;
      b_D = H->size[0] << 1;
      if (br <= b_D - 1) {
        s->data[br] = fabs(H->data[br]);
        br++;
      } else {
        exitg3 = 1;
      }
    } while (exitg3 == 0);

    i0 = s->size[0];
    s->size[0] = g->size[0] << 1;
    emxEnsureCapacity((emxArray__common *)s, i0, (int32_T)sizeof(real_T));
    br = g->size[0] << 1;
    for (i0 = 0; i0 < br; i0++) {
      s->data[i0] = -g->data[i0] / s->data[i0];
    }

    i0 = deltaone->size[0] * deltaone->size[1];
    deltaone->size[0] = y->size[0];
    deltaone->size[1] = 2;
    emxEnsureCapacity((emxArray__common *)deltaone, i0, (int32_T)sizeof(real_T));
    br = y->size[0] * y->size[1];
    for (i0 = 0; i0 < br; i0++) {
      deltaone->data[i0] = y->data[i0];
    }

    /*  use step-halving procedure to ensure progress is made */
    ib = 1;
    ia = 0;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (ia < 20)) {
      ib = ia + 1;
      b_D = deltaone->size[0] << 1;
      i0 = b_deltaone->size[0];
      b_deltaone->size[0] = b_D;
      emxEnsureCapacity((emxArray__common *)b_deltaone, i0, (int32_T)sizeof
                        (real_T));
      for (i0 = 0; i0 < b_D; i0++) {
        b_deltaone->data[i0] = deltaone->data[i0] + s->data[i0];
      }

      for (i0 = 0; i0 < 2; i0++) {
        b_y[i0] = y->size[i0];
      }

      i0 = y->size[0] * y->size[1];
      y->size[0] = b_y[0];
      y->size[1] = b_y[1];
      emxEnsureCapacity((emxArray__common *)y, i0, (int32_T)sizeof(real_T));
      br = b_y[1];
      for (i0 = 0; i0 < br; i0++) {
        ar = b_y[0];
        for (i1 = 0; i1 < ar; i1++) {
          y->data[i1 + y->size[0] * i0] = b_deltaone->data[i1 + b_y[0] * i0];
        }
      }

      b_euclid(y, y, d);
      b_D = x->size[0];
      i0 = delta->size[0] * delta->size[1];
      delta->size[0] = b_D;
      emxEnsureCapacity((emxArray__common *)delta, i0, (int32_T)sizeof(real_T));
      b_D = x->size[0];
      i0 = delta->size[0] * delta->size[1];
      delta->size[1] = b_D;
      emxEnsureCapacity((emxArray__common *)delta, i0, (int32_T)sizeof(real_T));
      br = x->size[0] * x->size[0];
      for (i0 = 0; i0 < br; i0++) {
        delta->data[i0] = 0.0;
      }

      E_new = x->size[0];
      u1 = x->size[0];
      if (E_new <= u1) {
      } else {
        E_new = u1;
      }

      b_D = (int32_T)E_new;
      if (b_D > 0) {
        for (br = 0; br + 1 <= b_D; br++) {
          delta->data[br + delta->size[0] * br] = 1.0;
        }
      }

      i0 = d->size[0] * d->size[1];
      emxEnsureCapacity((emxArray__common *)d, i0, (int32_T)sizeof(real_T));
      b_D = d->size[0];
      br = d->size[1];
      br *= b_D;
      for (i0 = 0; i0 < br; i0++) {
        d->data[i0] += delta->data[i0];
      }

      rdivide(d, dinv);
      i0 = d_D->size[0] * d_D->size[1];
      d_D->size[0] = D->size[0];
      d_D->size[1] = D->size[1];
      emxEnsureCapacity((emxArray__common *)d_D, i0, (int32_T)sizeof(real_T));
      br = D->size[0] * D->size[1];
      for (i0 = 0; i0 < br; i0++) {
        d_D->data[i0] = D->data[i0] - d->data[i0];
      }

      power(d_D, delta);
      i0 = c_delta->size[0] * c_delta->size[1];
      c_delta->size[0] = delta->size[0];
      c_delta->size[1] = delta->size[1];
      emxEnsureCapacity((emxArray__common *)c_delta, i0, (int32_T)sizeof(real_T));
      br = delta->size[0] * delta->size[1];
      for (i0 = 0; i0 < br; i0++) {
        c_delta->data[i0] = delta->data[i0] * Dinv->data[i0];
      }

      c_sum(c_delta, b_x);
      if (b_x->size[1] == 0) {
        E_new = 0.0;
      } else {
        E_new = b_x->data[0];
        for (br = 2; br <= b_x->size[1]; br++) {
          E_new += b_x->data[br - 1];
        }
      }

      if (E_new < E) {
        exitg2 = TRUE;
      } else {
        i0 = s->size[0];
        emxEnsureCapacity((emxArray__common *)s, i0, (int32_T)sizeof(real_T));
        br = s->size[0];
        for (i0 = 0; i0 < br; i0++) {
          s->data[i0] *= 0.5;
        }

        ia++;
      }
    }

    /*  bomb out if too many halving steps are required */
    if ((ib == 20) || (fabs((E - E_new) / E) < 1.0E-9)) {
      exitg1 = TRUE;
    } else {
      /*  evaluate termination criterion */
      /*  report progress */
      E = E_new;
      i++;
    }
  }

  emxFree_real_T(&b_deltaone);
  emxFree_real_T(&d_D);
  emxFree_real_T(&c_delta);
  emxFree_real_T(&b_x);
  emxFree_real_T(&b_C);
  emxFree_real_T(&C);
  emxFree_real_T(&s);
  emxFree_real_T(&H);
  emxFree_real_T(&y2);
  emxFree_real_T(&g);
  emxFree_real_T(&deltaone);
  emxFree_real_T(&delta);
  emxFree_real_T(&dinv);
  emxFree_real_T(&d);
  emxFree_real_T(&Dinv);
  emxFree_real_T(&D);

  /*  fiddle stress to match the original Sammon paper */
}
Exemplo n.º 29
0
mp_integer bv_spect::max_value() const
{
  return is_signed?power(2, width-1)-1:
                   power(2, width)-1;
}
Exemplo n.º 30
0
void Tester_68k::testNeg() {
    u16 opcode;

    //MOVE.L    #$12345678, D0
    //MOVE      #0, CCR
    //NEG.B     D0
    setUp();
    opcode = 0x4400 | (0 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0x12345678);
    process();
    check("NEG.B D0");

    //MOVE.L    #$12345600, D0
    //MOVE      #0, CCR
    //NEG.B     D0
    setUp();
    opcode = 0x4400 | (0 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0x12345600);
    process();
    check("NEG.B D0 alt");

    //MOVE.L    #$12345680, D0
    //MOVE      #0, CCR
    //NEG.B     D0
    setUp();
    opcode = 0x4400 | (0 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0x12345680);
    process();
    check("NEG.B D0 overflow");

    //MOVE.L    #$12348000, D0
    //MOVE      #0, CCR
    //NEG.W     D0
    setUp();
    opcode = 0x4400 | (1 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0x12348000);
    process();
    check("NEG.W D0 overflow");

    //MOVE.L    #$12345678, D0
    //MOVE      #0, CCR
    //NEG.L     D0
    setUp();
    opcode = 0x4400 | (2 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0x12345678);
    process();
    check("NEG.L D0");

    //MOVE.L    #$ffffffff, D0
    //MOVE      #0, CCR
    //NEG.L     D0
    setUp();
    opcode = 0x4400 | (2 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0xffffffff);
    process();
    check("NEG.L D0 alt");

    //MOVE.L    #$f0012311, $3000
    //MOVE      #0, CCR
    //NEG.L     ($3000).L
    //MOVE.L    $3000, D0
    setUp();
    opcode = 0x4400 | (2 << 6) | getEA(ABS_LONG);
    addWord(opcode);
    addWord(0);
    addWord(0x3000);
    addWord(0xffff);
    power();
    memoryblock.writeLong(0x3000, 0xf0012311);
    process();
    check("NEG.L ($3000).L");
}