• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ div函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中div函数的典型用法代码示例。如果您正苦于以下问题:C++ div函数的具体用法?C++ div怎么用?C++ div使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了div函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cgiMain

int cgiMain() {

  static char      title[256]        = "";
  static char   subtitle[256]        = "";
         char      sorting[16]       = "desc";
         time_t    now               = time(NULL);
         time_t    start             = time(NULL);
         time_t    expiration        = time(NULL);
         double    available_secs    = 0;
         double    remaining_secs    = 0;
  struct dirent    **certstore_files = NULL;
         int       pagenumber        = 1;
         int       certcounter       = 0;
         int       tempcounter       = 0;
         int       pagecounter       = 0;
         int       dispcounter       = 0;
         int       dispmaxlines      = 0;
         int       certvalidity      = 0;
         div_t     disp_calc;
         div_t     oddline_calc;
         double    percent           = 0;

         cert                        = X509_new();
         certsubject                 = X509_NAME_new();
	 char      **form_data       = NULL;  /* string array for query data */

  /* get the current time */
  now = time(NULL);

/* ------------------------------------------------------------------------- *
 * If we are called without arguments, we display the cert search criteria   *
 * ------------------------------------------------------------------------- */
  if (cgiFormEntries(&form_data) != cgiFormSuccess)
    int_error("Error: Could not retrieve CGI form data.");
  if(form_data[0] == NULL) {

    start_tm = *gmtime(&now);

    snprintf(title, sizeof(title), "Search existing Certificates");
    pagehead(title);
    fprintf(cgiOut, "<form action=\"certsearch.cgi\" method=\"get\">");
    fprintf(cgiOut, "<table>");

    /* Search for Subject String */
    fprintf(cgiOut, "<tr><th colspan=\"5\">Search by Name</th></tr>\n");
    fprintf(cgiOut, "<tr>\n");
    fprintf(cgiOut, "<th class=\"cnt\" rowspan=\"2\">\n");
    fprintf(cgiOut, "<input type=\"radio\" value=\"dn\" name=\"search\" />");
    fprintf(cgiOut, "</th>\n");
    fprintf(cgiOut, "<td class=\"type\">\n");
    fprintf(cgiOut, "Distinguished Name Field:");
    fprintf(cgiOut, "</td>\n");
    fprintf(cgiOut, "<td class=\"center\">\n");
    fprintf(cgiOut, "<select name=\"field\">");
    fprintf(cgiOut, "<option value=\"countryName\">Country</option>");
    fprintf(cgiOut, "<option value=\"stateOrProvinceName\">State</option>");
    fprintf(cgiOut, "<option value=\"localityName\">Location</option>");
    fprintf(cgiOut, "<option value=\"organizationName\">Organisation</option>");
    fprintf(cgiOut, "<option value=\"organizationalUnitName\">Department</option>");
    fprintf(cgiOut, "<option value=\"emailAddress\">E-Mail Addr</option>");
    fprintf(cgiOut, "<option selected=\"selected\" value=\"commonName\">Common Name</option>");
    fprintf(cgiOut, "<option value=\"surname\">Surname</option>");
    fprintf(cgiOut, "<option value=\"givenName\">Given Name</option>");
    fprintf(cgiOut, "</select>");
    fprintf(cgiOut, "</td>\n");
    fprintf(cgiOut, "<td class=\"type\">\n");
    fprintf(cgiOut, "Search String<br />[20 chars max]:");
    fprintf(cgiOut, "</td>\n");
    fprintf(cgiOut, "<td class=\"center\">\n");
    fprintf(cgiOut, "<input type=\"text\" size=\"15\" name=\"dnvalue\" value=\"changeme.com\" />");
    fprintf(cgiOut, "</td>");
    fprintf(cgiOut, "</tr>\n");
    fprintf(cgiOut, "<tr>\n");
    fprintf(cgiOut, "<td class=\"desc\" colspan=\"4\">\n");
    fprintf(cgiOut, "Search for certificates that have the given string in the selected DN field. ");
    fprintf(cgiOut, "The search is case sensitive, so results for country=us can be different from country=US and country=Us.");
    fprintf(cgiOut, "</td>\n");
    fprintf(cgiOut, "</tr>\n");

    /* Search for Expiration Date */
    fprintf(cgiOut, "<tr><th colspan=\"5\">Search by Expiration Date</th></tr>\n");
    fprintf(cgiOut, "<tr>\n");
    fprintf(cgiOut, "<th class=\"cnt\" rowspan=\"2\">\n");
    fprintf(cgiOut, "<input type=\"radio\" value=\"exp\" name=\"search\" checked=\"checked\" />");
    fprintf(cgiOut, "</th>\n");
    fprintf(cgiOut, "<td class=\"type\">\n");
    fprintf(cgiOut, "Expiration Date is<br />between Start Date:");
    fprintf(cgiOut, "</td>\n");
    fprintf(cgiOut, "<td class=\"center\">\n");
    strftime(membio_buf, sizeof(membio_buf), "%d.%m.%Y", &start_tm);
    fprintf(cgiOut, "<input type=\"text\" size=\"9\" name=\"exp_startdate\" value=\"%s\" /> ", membio_buf);
    strftime(membio_buf, sizeof(membio_buf), "%H:%M", &start_tm);
    fprintf(cgiOut, "<input type=\"text\" size=\"3\" name=\"exp_starttime\" value=\"%s\" />", membio_buf);
    fprintf(cgiOut, "</td>");
    fprintf(cgiOut, "<td class=\"type\">\n");
    fprintf(cgiOut, "and End Date<br />[default 90 days]:");
    fprintf(cgiOut, "</td>\n");
    fprintf(cgiOut, "<td class=\"center\">\n");
    /* set second time 3 months (90 days) into the future: 86400s/d*90d=7776000s */
    expiration = now + 7776000;
//.........这里部分代码省略.........
开发者ID:fm4dd,项目名称:webcert,代码行数:101,代码来源:certsearch.c


示例2: mexFunction

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )    
{ 
	int			i,j,m,n;
    int			ifield, jstruct, *classIDflags;
    int			NStructElems, nfields, ndim, nsignal, nvals;
	const char  *field_name, *str;
	const		mxArray *field_array_ptr;
	double		dbl;
	float		*leadSnds[MAXCARRIERS], *lagSnds[MAXCARRIERS];
	float		*locations, *azimuths, *rove, *scalesLead, *scalesLag, *attensLead, *tmp;

	div_t div_result;

	InfoStruct recInfo;

    /* Check for proper number of arguments */    
    if (nrhs != 9)
		mexErrMsgTxt("9 input arguments required)."); 
	else if(!mxIsStruct(prhs[0]))
		mexErrMsgTxt("Input1 must be a structure.");

	// deal with the structure (arg0)
    nfields = mxGetNumberOfFields(prhs[0]);
    NStructElems = mxGetNumberOfElements(prhs[0]);

    /* check each field. */
	for(ifield=0; ifield<nfields; ifield++) 
	{
		field_name = mxGetFieldNameByNumber(prhs[0], ifield);
		field_array_ptr = mxGetFieldByNumber(prhs[0], 0, ifield); 

	    if (field_array_ptr == NULL)
			mexPrintf(".%s is empty\n", field_name);
		else
		{
			str = mxArrayToString(field_array_ptr);
			dbl = mxGetScalar(field_array_ptr);
			if(strncmp("FN1", field_name, 3) == 0)
				strncpy(recInfo.outFN1, str, MAX_FILENAME_LEN);

			if (strncmp("FN2",field_name, 3) ==0)
				strncpy(recInfo.outFN2, str, MAX_FILENAME_LEN);

			if (strncmp("record",field_name, 6) ==0)
				recInfo.record = (unsigned int) dbl;
		
			if (strncmp("latten",field_name, 6) ==0)
				recInfo.latten = (float) dbl;

			if (strncmp("ratten",field_name, 6) ==0)
				recInfo.ratten = (float) dbl;

			if (strncmp("n_trials",field_name,8) ==0)
				recInfo.n_trials = (unsigned int) dbl;

			if (strncmp("decimateFactor",field_name, 14) ==0)
				recInfo.decimateFactor = (unsigned int) dbl;

			if (strncmp("buf_pts",field_name, 7) ==0)
				recInfo.buf_pts = (long) dbl;

			if (strncmp("nptsTotalPlay",field_name, 13) ==0)
				recInfo.nptsTotalPlay = (long) dbl;

			if (strncmp("ISI",field_name, 3) ==0)
				recInfo.ISI = (unsigned int) dbl;

			if (strncmp("max_signal_jitter",field_name, 17) ==0)
				recInfo.max_signal_jitter = (unsigned int) dbl;

			if (strncmp("num_carriers",field_name, 12) ==0)
				recInfo.num_carriers = (unsigned int) dbl;

			if (strncmp("n_speakers",field_name, 10) ==0)
				recInfo.n_speakers = (unsigned int) dbl;

			if (strncmp("sound_onset",field_name, 11) ==0)
				recInfo.sound_onset = (long) dbl;
			
			if (strncmp("trials_to_show",field_name, 14) ==0)
				recInfo.trials_to_show = (long) dbl;

			if (strncmp("hab_loc",field_name, 7) ==0)
				recInfo.hab_loc = (float) dbl;

			if (strncmp("test_trial_freq",field_name, 15) ==0)
				recInfo.test_trial_freq = (float) dbl;
		}
	}


// check buf_pts = (n * 2^decimateFactor);
	div_result = div( recInfo.buf_pts, pow(2,recInfo.decimateFactor) );
    if(div_result.rem)
	{
		recInfo.buf_pts = pow(2,recInfo.decimateFactor) * (div_result.quot +1);
		mexPrintf("buf_pts and decimateFactor incompatable. buf_pts increased to %d \n",recInfo.buf_pts);
	}

// check nptsTotalPlay = (n * buf_pts)
//.........这里部分代码省略.........
开发者ID:ahoffman747,项目名称:tak-lab,代码行数:101,代码来源:play2_record2D2_alex5.c


示例3: MatLab4LocateParam

int MatLab4LocateParam( char *file_name , char *param_name , char *time_name ) {

        int len ;
        int temp ;
        int endian ;
        int mat_size ;
        int mat_type ;
        int my_byte_order ;
        div_t div_result ;
        int row , column , imaginary ;
        char * temp_ptr ;
        bool param_found , time_found ;
        FILE *fp ;
        bool swap = false ;
        int size ;
        int y_field_num , time_field_num ;
        int max_offset , offset = 0 ;

        TRICK_GET_BYTE_ORDER(my_byte_order) ;

        if ((fp = fopen(file_name , "r")) == 0 ) {
           std::cerr << "ERROR:  Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
           exit(-1) ;
        }

        // we use fseek calls to move around so I need to know the max offset of the file
        fseek( fp , 0 , SEEK_END ) ;
        max_offset = ftell(fp) ;
        rewind( fp ) ;

        // get field_num from param_name
        temp_ptr = rindex(param_name, '[') ;
        if ( temp_ptr != NULL ) {
                sscanf(&temp_ptr[1] , "%d" , &y_field_num ) ;
        }
        else {
                y_field_num = 0 ;
        }

        // get field_num from time_name
        temp_ptr = rindex(param_name, '[') ;
        if ( temp_ptr != NULL ) {
                sscanf(&temp_ptr[1] , "%d" , &time_field_num ) ;
        }
        else {
                time_field_num = 0 ;
        }

        param_found = time_found = false ;
        while ( offset < max_offset ) {

                // read the type in
                fread( &temp , 4 , 1 , fp ) ;
                if ( !strncmp( (char *)&temp , "MATL" , 4 )) {
                        return(0) ;
                }

                // byte swap it if it looks like we need to
                if ( temp & 0xFFFF0000 ) {
                        temp = trick_byteswap_int(temp) ;
                }

                div_result = div(temp , 1000) ;
                endian = div_result.quot ;
                temp = div_result.rem ;

                switch ( endian ) {
                        case 0:
                                swap = ( my_byte_order == TRICK_LITTLE_ENDIAN ) ? 0 : 1 ;
                                break ;
                        case 1:
                                swap = ( my_byte_order == TRICK_BIG_ENDIAN ) ? 0 : 1 ;
                                break ;
                        default:
                                fprintf(stderr,"Unknown endianness!\n") ;
                                fclose(fp) ;
                                return(0) ;
                                break ;
                }

                div_result = div( temp , 10 ) ;
                mat_size = div_result.quot ;
                mat_type = div_result.rem ;
                switch ( mat_size ) {
                        case 0:
                                size = 8 ;
                                break ;
                        case 1:
                                size = 4 ;
                                break ;
                        case 2:
                                size = 4 ;
                                break ;
                        case 3:
                                size = 2 ;
                                break ;
                        case 4:
                                size = 2 ;
                                break ;
                        case 5:
//.........这里部分代码省略.........
开发者ID:lonnell,项目名称:trick,代码行数:101,代码来源:MatLab4.cpp


示例4: incexc

ll incexc(vector<int> v, int i, int left, int lcmt){
    if(left==0) return div(lcmt);
    if(i==v.size()) return 0;
    return (incexc(v, i+1, left, lcmt)+
           ((left>0)? incexc(v, i+1, left-1, lcm(lcmt, v[i])) :0)) % MOD;
}
开发者ID:ABHINAVKR,项目名称:ACM,代码行数:6,代码来源:InclusionExclusion.cpp


示例5: main

int main(void)
{

    char choice='x';
    int a,b, exit=0;
    float fa,fb;

    do {
        printf("> ");
        fflush(stdin);
        scanf("%1s", &choice);
        switch(choice) {
            case '+':
                scanf("%d %d", &a, &b);
                printf("# %d\n",add(a,b));
                break;

            case '-':
                scanf("%d %d", &a, &b);
                printf("# %d\n",sub(a,b));
                break;

            case '/':
                scanf("%f %f", &fa, &fb);
                printf("# %.2f\n",div(fa, fb));
                break;

            case 'd':
                scanf("%d %d", &a, &b);
                printf("# %d\n",iDiv(a,b));
                break;

            case 'm':
                scanf("%d %d", &a, &b);
                printf("# %d\n",mod(a,b));
                break;

            case '*':
                scanf("%d %d", &a, &b);
                printf("# %d\n",mul(a,b));
                break;

            case '^':
                scanf("%d %d", &a,&b);
                printf("# %lld\n",nthPower(a, b));
                break;

            case '!':
                scanf("%d", &a);
                printf("# %lld\n",fact(a));
                break;

            case 's':
                scanf("%d", &a);
                printf("# %d\n",sum(a));
                break;

            case 'a':
                scanf("%d", &a);
                printf("# %.2f\n",avg(a));
                break;

            case 'c':
                scanf("%d %d", &a, &b);
                printf("# %lld\n",binom(a,b));
                break;

            case 'p':
                scanf("%d", &a);
                if(prime(a)) printf("# y\n");
                    else printf("# n\n");
                break;

            case 'q':
                exit = 1;
                break;

            default:printf("Unknown arguement: %c\n", choice);
        }
    } while(!exit);

    return 0;

}
开发者ID:hudecek,项目名称:Chomework-PB071-,代码行数:84,代码来源:calc.c


示例6: strlen


//.........这里部分代码省略.........
		    for(c = 0; c < 1; c++) {
		    	//
		        if(FT_Load_Char(face,0x4E2D+charcode-0x4E2D , FT_LOAD_RENDER)) {
		            fprintf(stderr, "FT_Load_Char failed\n");
		            free(font);
		            return NULL;
		        }

		        slot = face->glyph;
		        bmp = slot->bitmap;

		        //glyph_width = nextp2(bmp.width);
		        //glyph_height = nextp2(bmp.rows);

		        glyph_width = bmp.width;
		        glyph_height = bmp.rows;

		        if (glyph_width > segment_size_x) {
		            segment_size_x = glyph_width;
		        }

		        if (glyph_width > m_max_x)
		        	m_max_x = glyph_width;

		        if (glyph_height > segment_size_y) {
		            segment_size_y = glyph_height;
		        }

		        if (glyph_height > m_max_y)
		 		     m_max_y = glyph_height;
		    }

		    int font_tex_width = nextp2(num_segments_x * segment_size_x);
		    int font_tex_height = nextp2(num_segments_y * segment_size_y);

		    int bitmap_offset_x = 0, bitmap_offset_y = 0;

		    GLubyte* font_texture_data = (GLubyte*) malloc(sizeof(GLubyte) * 2 * font_tex_width * font_tex_height);
		    memset((void*)font_texture_data, 0, sizeof(GLubyte) * 2 * font_tex_width * font_tex_height);

		    if (!font_texture_data) {
		        fprintf(stderr, "Failed to allocate memory for font texture\n");
		        free(font);
		        return NULL;
		    }

		    // Fill font texture bitmap with individual bmp data and record appropriate size, texture coordinates and offsets for every glyph
		    for(c = 0; c < 1; c++)
		    {
		    	   if(FT_Load_Char(face,0x4E2D+charcode-0x4E2D , FT_LOAD_RENDER)) {
		            fprintf(stderr, "FT_Load_Char failed\n");
		            free(font);
		            return NULL;
		        }

		        slot = face->glyph;
		        bmp = slot->bitmap;

		        glyph_width = nextp2(bmp.width);
		        glyph_height = nextp2(bmp.rows);

		        div_t temp = div(c, num_segments_x);

		        bitmap_offset_x = segment_size_x * temp.rem;
		        bitmap_offset_y = segment_size_y * temp.quot;

		        for (j = 0; j < glyph_height; j++) {
		            for (i = 0; i < glyph_width; i++) {
		                font_texture_data[2 * ((bitmap_offset_x + i) + (j + bitmap_offset_y) * font_tex_width) + 0] =
		                font_texture_data[2 * ((bitmap_offset_x + i) + (j + bitmap_offset_y) * font_tex_width) + 1] =
		                    (i >= bmp.width || j >= bmp.rows)? 0 : bmp.buffer[i + bmp.width * j];
		            }
		        }

		        font->advance[c] = (float)(slot->advance.x >> 6);
		        font->tex_x1[c] = (float)bitmap_offset_x / (float) font_tex_width;
		        font->tex_x2[c] = (float)(bitmap_offset_x + bmp.width) / (float)font_tex_width;
		        font->tex_y1[c] = (float)bitmap_offset_y / (float) font_tex_height;
		        font->tex_y2[c] = (float)(bitmap_offset_y + bmp.rows) / (float)font_tex_height;
		        font->width[c] = bmp.width;
		        font->height[c] = bmp.rows;
		        font->offset_x[c] = (float)slot->bitmap_left;
		        font->offset_y[c] =  (float)((slot->metrics.horiBearingY-face->glyph->metrics.height) >> 6);
		    }


		    glBindTexture(GL_TEXTURE_2D, font->font_texture);
		    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

		    glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, font_tex_width, font_tex_height, 0, GL_LUMINANCE_ALPHA , GL_UNSIGNED_BYTE, font_texture_data);

		  //  fprintf(stderr, "charcode %d %d\n",charcode, cci);
		    fflush(stderr);
		    free(font_texture_data);
		    font->initialized = 1;
m_map[charcode] = font;
}
p += 2;
}
开发者ID:cubezone,项目名称:zaOS,代码行数:101,代码来源:zaFont.cpp


示例7: read_llb

int
read_llb(h2fmi_read_boot_page_t read_page, int offset, int size, unsigned char *buf)
{
    int rv = 0;
    int page = div(offset, LLB_PAGE_SIZE); /*offset / LLB_PAGE_SIZE*/
    int start = offset - page * LLB_PAGE_SIZE; /*offset % LLB_PAGE_SIZE*/
#if 0
    unsigned char *tmp = malloc_(4096);
    if (!tmp) {
        return -1;
    }

    for (page += 2; size > 0; page++) {
        int chunk = size;
        if (chunk > LLB_PAGE_SIZE - start) {
            chunk = LLB_PAGE_SIZE - start;
        }

        rv = read_page(0, page, tmp);
        if (rv) {
            break;
        }

        memcpy(buf, tmp + start, chunk);

        start = 0;
        buf += chunk;
        size -= chunk;
    }
#else  /* XXX more efficient, but should be used ONLY if read_page reads exactly LLB_PAGE_SIZE bytes */
    unsigned char *tmp = NULL;

    page += 2;
    if (start) {
        int chunk = LLB_PAGE_SIZE - start;
        if (!(tmp = malloc_(LLB_PAGE_SIZE))) return -1;
        rv = read_page(0, page, tmp);
        if (rv) {
            goto err;
        }
        memcpy(buf, tmp + start, chunk);
        buf += chunk;
        size -= chunk;
        page++;
    }

    for (; size >= LLB_PAGE_SIZE; page++) {
        rv = read_page(0, page, buf);
        if (rv) {
            goto err;
        }
        buf += LLB_PAGE_SIZE;
        size -= LLB_PAGE_SIZE;
    }

    if (size) {
        if (!tmp && !(tmp = malloc_(LLB_PAGE_SIZE))) return -1;
        rv = read_page(0, page, tmp);
        if (rv == 0) {
            memcpy(buf, tmp, size);
        }
    }

  err:
#endif

    free_(tmp);
    return rv;
}
开发者ID:Styden,项目名称:ibex,代码行数:69,代码来源:nand.c


示例8: div

 bigint& operator %=(const bigint& x){ div(x); return *this; }
开发者ID:viniciusmalloc,项目名称:lib-monkeys,代码行数:1,代码来源:bignum.cpp


示例9: flexframesync_decode_header


//.........这里部分代码省略.........
    if (_q->header[n+0] != FLEXFRAME_VERSION) {
        fprintf(stderr,"warning: flexframesync_decode_header(), invalid framing version\n");
        _q->header_valid = 0;
        return;
    }

    // strip off payload length
    unsigned int payload_dec_len = (_q->header[n+1] << 8) | (_q->header[n+2]);
    _q->payload_dec_len = payload_dec_len;

    // strip off modulation scheme/depth
    unsigned int mod_scheme = _q->header[n+3];

    // strip off CRC, forward error-correction schemes
    //  CRC     : most-significant 3 bits of [n+4]
    //  fec0    : least-significant 5 bits of [n+4]
    //  fec1    : least-significant 5 bits of [n+5]
    unsigned int check = (_q->header[n+4] >> 5 ) & 0x07;
    unsigned int fec0  = (_q->header[n+4]      ) & 0x1f;
    unsigned int fec1  = (_q->header[n+5]      ) & 0x1f;

    // validate properties
    if (mod_scheme == 0 || mod_scheme >= LIQUID_MODEM_NUM_SCHEMES) {
        fprintf(stderr,"warning: flexframesync_decode_header(), invalid modulation scheme\n");
        _q->header_valid = 0;
        return;
    }
    if (check >= LIQUID_CRC_NUM_SCHEMES) {
        fprintf(stderr,"warning: flexframesync_decode_header(), decoded CRC exceeds available\n");
        _q->header_valid = 0;
        return;
    }
    if (fec0 >= LIQUID_FEC_NUM_SCHEMES) {
        fprintf(stderr,"warning: flexframesync_decode_header(), decoded FEC (inner) exceeds available\n");
        _q->header_valid = 0;
        return;
    }
    if (fec1 >= LIQUID_FEC_NUM_SCHEMES) {
        fprintf(stderr,"warning: flexframesync_decode_header(), decoded FEC (outer) exceeds available\n");
        _q->header_valid = 0;
        return;
    }

    // configure payload receiver
    if (_q->header_valid) {
        // recreate modem
        _q->ms_payload    = mod_scheme;
        _q->bps_payload   = modulation_types[mod_scheme].bps;
        _q->demod_payload = modem_recreate(_q->demod_payload, _q->ms_payload);

        // set new packetizer properties
        _q->check  = check;
        _q->fec0   = fec0;
        _q->fec1   = fec1;

        // recreate packetizer object
        _q->p_payload = packetizer_recreate(_q->p_payload,
                                            _q->payload_dec_len,
                                            _q->check,
                                            _q->fec0,
                                            _q->fec1);

        // re-compute payload encoded message length
        _q->payload_enc_len = packetizer_get_enc_msg_len(_q->p_payload);

        // re-compute number of modulated payload symbols
        div_t d = div(8*_q->payload_enc_len, _q->bps_payload);
        _q->payload_mod_len = d.quot + (d.rem ? 1 : 0);
        
        // re-allocate buffers accordingly
        // (give encoded a few extra bytes to compensate for repacking)
        _q->payload_mod = (unsigned char*) realloc(_q->payload_mod, (_q->payload_mod_len  )*sizeof(unsigned char));
        _q->payload_enc = (unsigned char*) realloc(_q->payload_enc, (_q->payload_enc_len+8)*sizeof(unsigned char));
        _q->payload_dec = (unsigned char*) realloc(_q->payload_dec, (_q->payload_dec_len  )*sizeof(unsigned char));

        if (_q->payload_mod == NULL || _q->payload_enc == NULL || _q->payload_dec == NULL) {
            fprintf(stderr,"error: flexframesync_decode_header(), could not re-allocate payload arrays\n");
            _q->header_valid = 0;
            return;
        }
    }
    
#if DEBUG_FLEXFRAMESYNC_PRINT
    // print results
    printf("flexframesync_decode_header():\n");
    printf("    header crc      : %s\n", _q->header_valid ? "pass" : "FAIL");
    printf("    check           : %s\n", crc_scheme_str[check][1]);
    printf("    fec (inner)     : %s\n", fec_scheme_str[fec0][1]);
    printf("    fec (outer)     : %s\n", fec_scheme_str[fec1][1]);
    printf("    mod scheme      : %s\n", modulation_types[mod_scheme].name);
    printf("    payload dec len : %u\n", _q->payload_dec_len);
    printf("    payload enc len : %u\n", _q->payload_enc_len);
    printf("    payload mod len : %u\n", _q->payload_mod_len);

    printf("    user data       :");
    for (i=0; i<FLEXFRAME_H_USER; i++)
        printf(" %.2x", _q->header[i]);
    printf("\n");
#endif
}
开发者ID:Clivia,项目名称:liquid-dsp,代码行数:101,代码来源:flexframesync.c


示例10: Paillier

/**************************
//Paillier HE system
//len: length of params p,q
**************************/
void Paillier(int len=512){
  ZZ n, n2, p, q, g, lamda;
  ZZ p1, q1, p1q1;
  ZZ miu;
  
  ZZ m1, m2;
  ZZ BSm, HEm; //baseline and HE result
  ZZ c, c1, c2, cm1, cm2, r;

  //key gen
  start = std::clock();

  GenPrime(p, len);
  GenPrime(q, len);
  mul(n, p, q);
  mul(n2, n, n);

  sub(p1,p,1);
  sub(q1,q,1);
  GCD(lamda,p1,q1);
  mul(p1q1,p1,q1);
  div(lamda, p1q1, lamda);

  RandomBnd(g, n2);

  PowerMod(miu,g,lamda,n2);
  sub(miu, miu, 1);
  div(miu,miu,n); //should add 1?
  InvMod(miu, miu, n);
  
  duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  cout<<"Pailler Setup:"<< duration <<'\n';

  //Enc
  start = std::clock();
  RandomBnd(m1,n);
  RandomBnd(m2,n);

  RandomBnd(r,n); //enc m1
  PowerMod(c1, g,m1,n2);
  PowerMod(c2, r,n,n2);
  MulMod(cm1, c1,c2, n2);

  RandomBnd(r,n); //enc m2
  PowerMod(c1, g,m2,n2);
  PowerMod(c2, r,n,n2);
  MulMod(cm2, c1,c2, n2);

  duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  cout<<"Pailler Enc:"<< duration/2 <<'\n';

  //Evaluation
  start = std::clock();
  c=cm1;
  for(int i=0; i<TIMES; i++)
  	MulMod(c,c,cm2,n2);
  duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  cout<<"Pailler Eval:"<< duration <<'\n';

  //c=cm2;
  //Dec  
  start = std::clock();
  PowerMod(c,c,lamda,n2);
  sub(c,c,1);
  div(c,c,n); //should add 1?
  MulMod(HEm, c, miu, n);  

  duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  cout<<"Pailler Dec:"<< duration <<'\n';

  //baseline
  BSm=m1;
  for(int i=0; i<TIMES; i++)
  	AddMod(BSm,BSm,m2,n);

  assert(BSm==HEm);
}
开发者ID:wanghs09,项目名称:Application-based-on-SEAL,代码行数:81,代码来源:PHE.cpp


示例11: main


//.........这里部分代码省略.........
			{
				interrupt(0x21, 0, "No file entered", 0, 0);
				interrupt(0x21, 0, terminateString, 0, 0);
				continue;
			}
			//read the file to check if the file exists or not
			interrupt(0x21, 3, fileName1, result, 0);
			if(equal("Error!\0", result))
			{
				interrupt(0x21, 0, "File not found", 0, 0);
				interrupt(0x21, 0, terminateString, 0, 0);
			}
			else{
				interrupt(0x21, 7, fileName1, 0, 0);	
			}
		}
		//process the copy command
		else if(equal("copy\0", command))
		{
			//check if the file 1 name is entered
			if(fileName1[0] == '\0')
			{
				interrupt(0x21, 0, "File 1 not entered", 0, 0);
				interrupt(0x21, 0, terminateString, 0, 0);
				continue;
			}
			//check if the file 2 name is entered
			else if(fileName2[0] == '\0')
			{
				interrupt(0x21, 0, "File 2 not entered", 0, 0);
				interrupt(0x21, 0, terminateString, 0, 0);
				continue;
			}
			//read the file
			interrupt(0x21, 3, fileName1, result, 0);
			//check if the file exists
			if(equal("Error!\0", result))
			{
				interrupt(0x21, 0, "File not found", 0, 0);
				interrupt(0x21, 0, terminateString, 0, 0);
			}
			else{
				//count the number of sectors
				for(j = 0; result[j] != '\0'; j++);
				j = div(j+511,512);

				interrupt(0x21, 8, fileName2, result, j);	
			}
		}
		//process the dir command
		else if(equal("dir\0", command))
		{
			interrupt(0x21,9,result,0,0);
			interrupt(0x21, 0, result, 0, 0);
			interrupt(0x21, 0, terminateString, 0, 0);

		}
		//process the create command
		else if(equal("create\0", command))
		{
			//check if the file name is entered
			if(fileName1[0] == '\0')
			{
				interrupt(0x21, 0, "No name entered", 0, 0);
				interrupt(0x21, 0, terminateString, 0, 0);
				continue;
			}
			else
			{
				c=0;
				//read the first line into the buffer
				interrupt(0x21, 1, buffer, 0, 0);
				//terminate the loop if the first character in the line is 0xd (carriage return)
				while(buffer[0] != 0xd )
				{
					//copy the buffer into the result
					for (j = 0; buffer[j] != '\0'; ++j)
					{
						result[c++] = buffer[j];
					}
					//read the new line into the buffer
					interrupt(0x21, 1, buffer, 0, 0);
				}
				
				result[c-2] = '\0';
				interrupt(0x21,8,fileName1,result,1);
			}

		}
		else
		{
			//no valid command is entered
			interrupt(0x21, 0, "Bad command", 0, 0);
			interrupt(0x21, 0, terminateString, 0, 0);
		}



	}
}
开发者ID:AhmadElsagheer,项目名称:operating-system,代码行数:101,代码来源:shell.c


