예제 #1
0
void WallsUnits::rectToCt(ULength north, ULength east, ULength up, ULength& distance, UAngle& azm, UAngle& inc) const
{
    ULength ne2 = usq(north) + usq(east);
    ULength ne = usqrt(ne2); // horizontal offset
    if (!up.isValid()) up = ULength(0, Length::m());

    distance = usqrt(ne2 + usq(up)).in(d_unit);
    azm = uatan2(east, north).in(a_unit);
    if (azm < UAngle(0, Angle::degrees()))
    {
        azm += UAngle(360.0, Angle::degrees());
    }
    inc = uatan2(up, ne).in(v_unit);
}
예제 #2
0
void WallsUnits::applyHeightCorrections(ULength& dist, UAngle& fsInc, UAngle& bsInc, ULength ih, ULength th) const
{
    if (inch.isNonzero() || ih.isNonzero() || th.isNonzero())
    {
        UAngle inc = avgInc(fsInc + incv, bsInc + incvb);
        if (inc.isValid() && !isVertical(inc))
        {
            // horizontal offset before height correction
            ULength ne = ucos(inc) * (dist + incd);
            // vertical offset before height correction
            ULength u = usin(inc) * (dist + incd);

            u += inch;
            if (ih.isValid()) u += ih;
            if (th.isValid()) u -= th;

            // adjust fsInc/bsInc so that their new avg
            // is the corrected inclination
            UAngle dinc = uatan2(u, ne) - inc;
            fsInc += dinc;
            bsInc += (typevb_corrected ? dinc : -dinc);

            dist = usqrt(usq(ne) + usq(u)) - incd;
        }
    }
}
예제 #3
0
main(void)
{
	int i;
	unsigned long l = 0x3fed0169;
	struct int_sqrt q;

	for (i = 0; i < 101; ++i)
	{
		usqrt(i, &q);
		printf("sqrt(%3d) = %2d, remainder = %2d\n",
			i, q.sqrt, q. frac);
	}
	usqrt(l, &q);
	printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
      return 0;
}
예제 #4
0
int main(void)
{

__asm__ ("set	0x00000003, %o0\n\t"
	 "set	0x00000001, %o1\n\t"
	 "set	0x80000b00, %o2\n\t"
	 "st	%o0, [%o2 + 0x08]\n\t"
	 "st	%o1, [%o2 + 0x04]\n\t");

  double  a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
  double  a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0;
  double  a3 = 1.0, b3 = -3.5, c3 = 22.0, d3 = -31.0;
  double  a4 = 1.0, b4 = -13.7, c4 = 1.0, d4 = -35.0;
  double  x[3];
  double X,fl;
  int     solutions;
  int i,n_eq=0;
  unsigned long l = 0x3fed0169L;
  struct int_sqrt q;
  long n = 0;
  /* solve soem cubic functions */
  printf("********* CUBIC FUNCTIONS ***********\n");
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("1st equation\n");
  for(i=0;i<solutions;i++)
    //printf(" %f",x[i]);  		////OJO
  //printf("\n");          		////OJO
  /* should get 1 solution: 2.5           */
  SolveCubic(a2, b2, c2, d2, &solutions, x);  
  printf("2nd equation\n");
  for(i=0;i<solutions;i++)
    //printf(" %f",x[i]);			////OJO
  //printf("\n");				////OJO
  SolveCubic(a3, b3, c3, d3, &solutions, x);
  printf("3rd equation\n");
  for(i=0;i<solutions;i++)
  //  printf(" %f",x[i]);			////OJO
  //printf("\n");				////OJO
  SolveCubic(a4, b4, c4, d4, &solutions, x);
  printf("4th equation\n");
  for(i=0;i<solutions;i++)
  //  printf(" %f",x[i]); 			////OJO
  //printf("\n");				////OJO
  /* Now solve some random equations */
printf("Solving many random equations\n");   		////OJO
  for(a1=1;a1<10;a1++) {
    for(b1=10;b1>0;b1--) {
      for(c1=5;c1<15;c1+=0.5) {
	for(d1=-1;d1>-11;d1--) {
	  SolveCubic(a1, b1, c1, d1, &solutions, x);  
	  n_eq = n_eq++;
	  //printf("Solutions: 5 (random)");    ////OJO
	  //for(i=0;i<solutions;i++)		////OJO
	    //printf(" %f",x[i]);		////OJO
	  //printf("\n");			////OJO
	}
      }
    }
  }
printf("Solved %d random cubic equations\n",n_eq);
  
  printf("******** 1000 INTEGER SQR ROOTS *********\n");
  /* perform some integer square roots */
  for (i = 0; i < 1001; ++i)
    {
      usqrt(i, &q);
			// remainder differs on some machines
     // printf("sqrt(%3d) = %2d, remainder = %2d\n",
     //printf("sqrt(%3d) = %2d\n",			////OJO
     //	     i, q.sqrt);				////OJO
    }
  usqrt(l, &q);
  //printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
  //printf("\nsqrt(%lX) = %X\n", l, q.sqrt);		////OJO


  printf("** ANGLE CONVERSION DEG to RAD from 0 to 360 **\n");
  /* convert some rads to degrees */
  for (X = 0.0; X <= 360.0; X += 1.0)
   fl= deg2rad(X);          /////OJO
    //printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));    /////OJO
  puts("");
 printf("** ANGLE CONVERSION RAD to DEG from 0.0 to 2PI sampling 1e-6 **\n");
  for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180))
   fl=rad2deg(X);   ////OJO
    //printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
  
  printf("Program exits successfully\n");

__asm__ ("set	0x00000000, %o1\n\t"
	 "set	0x80000b00, %o2\n\t"
	 "st	%o1, [%o2 + 0x04]\n\t");

  return 0;
}
예제 #5
0
파일: forprime.c 프로젝트: jpflori/pari
static void
initprimes0(ulong maxnum, long *lenp, ulong *lastp, byteptr p1)
{
  pari_sp av = avma, bot = pari_mainstack->bot;
  long alloced, psize;
  byteptr q, end, p, end1, plast, curdiff;
  ulong last, remains, curlow, rootnum, asize;
  ulong prime_above;
  byteptr p_prime_above;

  maxnum |= 1; /* make it odd. */
  /* base case */
  if (maxnum < 1ul<<17) { initprimes1(maxnum>>1, lenp, lastp, p1); return; }

  /* Checked to be enough up to 40e6, attained at 155893 */
  rootnum = usqrt(maxnum) | 1;
  initprimes1(rootnum>>1, &psize, &last, p1);
  end1 = p1 + psize - 1;
  remains = (maxnum - last) >> 1; /* number of odd numbers to check */

  /* we access primes array of psize too; but we access it consecutively,
   * thus we do not include it in fixed_to_cache */
  asize = good_arena_size((ulong)(rootnum * slow2_in_roots), remains+1, 0,
                          &cache_model) - 1;
  /* enough room on the stack ? */
  alloced = (((byteptr)avma) <= ((byteptr)bot) + asize);
  if (alloced)
    p = (byteptr)pari_malloc(asize+1);
  else
    p = (byteptr)stack_malloc(asize+1);
  end = p + asize; /* the 0 sentinel goes at end. */
int startup(void)
{
  double  a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
  double  a2 = 1.0, b2 = -4.5, c2 = 17.0, d2 = -30.0;
  double  a3 = 1.0, b3 = -3.5, c3 = 22.0, d3 = -31.0;
  double  a4 = 1.0, b4 = -13.7, c4 = 1.0, d4 = -35.0;
  double  x[3];
  double X;
  int     solutions;
  int i;
  unsigned long l = 0x3fed0169L;
  struct int_sqrt q;
  long n = 0;

  /* solve soem cubic functions */
  printf("********* CUBIC FUNCTIONS ***********\n");
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");
  /* should get 1 solution: 2.5           */
  SolveCubic(a2, b2, c2, d2, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");
  SolveCubic(a3, b3, c3, d3, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");
  SolveCubic(a4, b4, c4, d4, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");
  /* Now solve some random equations */
  for(a1=1;a1<10;a1++) {
    for(b1=10;b1>0;b1--) {
      for(c1=5;c1<15;c1+=0.5) {
	for(d1=-1;d1>-11;d1--) {
	  SolveCubic(a1, b1, c1, d1, &solutions, x);  
	  printf("Solutions:");
	  for(i=0;i<solutions;i++)
	    printf(" %f",x[i]);
	  printf("\n");
	}
      }
    }
  }
  
  printf("********* INTEGER SQR ROOTS ***********\n");
  /* perform some integer square roots */
  for (i = 0; i < 1001; ++i)
    {
      usqrt(i, &q);
			// remainder differs on some machines
     // printf("sqrt(%3d) = %2d, remainder = %2d\n",
     printf("sqrt(%3d) = %2d\n",
	     i, q.sqrt);
    }
  usqrt(l, &q);
  //printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
  printf("\nsqrt(%lX) = %X\n", l, q.sqrt);


  printf("********* ANGLE CONVERSION ***********\n");
  /* convert some rads to degrees */
  for (X = 0.0; X <= 360.0; X += 1.0)
    printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
  puts("");
  for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180))
    printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
  
  
  return 0;
}
예제 #7
0
int main(void)
{
  double  a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
  double  x[3];
  double X;
  int     solutions;
  int i;
  unsigned long l = 0x3fed0169L;
  struct int_sqrt q;
  long n = 0;

  /* solve soem cubic functions */
  printf("********* CUBIC FUNCTIONS ***********\n");
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 1.0; b1 = -4.5; c1 = 17.0; d1 = -30.0;
  /* should get 1 solution: 2.5           */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 1.0; b1 = -3.5; c1 = 22.0; d1 = -31.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 1.0; b1 = -13.7; c1 = 1.0; d1 = -35.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 3.0; b1 = 12.34; c1 = 5.0; d1 = 12.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = -8.0; b1 = -67.89; c1 = 6.0; d1 = -23.6;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 45.0; b1 = 8.67; c1 = 7.5; d1 = 34.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = -12.0; b1 = -1.7; c1 = 5.3; d1 = 16.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  /* Now solve some random equations */
  for(a1=1;a1<10;a1+=1) {
    for(b1=10;b1>0;b1-=.25) {
      for(c1=5;c1<15;c1+=0.61) {
	   for(d1=-1;d1>-5;d1-=.451) {
		SolveCubic(a1, b1, c1, d1, &solutions, x);  
		printf("Solutions:");
		for(i=0;i<solutions;i++)
		  printf(" %f",x[i]);
		printf("\n");
	   }
      }
    }
  }


  printf("********* INTEGER SQR ROOTS ***********\n");
  /* perform some integer square roots */
  for (i = 0; i < 100000; i+=2)
    {
      usqrt(i, &q);
			// remainder differs on some machines
     // printf("sqrt(%3d) = %2d, remainder = %2d\n",
     printf("sqrt(%3d) = %2d\n",
	     i, q.sqrt);
    }
  printf("\n");
  for (l = 0x3fed0169L; l < 0x3fed4169L; l++)
    {
	 usqrt(l, &q);
	 //printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
	 printf("sqrt(%lX) = %X\n", l, q.sqrt);
    }


  printf("********* ANGLE CONVERSION ***********\n");
  /* convert some rads to degrees */
/*   for (X = 0.0; X <= 360.0; X += 1.0) */
  for (X = 0.0; X <= 360.0; X += .001)
    printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
  puts("");
/*   for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180)) */
  for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 5760))
    printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
  
  
  return 0;
}
예제 #8
0
int main(void)
{
  double  a1 = 1.0f, b1 = -10.5f, c1 = 32.0f, d1 = -30.0f;
  double  a2 = 1.0f, b2 = -4.5f, c2 = 17.0f, d2 = -30.0f;
  double  a3 = 1.0f, b3 = -3.5f, c3 = 22.0f, d3 = -31.0f;
  double  a4 = 1.0f, b4 = -13.7f, c4 = 1.0f, d4 = -35.0f;
  double  x[3];
  double X;
  int     solutions;
  int i;
  unsigned long l = 0x3fed0169L;
  struct int_sqrt q;
  long n = 0;

  /* solve soem cubic functions */
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);

  SolveCubic(a2, b2, c2, d2, &solutions, x);

  SolveCubic(a3, b3, c3, d3, &solutions, x);

  SolveCubic(a4, b4, c4, d4, &solutions, x);

  /* Now solve some random equations */
  _Pragma( "loopbound min 5 max 5" )
  for(a1=1;a1<10;a1+=2) {
    _Pragma( "loopbound min 5 max 5" )
    for(b1=10;b1>0;b1-=2) {
      _Pragma( "loopbound min 7 max 7" )
      for(c1=5;c1<15;c1+=1.5f) {
        _Pragma( "loopbound min 5 max 5" )
        for(d1=-1;d1>-11;d1-=2) {
          SolveCubic(a1, b1, c1, d1, &solutions, x);
        }
      }
    }
  }

  /* perform some integer square roots */
  _Pragma( "loopbound min 1000 max 1000" )
  for (i = 1; i < 1001; i+=1) {
    usqrt(i, &q);
    // remainder differs on some machines
  }

  usqrt(l, &q);

  /* convert some rads to degrees */
  _Pragma( "loopbound min 361 max 361" )
  for (X = 0.0f; X <= 360.0f; X += 1.0f) {
    deg2rad(X);
  }

  _Pragma( "loopbound min 360 max 360" )
  for (X = 0.0f; X <= (2 * PI + 1e-6f); X += (PI / 180)) {
    rad2deg(X);
  }

  return 0;
}
예제 #9
0
int main(void)
{
  double  a1 = 1.0;
__boundcheck_metadata_store((void *)(&a1),(void *)((size_t)(&a1)+sizeof(a1)*8-1));
double  b1 = -10.5;
__boundcheck_metadata_store((void *)(&b1),(void *)((size_t)(&b1)+sizeof(b1)*8-1));
double  c1 = 32.0;
__boundcheck_metadata_store((void *)(&c1),(void *)((size_t)(&c1)+sizeof(c1)*8-1));
double  d1 = -30.0;
__boundcheck_metadata_store((void *)(&d1),(void *)((size_t)(&d1)+sizeof(d1)*8-1));

  double  x[3];__boundcheck_metadata_store(&x[0],&x[3-1]);

  double X;
__boundcheck_metadata_store((void *)(&X),(void *)((size_t)(&X)+sizeof(X)*8-1));

  int     solutions;
__boundcheck_metadata_store((void *)(&solutions),(void *)((size_t)(&solutions)+sizeof(solutions)*8-1));

  int i;
__boundcheck_metadata_store((void *)(&i),(void *)((size_t)(&i)+sizeof(i)*8-1));

  unsigned long l = 0x3fed0169L;
__boundcheck_metadata_store((void *)(&l),(void *)((size_t)(&l)+sizeof(l)*8-1));

  struct int_sqrt q;
__boundcheck_metadata_store((void *)(&q),(void *)((size_t)(&q)+sizeof(q)*8-1));

  long n = 0;
__boundcheck_metadata_store((void *)(&n),(void *)((size_t)(&n)+sizeof(n)*8-1));


  /* solve soem cubic functions */
  printf("********* CUBIC FUNCTIONS ***********\n");
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,23,18,"main",i)]);
  printf("\n");

  a1 = 1.0; b1 = -4.5; c1 = 17.0; d1 = -30.0;
  /* should get 1 solution: 2.5           */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,31,18,"main",i)]);
  printf("\n");

  a1 = 1.0; b1 = -3.5; c1 = 22.0; d1 = -31.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,38,18,"main",i)]);
  printf("\n");

  a1 = 1.0; b1 = -13.7; c1 = 1.0; d1 = -35.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,45,18,"main",i)]);
  printf("\n");

  a1 = 3.0; b1 = 12.34; c1 = 5.0; d1 = 12.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,52,18,"main",i)]);
  printf("\n");

  a1 = -8.0; b1 = -67.89; c1 = 6.0; d1 = -23.6;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,59,18,"main",i)]);
  printf("\n");

  a1 = 45.0; b1 = 8.67; c1 = 7.5; d1 = 34.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,66,18,"main",i)]);
  printf("\n");

  a1 = -12.0; b1 = -1.7; c1 = 5.3; d1 = 16.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[_RV_insert_check(0,3,73,18,"main",i)]);
  printf("\n");

  /* Now solve some random equations */
  for(a1=1;a1<10;a1+=1) {
    for(b1=10;b1>0;b1-=.25) {
      for(c1=5;c1<15;c1+=0.61) {
	   for(d1=-1;d1>-5;d1-=.451) {
		SolveCubic(a1, b1, c1, d1, &solutions, x);  
		printf("Solutions:");
		for(i=0;i<solutions;i++)
		  printf(" %f",x[_RV_insert_check(0,3,84,18,"main",i)]);
		printf("\n");
	   }
      }
    }
  }


  printf("********* INTEGER SQR ROOTS ***********\n");
  /* perform some integer square roots */
  for (i = 0; i < 100000; i+=2)
    {
      usqrt(i, &q);
			// remainder differs on some machines
     // printf("sqrt(%3d) = %2d, remainder = %2d\n",
     printf("sqrt(%3d) = %2d\n",
	     i, q.sqrt);
    }
  printf("\n");
  for (l = 0x3fed0169L; l < 0x3fed4169L; l++)
    {
	 usqrt(l, &q);
	 //printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
	 printf("sqrt(%lX) = %X\n", l, q.sqrt);
    }


  printf("********* ANGLE CONVERSION ***********\n");
  /* convert some rads to degrees */
/*   for (X = 0.0; X <= 360.0; X += 1.0) */
  for (X = 0.0; X <= 360.0; X += .001)
    printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
  puts("");
/*   for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180)) */
  for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 5760))
    printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
  
  
  return 0;
}