Ejemplo n.º 1
0
void func(struct Packet pkt) {
  // dodeque method
  pkt.sojourn_time = pkt.deq_tick - pkt.enq_tick;
  if (pkt.sojourn_time < TARGET) {
    first_above_time = 0;
  } else {
    if (first_above_time == 0) {
        first_above_time = pkt.tick + INTERVAL;
    } else if (pkt.tick >= first_above_time) {
        pkt.ok_to_drop = 1;
    }
  }

  // Hysterisis
  if (dropping) {
    if (! pkt.ok_to_drop) {
      dropping = 0;
    }
    if (pkt.tick >= drop_next && dropping) {
      pkt.drop = 1;
      count += 1;
      drop_next = drop_next + INTERVAL / mysqrt(count);
    }
  } else if (pkt.ok_to_drop) {
    pkt.drop = 1;
    dropping = 1;
    if (count > 2 && pkt.tick - drop_next < 8 * INTERVAL) {
      count = count - 2;
    } else {
      count = 1;
      drop_next = pkt.tick + INTERVAL / mysqrt(count);
    }
  }
}
Ejemplo n.º 2
0
main() {
	long long a, b, c; 
	double A, s;
	while(scanf("%lld %lld %lld", &a, &b, &c) == 3) {  
    	if(a == 0 && b==0 && c == 0) break;
    	a *= magnify, b *= magnify, c *= magnify;
    	s = (a + b + c) / 2.0;
		A = mysqrt( s * (s-a) * (s-b) * (s-c) , 10);
		printf("%.2lf\n", mysqrt( (a*a + b*b + c*c)/2.0 + A * 2 * sqrt(3), 10)/ magnify);
	}
	return 0;      
}
Ejemplo n.º 3
0
float mysqrt(float number, float l, float u)
{
  float m, e;
  m = (l + u) / 2;
  e = m * m - number;
  if (e < 0)
    e = -e;
  
  if (e < P)
    return m;
  if (m * m < number)
    mysqrt(number, m, u);
  else
    mysqrt(number, l, m);
}
Ejemplo n.º 4
0
int main(void){

	int i = 12;

//	printf("%d\n", mysqrt(i));

	int normtest[] = {10, 30, 80};
	int normalized[3];
	int crosstest[] = {0, 0, 6};
	int crossed[3];

	//int a[] = {1000, 234, 183};
	//int b[] = {0,0,0};

	//normalize(a, b);
	//printf("\n\n{%d, %d, %d}\n\n", b[0], b[1], b[2]);
	int j;
	for (j=0; j<20; j++) {
		printf("sqrt(%d) = ", j);
		mysqrt(j);
	}

//	printf("Hello!\n\r");
//	normalize(normtest, normalized);
//	printf("%d %d %d\n", normalized[0], normalized[1], normalized[2]);
//	printf("%d\n", dot(normtest, normalized));
//	cross(normtest, crosstest, crossed);
//	printf("%d %d %d\n", crossed[0], crossed[1], crossed[2]);
	return 0;

}
Ejemplo n.º 5
0
int main (int argc, char *argv[])
{
    if (argc < 2)
    {
        fprintf(stdout,"Usage: %s number\n",argv[0]);
        return 1;
    }

    double inputValue = atof(argv[1]);

#ifdef USE_MYMATH
    std::cout << "INFO: using mysqrt()" << std::endl;
    double outputValue = mysqrt(inputValue);
#else
    std::cout << "INFO: using standard sqrt()" << std::endl;
    double outputValue = sqrt(inputValue);
#endif

    unsigned factResult = factorial(0u);

    fprintf(stdout,"The square root of %g is %g\n",
            inputValue, outputValue);

    fprintf(stdout,"The factorial %d is %d\n", 0u, factResult);

    return 0;
}
double mysqrt(double start,double end){

	
	double mid = (start+end)/2;

	if(fabs(mid*mid-N)<=1e-4)
		return mid;

	if(mid*mid > N){
		return mysqrt(start,mid-1);
	}
	else {
		return mysqrt(mid+1,end);
	}

}
Ejemplo n.º 7
0
int main (int argc, char *argv[])
{
	if (argc < 2)
	{
		fprintf(stdout,"%s Version %d.%d\n",argv[0],
				Tutorial_VERSION_MAJOR,
				Tutorial_VERSION_MINOR);
		fprintf(stdout,"Usage: %s number\n",argv[0]);
		return 1;
	}
	double inputValue = atof(argv[1]);
#if defined (HAVE_LOG) && defined (HAVE_EXP)
	fprintf(stdout,"use logexp\n");
	double outputValue = exp(log(inputValue)*0.5);
#else
#ifdef USE_MYMATH
	fprintf(stdout,"use mymath\n");
	double outputValue = mysqrt(inputValue);
#else
	fprintf(stdout,"use cmath\n");
	double outputValue = sqrt(inputValue);
#endif
#endif
	fprintf(stdout,"The square root of %g is %g\n",
			inputValue, outputValue);
	return 0;
}
Ejemplo n.º 8
0
int main()
{
	float n;
	scanf("%f", &n);
	printf("%.5f\n", mysqrt(n));
	return 0;

}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    int val;
    if (2 != argc) return 0;
    val = atoi(argv[1]);
    if (0 >= val) return 0;
    printf("%f\n", mysqrt(val));
    return 0;
}
Ejemplo n.º 10
0
int main() {
    
    // Just a small test - prints out the square root of some integers.
    int i;
    for (i=4; i<100; i+=3)
       printf("%d %lf\n", i, mysqrt(i));
   
    system("PAUSE");
    return 0;   
}
Ejemplo n.º 11
0
void prompt_info(int sig){

#ifdef USE_MYMATH
    double outputValue = mysqrt(inputValue);
#else
    double outputValue = sqrt(inputValue);
#endif // USE_MYMATH
    sprintf(msg, "%f", outputValue);
    write(STDERR_FILENO, msg, strlen(msg));
}
Ejemplo n.º 12
0
int main(void)
{
  int i;
  _Pragma("loopbound min 6 max 6")
  for ( i = 0; i < ( sizeof( v ) / sizeof( float ) ); i++ ) {
    mysqrt(v[i]);
  }

  end_count();
  printstats(cyc_ptr_low_start, cyc_ptr_low_end);

  return 0;
}
Ejemplo n.º 13
0
double higp2(double di, double dj, double tk)
{
	int i,j;
	
	if(tk<0.5)
		return 0.0;
	i=floor(di+0.5);
	j=floor(dj+0.5);
	if(i==0)
		return mysqrt(hipr[j-1]);
	else
		return hipz[j-1][i-1];
}
Ejemplo n.º 14
0
int main()
{
	double inputValue = 2;

	double sumValue = mysum(inputValue, inputValue);
	double sqrtValue = mysqrt(inputValue);

	std::cout << "The sum of " << inputValue << " and " << inputValue << " is " << sumValue << std::endl;
	std::cout << "The square root of " << inputValue << " is " << sqrtValue << std::endl;

	getchar();
	return 0;
}
Ejemplo n.º 15
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_seq_data1_process, ev, data) {

	static uint16_t data_sam[NUM_SAM]; 
	uint16_t sum = 0;
	uint16_t sqsum = 0;
	static struct etimer etimer;

	PROCESS_BEGIN();


	//DEBUG CODE
	printf("cusum-seq: Gathering post-change data... ");


	// Gather NUM_SAM samples over 1 second of time
	SENSORS_ACTIVATE(light_sensor);
	for(counter = 0;counter < NUM_SAM;counter++) {
		// Get data for no change analysis.
		etimer_set(&etimer, CLOCK_SECOND / NUM_SAM);
		PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
		data_sam[counter] = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
	}
	printf("done!\n");
	SENSORS_DEACTIVATE(light_sensor);
	
	sum = 0;
	sqsum = 0;

	// Sum the change data
	for(counter = 0;counter < NUM_SAM;counter++) {
		sum = sum + data_sam[counter];
	}
	printf("cusum-seq: sum = %d\n",sum);
	mean_1 = sum/NUM_SAM;		// 542.3846
	printf("mean_1 = %d\n",mean_1);

	// Caclulate std_dev_1
	for(counter = 0;counter < NUM_SAM;counter++) {
		sqsum = sqsum + mypow2(abs_sub(data_sam[counter], mean_1));
	}
	std_dev_1 = sqsum/NUM_SAM;	// 16.8388
	std_dev_1 = mysqrt(std_dev_1);
	printf("cusum-seq: std_dev_1 = %d\n",std_dev_1);

	// DEBUG CODE
	blink_LEDs(LEDS_ALL);

	PROCESS_END();
}
Ejemplo n.º 16
0
void normalize(int * input,int * output){
	int i;
	int magnitude = 0;

	// Sum the squares of the three input items and take square root.
	for(i = 0; i < 3; i ++){
		magnitude += input[i] * input[i];
	}
	magnitude = mysqrt(magnitude);

	// Scale output by ONE/magnitude.
	for(i = 0; i < 3; i ++){
		output[i] = input[i] * ONE / magnitude;
	}
}
Ejemplo n.º 17
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sample_stats_process, ev, data) {

	static uint16_t data_sam[NUM_SAM]; 
	uint16_t sum = 0;
	uint16_t sqsum = 0;
	static struct etimer etimer;

	PROCESS_BEGIN();

	// Gather NUM_SAM samples over 1 second of time
	sensor_init();
	printf("Gathering data... ");
	for(counter = 0;counter < NUM_SAM;counter++) {
		// Get data for no change analysis.
		etimer_set(&etimer, CLOCK_SECOND / NUM_SAM);
		PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
		data_sam[counter] = sensor_read();
	}
	printf("done!\n");
	sensor_uinit();

	// Sum the no change data
	sum = 0;
	for(counter = 0;counter < NUM_SAM;counter++) {
		sum = sum + data_sam[counter];
	}
	sample_mean = 0;
	printf("sum = %d\n",sum);
	sample_mean = sum/NUM_SAM;
	printf("sample_mean = %d\n",sample_mean);

	// Caclulate sample_std_dev
	sqsum = 0;
	for(counter = 0;counter < NUM_SAM;counter++) {
		sqsum = sqsum + mypow2(abs_sub(data_sam[counter], sample_mean));
	}
	sample_std_dev = 0;
	sample_std_dev = sqsum/NUM_SAM;
	sample_std_dev = mysqrt(sample_std_dev);
	printf("std_dev = %d\n",sample_std_dev);

	PROCESS_END();
}
Ejemplo n.º 18
0
int main (int argc, char *argv[])
{
  if (argc < 2)
  {
	  fprintf(stdout,"%s Version %d.%d\n",
				argv[0],
				Tutorial_VERSION_MAJOR,
				Tutorial_VERSION_MINOR);
    fprintf(stdout,"Usage: %s number\n",argv[0]);
    return 1;
  }
  double inputValue = atof(argv[1]);
  #ifdef USE_MYMATH
	double outputValue = mysqrt(inputValue);
  #else
	double outputValue = sqrt(inputValue);
  #endif
  fprintf(stdout,"The square root of %g is %g\n",
          inputValue, outputValue);
  return 0;
}
Ejemplo n.º 19
0
int main()
{
    unsigned int T;
    unsigned int P, S;
    float side1, side2;
    float side1_square, side2_square;
    float volume1, volume2;
    float discriminant;
    scanf("%u", &T);
    while (T--)
    {
        scanf ("%u %u", &P, &S);
        discriminant = mysqrt(P * P - 24 * S);
        side1 = (P + discriminant) / 12;
        side2 = (P - discriminant) / 12;
        side1_square = side1 * side1;
        side2_square = side2 * side2;
        volume1 = side1_square * side1 - (P / 4) * side1_square + (S / 2) * side1;
        volume2 = side2_square * side2 - (P / 4) * side2_square + (S / 2) * side2;
        printf("%.2f\n", ((volume1 > volume1)? volume1 : volume2));
    }
    return 0;
}
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
   if (argc != 2) {
      std::cerr << "tutorial version " TO_STRING(TUTORIAL_VERSION_MAJOR) "." TO_STRING(TUTORIAL_VERSION_MINOR) "\n"
         "Usage: " << argv[0] << " num" << std::endl;
      return EXIT_FAILURE;
   }
   char *p;
   double num = std::strtod(argv[1], &p);
   if (p[strspn(p, " \t\n")] != '\0' || p == argv[1]) {
      std::cerr << "Error with argument" << std::endl;
      return EXIT_FAILURE;
   }

#ifdef MYSQRT
   num = mysqrt(num);
#else
   num = sqrt(num);
#endif

   std::cout << std::setprecision(std::numeric_limits<double/*decltype(num)*/>::max_digits10) << num << std::endl;
   
   return EXIT_SUCCESS;
}
Ejemplo n.º 21
0
int main()
{
	int i, n, r;
	double s1;
	char s2[15], s3[15]; 

	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);

	scanf("%d\n", &n); 

	clock_t now;
	now = clock();

	for (i = 0; i < n; i++)
	{
		scanf("%lf\n", &s1);
		sqrt(s1);	
	}
	clock_t now2;
	now2 = clock();
	printf("%d s\n", now2 - now);

	now = clock();

	for (i = 0; i < n; i++)
	{
		scanf("%s\n", s2);
		mysqrt(s2, s3); 
	}

	now2 = clock();
	printf("%d s\n", now2 - now);

	return 0;
}
main(){
	scanf("%d",&N);
	printf("%.4lf\n",mysqrt(1,N));
return 0;
}
Ejemplo n.º 23
0
int main(void)
{
	printf("%f\n", mysqrt(1.0, 0.000001));

	return 0;
}
Ejemplo n.º 24
0
int testpixel(int x,int y)
                 {
                    int s;
                    s=mysqrt(abs(x)*abs(x)+abs(y)*abs(y));
                   return s;   
                   }
Ejemplo n.º 25
0
int main(void)
{
  printf("%f\n", mysqrt(3, 1, 2));
  return 0;
}
Ejemplo n.º 26
0
int main() {
    std::cout << mysqrt(25.0) << std::endl;
    std::cout << mysqrt(39.98) << std::endl;
    std::cout << myisqrt(16) << std::endl; 
    std::cout << myisqrt(18) << std::endl;  
}