示例12: parse_args

int parse_args(int argc, char **argv, arguments_t *a) {

  int i;
  time_t systime;
  unsigned long long curr_time;
 
#ifndef _MSC_VER
  char *ep;
#endif

  unsigned int tmp_max_sb_len;
  unsigned int tmp_es_len;
  char *tmp_addr;
  unsigned char fec_enc;
  char *tmp_base_dir;
  char *tmp_repair;
  BOOL repair;
  unsigned long long tmp_tsi;
  unsigned long long duration;
  char *loss_ratio2;
  div_t div_max_k;
  div_t div_max_n;
 
  time(&systime);
  curr_time = systime + 2208988800U;
  
  tmp_tsi = DEF_TSI;					 /* transport session identifier */
  tmp_max_sb_len = 0;
  tmp_es_len = 0;
  tmp_addr = NULL;
  fec_enc = DEF_FEC;
  tmp_base_dir = NULL;
  tmp_repair = NULL;
  repair = FALSE;
  loss_ratio2 = NULL;
  duration = 0;

  a->toi = 0;							/* transport object identifier */
  a->cont = FALSE;					 /* continuous transmission */
  a->rx_automatic = FALSE;				 /* download files defined in IDT automatically */
  a->rx_object = FALSE;
  a->file_table_output = FALSE;
  a->log_fd = -1;
  a->complete_fdt = 0;
  a->send_session_close_packets = 1;
  a->name_incomplete_objects = FALSE;

#ifdef _MSC_VER
  a->open_file = FALSE;					 /* open received file automatically */
#endif

  memset(a->sdp_file, 0, MAX_PATH_LENGTH);
  memset(a->file_path, 0, MAX_PATH_LENGTH);  /* file(s) or directory to send */
  memset(a->fdt_file, 0, MAX_PATH_LENGTH);
  strcpy(a->fdt_file, DEF_FDT);				 /* fdt file (fdt based send) */
 
  a->alc_a.cc_id = DEF_CC;				/* congestion control */
  a->alc_a.mode = RECEIVER;				/* sender or receiver? */			
  a->alc_a.port = DEF_MCAST_PORT;				 /* local port number for base channel */
  a->alc_a.nb_channel = DEF_NB_CHANNEL;			 /* number of channels */
  a->alc_a.intface = NULL;					 /* interface */
  a->alc_a.intface_name = NULL;				 /* interface name/index for IPv6 multicast join */
  a->alc_a.addr_family = DEF_ADDR_FAMILY;
  a->alc_a.addr_type = 0;
  a->alc_a.es_len = DEF_SYMB_LENGTH;				 /* encoding symbol length */
  a->alc_a.max_sb_len = DEF_MAX_SB_LEN;			 /* source block length */
  a->alc_a.tx_rate = DEF_TX_RATE;				 /* transmission rate in kbit/s */
  a->alc_a.ttl = DEF_TTL;					 /* time to live  */
  a->alc_a.nb_tx = DEF_TX_NB;					 /* nb of time to send the file/directory */
  a->alc_a.simul_losses = FALSE;				 /* simulate packet losses */
  a->alc_a.loss_ratio1 = P_LOSS_WHEN_OK;
  a->alc_a.loss_ratio2 = P_LOSS_WHEN_LOSS;
  a->alc_a.fec_ratio = DEF_FEC_RATIO;				 /* FEC ratio percent */	
  a->alc_a.fec_enc_id = DEF_FEC_ENC_ID;			 /* FEC Encoding */
  a->alc_a.fec_inst_id = DEF_FEC_INST_ID; 
  a->alc_a.rx_memory_mode = 1;
  a->alc_a.verbosity = 1;  
  a->alc_a.use_fec_oti_ext_hdr = 0;				 /* include fec oti extension header to flute header */
  a->alc_a.encode_content = 0;				 /* encode content */
  a->alc_a.src_addr = NULL;
  a->alc_a.optimize_tx_rate = FALSE;
  a->alc_a.calculate_session_size = FALSE;
  a->alc_a.half_word = FALSE;
  a->alc_a.accept_expired_fdt_inst = FALSE;

#ifdef SSM
  a->alc_a.use_ssm = FALSE;					 /* use source specific multicast */
#endif
  
  if(strstr(argv[0], "repair_sender")) {
    a->alc_a.mode = SENDER;
    repair = TRUE;
  }
  else {
    a->alc_a.mode = RECEIVER;
  }

  for(i = 1; i < argc ; i++) {
    if(argv[i][0] == '-') {
      
//.........这里部分代码省略.........
开发者ID:niteeshbhat,项目名称:ATSC_ROUTE,代码行数:101,代码来源:parse_args.c


示例13: StdlibDiv

void StdlibDiv(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
    ReturnValue->Val->Integer = div(Param[0]->Val->Integer, Param[1]->Val->Integer);
}
开发者ID:cartman300,项目名称:picoc,代码行数:4,代码来源:stdlib.c


示例14: ceil_DIV

/* ceil_DIV(a,b) :=  ceil(a / b)  in _int_ arithmetic : */
static R_INLINE
int ceil_DIV(int a, int b)
{
    div_t div_res = div(a, b);
    return div_res.quot + ((div_res.rem != 0) ? 1 : 0);
}
开发者ID:Patsylou,项目名称:Web-Classification,代码行数:7,代码来源:printarray.c


示例15: _MP_Rem

void __CLRCALL_PURE_OR_CDECL _MP_Rem(_MP_arr u, _Max_type v0)
	{	// divide multi-word value by value, leaving remainder in u
	_Max_type v[2];
	v[0] = v0 & mask;
	v[1] = v0 >> shift;
	const int n = limit(v, 2);
	const int m = limit(u, _MP_len) - n;

	// Knuth, vol. 2, p. 272, Algorithm D
	// D1: [Normalize.]
	_Max_type d = max / (v[n - 1] + 1);
	if (d != 1)
		{	// scale numerator and divisor
		mul(u, _MP_len, d);
		mul(v, n, d);
		}
	// D2: [Initialize j.]
	for (int j = m; 0 <= j; --j)
		{	// D3: [Calculate qh.]
		_Max_type qh = ((u[j + n] << shift) + u[j + n - 1]) / v[n - 1];
		if (qh == 0)
			continue;
		_Max_type rh = ((u[j + n] << shift) + u[j + n - 1]) % v[n - 1];
		for (;;)
			if (qh < max && qh * v[n - 2] <= (rh << shift) + u[j + n - 2])
				break;
			else
				{	// reduce tentative value and retry
				--qh;
				rh += v[n - 1];
				if (max <= rh)
					break;
				}
		// D4: [Multiply and subtract.]
		_Max_type k = 0;
		int i;
		for (i = 0; i < n; ++i)
			{	// multiply and subtract
			u[j + i] -= qh * v[i] + k;
			k = u[j + i] >> shift;
			if (k)
				k = max - k;
			u[j + i] &= mask;
			}
		for (; k != 0 && j + i < _MP_len; ++i)
			{	// propagate borrow
			u[j + i] -= k;
			k = u[j + i] >> shift;
			if (k)
				k = max - k;
			u[j + i] &= mask;
			}
		// D5: [Test remainder.]
		if (k != 0)
			{	// D6: [Add back.]
			--qh;
			add(u + j, n + 1, v, n);
			}
		// D7: [Loop on j.]
		}
	// D8: [Unnormalize.]
	if (d != 1)
		div(u, d);
	}
开发者ID:Chuyu-Team,项目名称:VC-LTL,代码行数:64,代码来源:multprec.cpp


示例16: find_empty_segs

static void
find_empty_segs (PixelRegion  *maskPR,
		 gint          scanline,
		 gint          empty_segs[],
		 gint          max_empty,
		 gint         *num_empty,
		 BoundaryType  type,
		 gint          x1,
		 gint          y1,
		 gint          x2,
		 gint          y2)
{
  uint8_t* data;
  int x;
  int start, end;
  int val, last;
  int endx, l_num_empty;
  div_t d;

  data  = NULL;
  start = 0;
  end   = 0;

  *num_empty = 0;

  if (scanline < 0 || scanline >= maskPR->h)
    {
      empty_segs[(*num_empty)++] = 0;
      empty_segs[(*num_empty)++] = G_MAXINT;
      return;
    }

  if (type == WithinBounds)
    {
      if (scanline < y1 || scanline >= y2)
	{
	  empty_segs[(*num_empty)++] = 0;
	  empty_segs[(*num_empty)++] = G_MAXINT;
	  return;
	}

      start = x1;
      end = x2;
    }
  else if (type == IgnoreBounds)
    {
      start = 0;
      end = maskPR->w;
      if (scanline < y1 || scanline >= y2)
	x2 = -1;
    }

  /*   tilex = -1; */
  empty_segs[(*num_empty)++] = 0;
  last = -1;

  l_num_empty = *num_empty;

  d = div (start, 8);
  data = ((uint8_t*)maskPR->line[scanline])+d.quot;

  for (x = start; x < end;)
    {
      endx = end;
      if (type == IgnoreBounds && (endx > x1 || x < x2))
	{
	  for (; x < endx; x++)
	    {
	      if (*data & (1<<d.rem))
		if (x >= x1 && x < x2)
		  val = -1;
		else
		  val = 1;
	      else
		val = -1;
	      
	      _image_bitmap_next_bit(d, data);

	      if (last != val)
		empty_segs[l_num_empty++] = x;
	      
	      last = val;
	    }
	}
      else
	{
	  for (; x < endx; x++)
	    {
	      if (*data & (1<<d.rem))
		val = 1;
	      else
		val = -1;
	      
	      _image_bitmap_next_bit(d, data);

	      if (last != val)
		empty_segs[l_num_empty++] = x;

	      last = val;
	    }
//.........这里部分代码省略.........
开发者ID:Skiles,项目名称:aseprite,代码行数:101,代码来源:boundary.cpp


示例17: releaseAudioData

// ============================================================================================
void	TestLauncher::run()
{
	bool res = false;
	int bsize = audioDeviceSettings->getBufferSize();
	unsigned int deviceChan = audioDeviceSettings->getOutputChannels();
	int nbuff;
	int remsamples;
	double progressMax;

	releaseAudioData();

	for (int i = 0; i<stimCount; i++)
	{
                if (threadShouldExit())
                    break;
		
			/* Create input stream for the audio file */
			File af(getCurrentTest()->soundFiles[i]);
			wavReader = audioFormatManager.createReaderFor( af );

			dbgOut( L"Loading file " + af.getFullPathName() ); 	

			if (wavReader == NULL)
			{
				lastError = L"Unable to create reader for  " + getCurrentTest()->soundFiles[i];
				return ;
	
			}

			/* get length and number of channels */
			if (wavReader->numChannels > deviceChan)
			{
				lastError = L"The number of audio channels in stimuli files exceeds available device outputs.";
				return ;
			}

			chanCount = wavReader->numChannels;
			samplesCount = static_cast<unsigned int> ( wavReader->lengthInSamples );
			
			/* adjust to the integer number of audio buffers */
			nbuff = div(samplesCount,bsize).quot;
			remsamples = div(samplesCount,bsize).rem;
			
			if (remsamples > 0)
			{
				samplesCount = bsize*(nbuff+1);
				progressMax = stimCount*(nbuff+1);
			}
			else
			{
				progressMax = stimCount*nbuff;
			}
				

			/* create audio data buffers */
			currentData = new int* [chanCount];
			if (currentData == NULL)
			{
				lastError = L"Unable to allocate " + String(2*chanCount*sizeof(float*) + L"b of memory." );
				return ;
			}

			/* create an array of pointers to data buffers */
			for (int ch = 0; ch < chanCount; ch++)
			{
				currentData[ch] = new int[samplesCount];
				if (currentData[ch] == NULL)
				{
					lastError = L"Unable to allocate " + String(samplesCount*sizeof(float*) + L"b of memory." );
					/* clean up (data is massive) */
					for (int k = 0; k<ch; k++)
					{
						delete [] currentData[k];
					}
					delete [] currentData;
					releaseAudioData();
					return ;
				}
				/* clear memory */
				//zeromem(currentData[ch], sizeof(int)*samplesCount);
			}
			/* add array to audioStimData */
			audioStimData.add(currentData);

			/* read file in memory */			
			for (int k=0; k<nbuff; k++)
			{
				res = wavReader->readSamples( currentData, chanCount, bsize*k, bsize*k, bsize);
				if (!res)
				{
					releaseAudioData();
					lastError = L"Unable to read data from file " + getCurrentTest()->soundFiles[i];
					return ;
				}

				/* update progress bar */
				setProgress((i*nbuff + k)/progressMax);
			}
			/* read the last buffer and zero pad */
//.........这里部分代码省略.........
开发者ID:JonBoley,项目名称:MUSHRATest,代码行数:101,代码来源:TestLauncher.cpp


示例18: dom_decomp_2d

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ div64_u64函数代码示例发布时间:2022-05-30
下一篇:
C++ disturb函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap