Пример #1
0
void DestinationDef::set_xyz(Double left, Double top, Double z)
{
    set_string(MODE, "XYZ");
    set_double(LEFT, left);
    set_double(TOP, top);
    set_double(ZOOM, z);
}
Пример #2
0
void DoubleFieldManipulator::set_from(
	char *location,
	const FieldManipulator& sourceManipulator,
	const char *sourceLocation) const
{
	set_double(location, sourceManipulator.get_double(sourceLocation));
}
Пример #3
0
	void	as_value::operator=(const as_value& v)
	{
		switch (v.m_type)
		{
			case UNDEFINED:
				set_undefined();
				break;

			case NUMBER:
				set_double(v.m_number);
				m_flags = v.m_flags;
				break;

			case BOOLEAN:
				set_bool(v.m_bool);
				m_flags = v.m_flags;
				break;

			case STRING:
				set_tu_string(v.m_string);
				m_flags = v.m_flags;
				break;

			case OBJECT:
				set_as_object(v.m_object);
				m_flags = v.m_flags;
				break;

			case PROPERTY:
				drop_refs(); 
				
				// is binded property ?
				if (v.m_property_target == NULL)
				{
					m_type = PROPERTY;
					m_property = v.m_property;
					m_property_target = NULL;
				}
				else
				{
					v.get_property(this);
				}
				m_flags = v.m_flags;

				break;

			default:
				assert(0);
		}
	}
Пример #4
0
void Value::set_immediate_from_static_field(InstanceClass* ic, int offset) {
  TypeArray::Raw f = ic->fields();
  Oop::Raw object;

  for (int index = 0; index < f().length(); index += 5) {
    Field static_field(ic, index);

    if (static_field.offset() == offset) {
      // Note: there may be a non-static field with the same 'offset'
      // as the static field we're trying to find.
      if (static_field.is_final() && static_field.is_static()) {
        switch (static_field.type()) {
          case T_BOOLEAN : // fall-through - stored as 32-bit
          case T_CHAR    : // fall-through - stored as 32-bit
          case T_BYTE    : // fall-through - stored as 32-bit
          case T_SHORT   : // fall-through - stored as 32-bit
          case T_INT     : set_int(ic->int_field(offset));       break;

          case T_ARRAY   : // fall-through
          case T_OBJECT  :
            // Note: if setting immediate for object fields is enabled for cross
            // generator, this reference will be written to the TEXT block as a
            // part of relocation information for the compiled method. The
            // problem is that the referenced object may be put to the HEAP
            // block and it would be impossible to write its reference
            // in the TEXT block. At this point we don't know the block type of
            // the referenced object, so for now we disable setting immediate
            // for cross generator.
            if (!USE_AOT_COMPILATION || !GenerateROMImage) {
              object = ic->obj_field(offset); 
              set_obj(&object);
            }
            break;
#if ENABLE_FLOAT
          case T_FLOAT   : set_float(ic->float_field(offset));   break;
          case T_DOUBLE  : set_double(ic->double_field(offset)); break;
#endif
          case T_LONG    : set_long(ic->long_field(offset));     break;
          default        : SHOULD_NOT_REACH_HERE();              break;
        }
      }
      return;
    }
  }

  // This field is not final and was removed from the fields array
  // during romization
}
Пример #5
0
int main (int argc, char const *argv[])
{
    // Continue to the breakpoint in set_char()
    set_char();         //// continue; var i; val -set 99 1
    set_uchar();        //// continue; var i; val -set 99 2
    set_short();        //// continue; var i; val -set -42 3
    set_ushort();       //// continue; var i; val -set 42 4
    set_int();          //// continue; var i; val -set -42 5
    set_uint();         //// continue; var i; val -set 42 6
    set_long();         //// continue; var i; val -set -42 7
    set_ulong();        //// continue; var i; val -set 42 8
    set_float();        //// continue; var i; val -set 123.456 9
    set_double();       //// continue; var i; val -set 123.456 10
    set_long_double();  //// continue; var i; val -set 123.456 11
    set_point ();       //// continue
    return 0;
}
Пример #6
0
void DoubleFieldManipulator::set_int(char *location, int value) const
{
	set_double(location, static_cast<double>(value));
}
Пример #7
0
static SANE_Status
scan_area_and_windows (Tamarack_Scanner *s)
{
  struct def_win_par dwp;

  memset (&dwp,'\0',sizeof (dwp));
  dwp.dwph.opc = TAMARACK_SCSI_AREA_AND_WINDOWS;
  set_triple (dwp.dwph.len,8 + sizeof (dwp.wdb)); 

  set_double (dwp.wdh.wpll, sizeof (dwp.wdb));

  dwp.wdb.winid = WINID;
  set_double (dwp.wdb.xres, (int) SANE_UNFIX (s->val[OPT_RESOLUTION].w));
  set_double (dwp.wdb.yres, (int) SANE_UNFIX (s->val[OPT_RESOLUTION].w));

  set_quad (dwp.wdb.ulx, (int) (47.2 * SANE_UNFIX (s->val[OPT_TL_X].w)));
  set_quad (dwp.wdb.uly, (int) (47.2 * SANE_UNFIX (s->val[OPT_TL_Y].w)));
  set_quad (dwp.wdb.width, 
     (int) (47.2 * SANE_UNFIX (s->val[OPT_BR_X].w - s->val[OPT_TL_X].w)));
  set_quad (dwp.wdb.length,
     (int) (47.2 * SANE_UNFIX (s->val[OPT_BR_Y].w - s->val[OPT_TL_Y].w)));

  dwp.wdb.brightness = sign_mag (SANE_UNFIX (s->val[OPT_BRIGHTNESS].w));
  dwp.wdb.contrast   = sign_mag (SANE_UNFIX (s->val[OPT_CONTRAST].w));
  dwp.wdb.thresh     = 0x80;


  switch (s->mode) {
  case THRESHOLDED:
    dwp.wdb.bpp = 1;
    dwp.wdb.image_comp = 0;
    dwp.wdb.thresh     = 1 + 2.55 * (SANE_UNFIX (s->val[OPT_THRESHOLD].w)); 
    break;
  case DITHERED:
    dwp.wdb.bpp = 1;
    dwp.wdb.image_comp = 1;
    break;
  case GREYSCALE:
    dwp.wdb.bpp = 8;
    dwp.wdb.image_comp = 2;
    break;
  case TRUECOLOR:
    dwp.wdb.bpp = 8;
    dwp.wdb.image_comp = 2;
    break;
  default:
    DBG(1, "Invalid mode. %d\n", s->mode);
    return SANE_STATUS_INVAL;
  }
  DBG(1, "bright, thresh, contrast = %d(%5.1f), %d, %d(%5.1f)\n", 
      dwp.wdb.brightness, SANE_UNFIX (s->val[OPT_BRIGHTNESS].w),
      dwp.wdb.thresh    ,
      dwp.wdb.contrast  , SANE_UNFIX (s->val[OPT_CONTRAST].w));

  set_double (dwp.wdb.halftone, 1); /* XXX What does this do again ? */
  dwp.wdb.pad_type   = 3;           /* This is the only usable pad-type. */
  dwp.wdb.exposure   = 0x6f;        /* XXX Option? */
  dwp.wdb.compr_type = 0;

  /* XXX Shouldn't this be sizeof (dwp) */
  return sanei_scsi_cmd (s->fd, &dwp, (10+8+38), 0, 0);
}
Пример #8
0
	as_value::as_value(int val) :
		m_type(UNDEFINED),
		m_flags(0)
	{
		set_double(val);
	}
Пример #9
0
int CLIF_arg_double (CLIF_argument *argm, char *arg, int index) {

	return  set_double (argm->data, arg);
}
Пример #10
0
int CLIF_set_double (CLIF_option *optn, char *arg) {

	return  set_double (optn->data, arg);
}
Пример #11
0
BYTE cmd_line_parse(int argc, char **argv) {
	int longIndex = 0, opt = 0;

	opt = getopt_long(argc, argv, opt_short, opt_long, &longIndex);
	while (opt != -1) {
		switch (opt) {
			case 0:
				/* long options */
				if (!(strcmp(opt_long[longIndex].name, "swap-duty"))) {
					set_int(cfg_from_file.swap_duty, SET_SWAP_DUTY);
				} else if (!(strcmp(opt_long[longIndex].name, "swap-emphasis"))) {
					set_int(cfg_from_file.disable_swap_emphasis_pal, SET_SWAP_EMPHASIS_PAL);
				} else if (!(strcmp(opt_long[longIndex].name, "portable"))) {
					/* l'ho gia' controllato quindi qui non faccio niente */
				} else if (!(strcmp(opt_long[longIndex].name, "txt-on-screen"))) {
					set_int(cfg_from_file.txt_on_screen, SET_TEXT_ON_SCREEN);
				} else if (!(strcmp(opt_long[longIndex].name, "overscan-brd-ntsc"))) {
					set_oscan(SET_OVERSCAN_BRD_NTSC, 0);
				} else if (!(strcmp(opt_long[longIndex].name, "overscan-brd-pal"))) {
					set_oscan(SET_OVERSCAN_BRD_PAL, 1);
				} else if (!(strcmp(opt_long[longIndex].name, "par-soft-stretch"))) {
					set_int(cfg_from_file.PAR_soft_stretch, SET_PAR_SOFT_STRETCH);
				} else if (!(strcmp(opt_long[longIndex].name, "background-pause"))) {
					set_int(cfg_from_file.bck_pause, SET_BCK_PAUSE);
				} else if (!(strcmp(opt_long[longIndex].name, "language"))) {
					set_int(cfg_from_file.language, SET_GUI_LANGUAGE);
				}
				break;
			case 'a':
				set_int(cfg_from_file.apu.channel[APU_MASTER], SET_AUDIO);
				break;
			case 'b':
				set_int(cfg_from_file.audio_buffer_factor, SET_AUDIO_BUFFER_FACTOR);
				break;
			case 'c':
				set_int(cfg_from_file.channels_mode, SET_CHANNELS);
				break;
			case 'd':
				cfg_from_file.stereo_delay = set_double(5);
				break;
			case 'f':
				set_int(cfg_from_file.fps, SET_FPS);
				break;
			case 'g':
				set_int(cfg_from_file.cheat_mode, SET_CHEAT_MODE);
				break;
			case 'h':
			case '?':
				usage(basename(argv[0]));
				break;
			case 'V': {
				if (!info.portable) {
					fprintf(stdout, "%s %s\n", NAME, VERSION);
				} else {
					fprintf(stdout, "Portable %s %s\n", NAME, VERSION);
				}
				emu_quit(EXIT_SUCCESS);
				break;
			}
			case 'k':
				set_int(cfg_from_file.frameskip, SET_FRAMESKIP);
				break;
			case 'i':
				set_int(cfg_from_file.filter, SET_FILTER);
				break;
			case 'l':
				set_int(cfg_from_file.samplerate, SET_SAMPLERATE);
				break;
			case 'm':
				set_int(cfg_from_file.mode, SET_MODE);
				break;
			case 'n':
				set_int(cfg_from_file.ntsc_format, SET_NTSC_FORMAT);
				break;
			case 'o':
				set_int(cfg_from_file.oscan, SET_OVERSCAN_DEFAULT);
				break;
			case 'p':
				set_int(cfg_from_file.palette, SET_PALETTE);
				break;
			case 'q':
				set_int(cfg_from_file.audio_quality, SET_AUDIO_QUALITY);
				break;
#if defined (WITH_OPENGL)
			case 'r':
				set_int(cfg_from_file.render, SET_RENDERING);
				gfx_set_render(cfg_from_file.render);
				break;
#endif
			case 's':
				set_int(cfg_from_file.scale, SET_SCALE);
				gfx.scale_before_fscreen = cfg_from_file.scale;
				break;
			case 't':
				{
					int rc = settings_val_to_int(SET_STRETCH_FULLSCREEN, optarg);

					if (rc >= 0) {
						cfg_from_file.scale = !rc;
					}
				}
				break;
			case 'u':
				set_int(cfg_from_file.fullscreen, SET_FULLSCREEN);
				break;
			case 'v':
				set_int(cfg_from_file.vsync, SET_VSYNC);
				break;
			case 'e':
				set_int(cfg_from_file.pixel_aspect_ratio, SET_PAR);
				break;
			case 'j':
				set_int(cfg_from_file.interpolation, SET_INTERPOLATION);
				break;
			default:
				break;
		}

		opt = getopt_long(argc, argv, opt_short, opt_long, &longIndex);
	}
	return (optind);
}
Пример #12
0
/*

  INPUTS      :
  imgx         Spatial gradients under x.
  imgy         Spatial gradients under y.
  imgt         Temporal gradient (DFD): imgt = I(pi+depl,t+1) - I(pi,t)
  zone_val     Estimation support.
  etiq	       Support value to take into consderation.
  fen          Work window.
  ima_pond     Ponderation.

  OUTPUT      :
  d_param      Estimated motion model in the polynomial form.
 
  DESCRIPTION :
  Compute a robust estimation of the motion model.

  RETURN      :
  The number of pixels used for the computation.
  
*/
bool estimate_QUA_COMPLET(TImageFloat *imgx, TImageFloat *imgy,
			 TImageFloat *imgt, TImageShort *zone_val,
			 int etiq, TWindow win,
			 TImageFloat *ima_pond, Para *d_param)
{
  int           N; // Number of parameters

  N = d_param->nb_para;
  if (d_param->var_light)
    N++;

  int		cnt = 0;		// Pixel counter
  int		nb_pts_utiles = 0;	// Used pixel counter

  double	YTWY	  = 0.0;
  double	YTWXTheta = 0.0;

  double        *A_  = new double [N*N];
  double        **A  = new double* [N];
  double        *B   = new double [N];
  double        *X   = new double [N];
  double        *phi = new double [N];
  double        li_c = d_param->li_c;
  double        co_c = d_param->co_c;

  int		success = 0;	// return value
  int		x;		// column
  int		y;		// row
  int		i, j;
  
  for (i=0; i < N; i ++)
    A[i] = A_ + i*N;

  d_param->sigma2res = 0.0;
  set_double (X, 0.0, N);
  set_double (B, 0.0, N);
  set_double (&A[0][0], 0.0, N * N);

  // Diagonal pertubation, to assume that the matrix would be inversible
  for (i = 0; i < N; i++)
    A[i][i] = PERTURBATION;

  if (d_param->var_light)
    phi[N-1] = 1.0;  // For the global illumination variation parameter 

  for (y = win.dli; y <win.fli; y++)  {
    size_t	off   = MIJ(0, y, 0, ima_pond->nbco);
    short	*pval = &zone_val->ad[off];
    float	*pond = &ima_pond->ad[off];
    float	*pgx  = &imgx->ad[off];
    float	*pgy  = &imgy->ad[off];
    float	*pgt  = &imgt->ad[off];

    double	dy = (double) (y - li_c);

    for(x = win.dco; x < win.fco; x++) {
      double	dpond, dpgt;	// temporary values
      double	dx;

      if ((pval[x]==etiq) && (((pgx[x]!=0.0)||(pgy[x]!=0.0))||(pgt[x]!=0.0))){
	nb_pts_utiles++;
	if (pond[x] > POND_MINI) {
	  cnt++;

	  dpond = (double) pond[x];
	  dpgt  = (double) pgt[x];
	  dx    = (double) (x - co_c);

  	  phi[0]  = pgx[x];
	  phi[1]  = pgy[x];
	  phi[2]  = phi[0] * dx;
	  phi[3]  = phi[0] * dy;
	  phi[4]  = phi[1] * dx;
	  phi[5]  = phi[1] * dy;
	  phi[6]  = phi[2] * dx;
	  phi[7]  = phi[2] * dy;
	  phi[8]  = phi[3] * dy;
	  phi[9]  = phi[4] * dx;
	  phi[10] = phi[4] * dy;
	  phi[11] = phi[5] * dy;

	  // For the residual variance computation
	  if (d_param->compute_sigma2res)
	    YTWY += dpond * dpgt * dpgt;

	  for (i = 0; i < N; i++)  {
	    double	d = (double) phi[i] * dpond;

	    B[i] -= d * dpgt;
	    // Cumulation on a triangle matrix
	    for (j = 0; j <= i; j++)
	      A[i][j] +=  phi[j] * d;
	  }
	}
      }
    }
  }

  // Fill the upper triangle of the matrix
  for (i = 0; i < N; i++)
    for (j = i + 1; j < N; j++)
      A[i][j] = A[j][i];

  d_param->tx_pts = ((double)cnt)/nb_pts_utiles;

  if (cnt <= N * 2) {	// Not enough pixels
    delete [] A_;
    delete [] A;
    delete [] B;
    delete [] X;
    delete [] phi;
    return false;
  }

  // Solve AX = B by exploiting the symetry of the matrix
  success = resoud_mat_sym (&A[0][0], B, X, N, N);

  if (! success) {
    set_double (X, 0.0, N);
    return false;
  }

  // Convert the compact form to the polynomial form
  if (d_param->var_light) {
    for (i=0; i < N-1; i ++)
      d_param->thet[i] = X[i];
    d_param->thet[12] = X[N-1]; // Illumination variation
  }
  else {
    for (i=0; i < N; i ++)
      d_param->thet[i] = X[i];
  }
 
  if ( ! d_param->compute_sigma2res) {
    delete [] A_;
    delete [] A;
    delete [] B;
    delete [] X;
    delete [] phi;
    return true;
  }

  // Compute the residual variance
  YTWXTheta = dot_double (B, X, N);
  d_param->sigma2res = (YTWY - YTWXTheta) / (double) cnt;

  if ( ! d_param->compute_covariance) {
    delete [] A_;
    delete [] A;
    delete [] B;
    delete [] X;
    delete [] phi;
    return true;
  }

  // Compute the covariance matrix
  double *InvA_  = new double [N*N];
  double **InvA  = new double* [N];
  for (i=0; i < N; i ++)
    InvA[i] = InvA_ + i*N;

  success = inverse_mat_sym (&A[0][0], &InvA[0][0], N);
  if (! success) {
    return false;
  }
  update_covariance(&InvA[0][0], d_param);

  delete [] A_;
  delete [] A;
  delete [] B;
  delete [] X;
  delete [] phi;
  delete [] InvA_;
  delete [] InvA;

  return true;
}
Пример #13
0
void cmd_line_parse(int argc, uTCHAR **argv) {
	QStringList splitted;
	QString arg, key, skey, value, exe = QFileInfo(uQString(argv[0])).baseName();
	int opt = 0;

	for (int a = 1; a < argc; a++) {
		arg = uQString(argv[a]);
		splitted = arg.split("=");
		key = QString(splitted.at(0));

		if (key.startsWith("--") || key.startsWith("-")) {
			key = key.replace("-", "");

			for (unsigned int b = 0; b < LENGTH(opt_long); b++) {
				if ((opt_long[b].lopt == key) || (opt_long[b].sopt == key)) {
					skey = opt_long[b].sopt;
					if (opt_long[b].ra == req_arg) {
						if (splitted.count() > 1) {
							value = QString(splitted.at(1));
						} else {
							if ((a + 1) >= argc) {
								QMessageBox::warning(0,
									"Error",
									QString("%1: the option needs an arguments -- \"%2\"").arg(exe, key));
								usage(exe);
							} else {
								value = uQString(argv[++a]);
							}
						}
					}
					opt = (*((char *) skey.toLatin1().constData()));
				}
			}
		} else {
			umemset(info.rom_file, 0x00, usizeof(info.rom_file));
			ustrncpy(info.rom_file, uQStringCD(key), usizeof(info.rom_file) - 1);
			continue;
		}

		switch (opt) {
			case 0:
				// long options
				if (key == "swap-duty") {
					set_int(cfg_from_file.swap_duty, SET_SWAP_DUTY);
				} else if (key == "swap-emphasis") {
					set_int(cfg_from_file.disable_swap_emphasis_pal, SET_SWAP_EMPHASIS_PAL);
				} else if (key == "portable") {
					// l'ho gia' controllato quindi qui non faccio niente
				} else if (key == "txt-on-screen") {
					set_int(cfg_from_file.txt_on_screen, SET_TEXT_ON_SCREEN);
				} else if (key == "input-display") {
					set_int(cfg_from_file.input_display, SET_INPUT_DISPLAY);
				} else if (key == "disable-tv-noise") {
					set_int(cfg_from_file.disable_tv_noise, SET_DISABLE_TV_NOISE);
				} else if (key == "disable-sepia") {
					set_int(cfg_from_file.disable_sepia_color, SET_DISABLE_SEPIA_PAUSE);
#if defined (WITH_OPENGL)
				} else if (key == "disable-srgb-fbo") {
					set_int(cfg_from_file.disable_srgb_fbo, SET_DISABLE_SRGB_FBO);
#endif
				} else if (key == "overscan-brd-ntsc") {
					set_oscan(SET_OVERSCAN_BRD_NTSC, 0);
				} else if (key == "overscan-brd-pal") {
					set_oscan(SET_OVERSCAN_BRD_PAL, 1);
				} else if (key == "par-soft-stretch") {
					set_int(cfg_from_file.PAR_soft_stretch, SET_PAR_SOFT_STRETCH);
				} else if (key == "hide-sprites") {
					set_int(cfg_from_file.hide_sprites, SET_HIDE_SPRITES);
				} else if (key == "hide-background") {
					set_int(cfg_from_file.hide_background, SET_HIDE_BACKGROUND);
				} else if (key == "unlimited-sprites") {
					set_int(cfg_from_file.unlimited_sprites, SET_UNLIMITED_SPRITES);
				} else if (key == "save-battery-ram-file") {
					set_int(cfg_from_file.save_battery_ram_file, SET_BATTERY_RAM_FILE_EVEY_TOT);
				} else if (key == "background-pause") {
					set_int(cfg_from_file.bck_pause, SET_BCK_PAUSE);
				} else if (key == "language") {
					set_int(cfg_from_file.language, SET_GUI_LANGUAGE);
				} else if (key == "disable-new-menu") {
					set_int(cfg_from_file.disable_new_menu, SET_GUI_DISABLE_NEW_MENU);
				}
				break;
			case 'a':
				set_int(cfg_from_file.apu.channel[APU_MASTER], SET_AUDIO);
				break;
			case 'b':
				set_int(cfg_from_file.audio_buffer_factor, SET_AUDIO_BUFFER_FACTOR);
				break;
			case 'c':
				set_int(cfg_from_file.channels_mode, SET_CHANNELS);
				break;
			case 'd':
				cfg_from_file.stereo_delay = set_double(5);
				break;
			case 'f':
				set_int(cfg_from_file.fps, SET_FPS);
				break;
			case 'g':
				set_int(cfg_from_file.cheat_mode, SET_CHEAT_MODE);
				break;
			case 'h':
			case '?':
				usage(exe);
				break;
			case 'V': {
				if (!info.portable) {
					fprintf(stdout, "%s %s\n", NAME, VERSION);
				} else {
					fprintf(stdout, "Portable %s %s\n", NAME, VERSION);
				}
				emu_quit(EXIT_SUCCESS);
				break;
			}
			case 'k':
				set_int(cfg_from_file.frameskip, SET_FRAMESKIP);
				break;
			case 'i':
				set_int(cfg_from_file.filter, SET_FILTER);
				break;
			case 'l':
				set_int(cfg_from_file.samplerate, SET_SAMPLERATE);
				break;
			case 'm':
				set_int(cfg_from_file.mode, SET_MODE);
				break;
			case 'n':
				set_int(cfg_from_file.ntsc_format, SET_NTSC_FORMAT);
				break;
			case 'o':
				set_int(cfg_from_file.oscan, SET_OVERSCAN_DEFAULT);
				break;
			case 'p':
				set_int(cfg_from_file.palette, SET_PALETTE);
				break;
			case 'q':
				set_int(cfg_from_file.audio_quality, SET_AUDIO_QUALITY);
				break;
#if defined (WITH_OPENGL)
			case 'r':
				set_int(cfg_from_file.render, SET_RENDERING);
				gfx_set_render(cfg_from_file.render);
				break;
#endif
			case 's':
				set_int(cfg_from_file.scale, SET_SCALE);
				gfx.scale_before_fscreen = cfg_from_file.scale;
				break;
			case 't':
				{
					int rc = settings_val_to_int(SET_STRETCH_FULLSCREEN, oarg);

					if (rc >= 0) {
						cfg_from_file.scale = !rc;
					}
				}
				break;
			case 'u':
				set_int(cfg_from_file.fullscreen, SET_FULLSCREEN);
				break;
			case 'v':
				set_int(cfg_from_file.vsync, SET_VSYNC);
				break;
			case 'e':
				set_int(cfg_from_file.pixel_aspect_ratio, SET_PAR);
				break;
			case 'j':
				set_int(cfg_from_file.interpolation, SET_INTERPOLATION);
				break;
			default:
				break;
		}
	}
}
Пример #14
0
MG_PRIVATE mg_error_t mg_uint256_div(mg_uint256_t *op1, const mg_uint256_t *op2, mg_uint256_t *quotient)
{
	mg_error_t err = 0;
	double op1_v, op2_v, q_tmp;
	mg_uint256_t buf1, buf2, buf3;
	mg_uint256_t *q = &buf1, *qv = &buf2, *qv_hi = &buf3;
	int q_n;
	
	int op1_digits = mgUINT256_WORD_COUNT;
	while(op1_digits > 0 && op1->word[op1_digits-1] == 0)
		op1_digits--;
	int op2_digits = mgUINT256_WORD_COUNT;
	while(op2_digits > 0 && op2->word[op2_digits-1] == 0)
		op2_digits--;

	if(op2_digits <= 1) {
		if(op2_digits <= 0) {
			err = mgE_ZERODIVIDE;
			goto _ERROR;
		}

		if(op1_digits <= 1) {
			mg_uint256_set(quotient, op1->word[0] / op2->word[0]);
			mg_uint256_set(op1, op1->word[0] % op2->word[0]);
			goto _EXIT;
		}
	}

	op2_v = (double)op2->word[op2_digits -1];
	if(op2_digits >= 2)
		op2_v += (double)op2->word[op2_digits-2] * DOUBLE_RSHIFT_32;
	if(op2_digits >= 3)
		op2_v += (double)op2->word[op2_digits-3] * DOUBLE_RSHIFT_32 * DOUBLE_RSHIFT_32;

	mg_uint256_set_zero(quotient);

	while (op1_digits >= op2_digits && mg_uint256_compare(op1, op2) >= 0) {
		if(op2_digits <= 1 && op1_digits <= 1) {
			mg_uint256_set(/*out*/q, op1->word[0] / op2->word[0]);
			mg_uint256_set(/*out*/op1, op1->word[0] % op2->word[0]);

			mg_uint256_add(/*out*/quotient, q);
			goto _EXIT;
		}

		op1_v = (double)op1->word[op1_digits-1];
		if(op1_digits >= 2)
			op1_v += (double)op1->word[op1_digits-2] * DOUBLE_RSHIFT_32;

		if(op1_digits >= 3)
			op1_v += (double)op2->word[op1_digits-3] * DOUBLE_RSHIFT_32 * DOUBLE_RSHIFT_32;

		q_n = op1_digits - op2_digits;
		q_tmp = op1_v / op2_v;
		if((q_tmp < 1.0 && q_n == 0)) {
			q_tmp = 1.0;
		} else if(q_tmp >= DOUBLE_LSHIFT_32) {
			q_tmp *= DOUBLE_CORRECT;
		}
		set_double(q, q_tmp, q_n);

		bool overflow = mg_uint256_mul_digits(
			op2, op2_digits, q, q_n + 1, /*out*/qv);

		while(overflow || mg_uint256_compare(op1, qv) < 0) {
			q_tmp *= DOUBLE_CORRECT;
			set_double(q, q_tmp, q_n);

			overflow = mg_uint256_mul_digits(
				op2, op2_digits, q, q_n + 1, /*out*/qv);
		}

		int borrow = mg_uint256_sub(op1, qv);
		assert(borrow == 0);
		mg_uint256_add(quotient, q);

		while(op1_digits > 0 && op1->word[op1_digits-1] == 0)
			op1_digits--;
	}
_EXIT:
	return 0;
_ERROR:
	return err;
}