コード例 #1
0
ファイル: main.c プロジェクト: YavorIT/C-Projects
int main()
{
    int choice, xgr;
    char exit;
    double xrad;
    start:;
    //          MENU
    printf("Which operation do you want? \n \n");

    printf("sin(x)  - 1\n");
    printf("cos(x)  - 2\n");
    printf("tg(x)   - 3\n");
    printf("cotg(x) - 4\n");

    scanf("%d", &choice);
        fflush(stdin);


    if (choice == 1){
            printf ("Input x in degrees:  ");
            scanf("%d", &xgr);
            fflush(stdin);
            xrad = xgr / 180. *M_PI;
        printf("sin(%d) = %.2f", xgr, sinx(xrad));
    }

    if (choice == 2){
             printf ("Input x in degrees:  ");
            scanf("%d", &xgr);
            fflush(stdin);
            xrad = xgr / 180. *M_PI;
        printf("cos(%d) = %.2f", xgr, cos(xrad));
    }

    if (choice == 3){
             printf ("Input x in degrees:  ");
            scanf("%d", &xgr);
            fflush(stdin);
            xrad = xgr / 180. *M_PI;
        printf("tg(%d) = %.2f", xgr, (sinx(xrad)/ cosx(xrad)));
    }

    if (choice == 4){
             printf ("Input x in degrees:  ");
            scanf("%d", &xgr);
            fflush(stdin);
            xrad = xgr / 180. *M_PI;
        printf("cotg(%d) = %.2f", xgr, (cosx(xrad) / sinx(xrad)));
    }
        printf("\nIf you want to continue hit \"A\" if not hit \"Q\" \n");
            scanf("%c", &exit);
        if (exit == 'a' || exit == 'A'){
            goto start;
        }

    return 0;
}
コード例 #2
0
main()
{
	float a,b;
	printf("\nNhap vao so can tinh x : "); scanf("%f",&a);
	printf("\nNhap vao do chinh xac Eps : "); scanf("%f",&b);
	printf("\nDo chinh xac Eps, Sin(%.6f) = %.6f ", a, sinx(a,b));
	printf("\nChinh xac Sin(%f) = %.6f", a, sin(a));
	getch();
}
コード例 #3
0
ファイル: SINX.CPP プロジェクト: pablinme/Proyectos
void calcular(double a[20], double b[20], double c[20], int n)
{

  for(int i = 0; i < n; i++)
  {

   b[i] = (PI*a[i]/180);
   c[i] = sinx(b[i]);

  }
}
コード例 #4
0
ファイル: sinx.c プロジェクト: vrandkode/vrandkode.resources
int main(int argc, char *argv[])
{
  int N, terms;
  float *x, *result;
  int i;
  float sum = 0.0;
  double dtime;

  if (argc > 2){
    N = atoi(argv[1]);
    terms = atoi(argv[2]);
  } else if (argc > 1){
    N = atoi(argv[1]);
    terms = 12;
  } else{
    N = 131072;
    terms = 12;
  }
  printf("Using N=%d and terms=%d\n",N,terms);

  x = (float *) malloc(N*sizeof(float));
  result = (float *) calloc(N,sizeof(float));

  for (i=0; i<N; i++)
    x[i] = 1.0;

  dtime = gettime();

  sinx(N,terms,x,result);

  dtime = gettime() - dtime;

  for (i=0; i<N; i++)
    sum += result[i];

  printf("Sum for result: %12.4f\n",sum);
  printf("Exec time: %9.5f sec.\n",dtime); 
}
コード例 #5
0
ファイル: moon.c プロジェクト: AustenConrad/plan-9
void
moon(void)
{
	Moontab *mp;
	double dlong, lsun, psun;
	double eccm, eccs, chp, cpe;
	double v0, t0, m0, j0;
	double arg1, arg2, arg3, arg4, arg5, arg6, arg7;
	double arg8, arg9, arg10;
	double dgamma, k5, k6;
	double lterms, sterms, cterms, nterms, pterms, spterms;
	double gamma1, gamma2, gamma3, arglat;
	double xmp, ymp, zmp;
	double obl2;

/*
 *	the fundamental elements - all referred to the epoch of
 *	Jan 0.5, 1900 and to the mean equinox of date.
 */

	dlong = 270.434164 + 13.1763965268*eday - .001133*capt2
		 + 2.e-6*capt3;
	argp = 334.329556 + .1114040803*eday - .010325*capt2
		 - 12.e-6*capt3;
	node = 259.183275 - .0529539222*eday + .002078*capt2
		 + 2.e-6*capt3;
	lsun = 279.696678 + .9856473354*eday + .000303*capt2;
	psun = 281.220833 + .0000470684*eday + .000453*capt2
		 + 3.e-6*capt3;

	dlong = fmod(dlong, 360.);
	argp = fmod(argp, 360.);
	node = fmod(node, 360.);
	lsun = fmod(lsun, 360.);
	psun = fmod(psun, 360.);

	eccm = 22639.550;
	eccs = .01675104 - .00004180*capt;
	incl = 18461.400;
	cpe = 124.986;
	chp = 3422.451;

/*
 *	some subsidiary elements - they are all longitudes
 *	and they are referred to the epoch 1/0.5 1900 and
 *	to the fixed mean equinox of 1850.0.
 */

	v0 = 342.069128 + 1.6021304820*eday;
	t0 =  98.998753 + 0.9856091138*eday;
	m0 = 293.049675 + 0.5240329445*eday;
	j0 = 237.352319 + 0.0830912295*eday;

/*
 *	the following are periodic corrections to the
 *	fundamental elements and constants.
 *	arg3 is the "Great Venus Inequality".
 */

	arg1 = 41.1 + 20.2*(capt+.5);
	arg2 = dlong - argp + 33. + 3.*t0 - 10.*v0 - 2.6*(capt+.5);
	arg3 = dlong - argp + 151.1 + 16.*t0 - 18.*v0 - (capt+.5);
	arg4 = node;
	arg5 = node + 276.2 - 2.3*(capt+.5);
	arg6 = 313.9 + 13.*t0 - 8.*v0;
	arg7 = dlong - argp + 112.0 + 29.*t0 - 26.*v0;
	arg8 = dlong + argp - 2.*lsun + 273. + 21.*t0 - 20.*v0;
	arg9 = node + 290.1 - 0.9*(capt+.5);
	arg10 = 115. + 38.5*(capt+.5);
	arg1 *= radian;
	arg2 *= radian;
	arg3 *= radian;
	arg4 *= radian;
	arg5 *= radian;
	arg6 *= radian;
	arg7 *= radian;
	arg8 *= radian;
	arg9 *= radian;
	arg10 *= radian;

	dlong +=
		   (0.84 *sin(arg1)
		 +  0.31 *sin(arg2)
		 + 14.27 *sin(arg3)
		 +  7.261*sin(arg4)
		 +  0.282*sin(arg5)
		 +  0.237*sin(arg6)
		 +  0.108*sin(arg7)
		 +  0.126*sin(arg8))/3600.;

	argp +=
		 (- 2.10 *sin(arg1)
		 -  0.118*sin(arg3)
		 -  2.076*sin(arg4)
		 -  0.840*sin(arg5)
		 -  0.593*sin(arg6))/3600.;

	node +=
		   (0.63*sin(arg1)
		 +  0.17*sin(arg3)
		 + 95.96*sin(arg4)
		 + 15.58*sin(arg5)
		 +  1.86*sin(arg9))/3600.;

	t0 +=
		 (- 6.40*sin(arg1)
		 -  1.89*sin(arg6))/3600.;

	psun +=
		   (6.40*sin(arg1)
		 +  1.89*sin(arg6))/3600.;

	dgamma = -  4.318*cos(arg4)
		 -  0.698*cos(arg5)
		 -  0.083*cos(arg9);

	j0 +=
		   0.33*sin(arg10);

/*
 *	the following factors account for the fact that the
 *	eccentricity, solar eccentricity, inclination and
 *	parallax used by Brown to make up his coefficients
 *	are both wrong and out of date.  Brown did the same
 *	thing in a different way.
 */

	k1 = eccm/22639.500;
	k2 = eccs/.01675104;
	k3 = 1. + 2.708e-6 + .000108008*dgamma;
	k4 = cpe/125.154;
	k5 = chp/3422.700;

/*
 *	the principal arguments that are used to compute
 *	perturbations are the following differences of the
 *	fundamental elements.
 */

	mnom = dlong - argp;
	msun = lsun - psun;
	noded = dlong - node;
	dmoon = dlong - lsun;

/*
 *	solar terms in longitude
 */

	lterms = 0.0;
	mp = moontab;
	for(;;) {
		if(mp->f == 0.0)
			break;
		lterms += sinx(mp->f,
			mp->c[0], mp->c[1],
			mp->c[2], mp->c[3], 0.0);
		mp++;
	}
	mp++;

/*
 *	planetary terms in longitude
 */

	lterms += sinx(0.822, 0,0,0,0, t0-v0);
	lterms += sinx(0.307, 0,0,0,0, 2.*t0-2.*v0+179.8);
	lterms += sinx(0.348, 0,0,0,0, 3.*t0-2.*v0+272.9);
	lterms += sinx(0.176, 0,0,0,0, 4.*t0-3.*v0+271.7);
	lterms += sinx(0.092, 0,0,0,0, 5.*t0-3.*v0+199.);
	lterms += sinx(0.129, 1,0,0,0, -t0+v0+180.);
	lterms += sinx(0.152, 1,0,0,0, t0-v0);
	lterms += sinx(0.127, 1,0,0,0, 3.*t0-3.*v0+180.);
	lterms += sinx(0.099, 0,0,0,2, t0-v0);
	lterms += sinx(0.136, 0,0,0,2, 2.*t0-2.*v0+179.5);
	lterms += sinx(0.083, -1,0,0,2, -4.*t0+4.*v0+180.);
	lterms += sinx(0.662, -1,0,0,2, -3.*t0+3.*v0+180.0);
	lterms += sinx(0.137, -1,0,0,2, -2.*t0+2.*v0);
	lterms += sinx(0.133, -1,0,0,2, t0-v0);
	lterms += sinx(0.157, -1,0,0,2, 2.*t0-2.*v0+179.6);
	lterms += sinx(0.079, -1,0,0,2, -8.*t0+6.*v0+162.6);
	lterms += sinx(0.073, 2,0,0,-2, 3.*t0-3.*v0+180.);
	lterms += sinx(0.643, 0,0,0,0, -t0+j0+178.8);
	lterms += sinx(0.187, 0,0,0,0, -2.*t0+2.*j0+359.6);
	lterms += sinx(0.087, 0,0,0,0, j0+289.9);
	lterms += sinx(0.165, 0,0,0,0, -t0+2.*j0+241.5);
	lterms += sinx(0.144, 1,0,0,0, t0-j0+1.0);
	lterms += sinx(0.158, 1,0,0,0, -t0+j0+179.0);
	lterms += sinx(0.190, 1,0,0,0, -2.*t0+2.*j0+180.0);
	lterms += sinx(0.096, 1,0,0,0, -2.*t0+3.*j0+352.5);
	lterms += sinx(0.070, 0,0,0,2, 2.*t0-2.*j0+180.);
	lterms += sinx(0.167, 0,0,0,2, -t0+j0+178.5);
	lterms += sinx(0.085, 0,0,0,2, -2.*t0+2.*j0+359.2);
	lterms += sinx(1.137, -1,0,0,2, 2.*t0-2.*j0+180.3);
	lterms += sinx(0.211, -1,0,0,2, -t0+j0+178.4);
	lterms += sinx(0.089, -1,0,0,2, -2.*t0+2.*j0+359.2);
	lterms += sinx(0.436, -1,0,0,2, 2.*t0-3.*j0+7.5);
	lterms += sinx(0.240, 2,0,0,-2, -2.*t0+2.*j0+179.9);
	lterms += sinx(0.284, 2,0,0,-2, -2.*t0+3.*j0+172.5);
	lterms += sinx(0.195, 0,0,0,0, -2.*t0+2.*m0+180.2);
	lterms += sinx(0.327, 0,0,0,0, -t0+2.*m0+224.4);
	lterms += sinx(0.093, 0,0,0,0, -2.*t0+4.*m0+244.8);
	lterms += sinx(0.073, 1,0,0,0, -t0+2.*m0+223.3);
	lterms += sinx(0.074, 1,0,0,0, t0-2.*m0+306.3);
	lterms += sinx(0.189, 0,0,0,0, node+180.);

/*
 *	solar terms in latitude
 */

	sterms = 0;
	for(;;) {
		if(mp->f == 0)
			break;
		sterms += sinx(mp->f,
			mp->c[0], mp->c[1],
			mp->c[2], mp->c[3], 0);
		mp++;
	}
	mp++;

	cterms = 0;
	for(;;) {
		if(mp->f == 0)
			break;
		cterms += cosx(mp->f,
			mp->c[0], mp->c[1],
			mp->c[2], mp->c[3], 0);
		mp++;
	}
	mp++;

	nterms = 0;
	for(;;) {
		if(mp->f == 0)
			break;
		nterms += sinx(mp->f,
			mp->c[0], mp->c[1],
			mp->c[2], mp->c[3], 0);
		mp++;
	}
	mp++;

/*
 *	planetary terms in latitude
 */

	pterms =
		   sinx(0.215, 0,0,0,0, dlong);

/*
 *	solar terms in parallax
 */

	spterms = 3422.700;
	for(;;) {
		if(mp->f == 0)
			break;
		spterms += cosx(mp->f,
			mp->c[0], mp->c[1],
			mp->c[2], mp->c[3], 0);
		mp++;
	}

/*
 *	planetary terms in parallax
 */

	spterms = spterms;

/*
 *	computation of longitude
 */

	lambda = (dlong + lterms/3600.)*radian;

/*
 *	computation of latitude
 */

	arglat = (noded + sterms/3600.)*radian;
	gamma1 = 18519.700 * k3;
	gamma2 = -6.241 * k3*k3*k3;
	gamma3 = 0.004 * k3*k3*k3*k3*k3;

	k6 = (gamma1 + cterms) / gamma1;

	beta = k6 * (gamma1*sin(arglat) + gamma2*sin(3.*arglat)
		 + gamma3*sin(5.*arglat) + nterms)
		 + pterms;
	if(flags['o'])
		beta -= 0.6;
	beta *= radsec;

/*
 *	computation of parallax
 */

	spterms = k5 * spterms *radsec;
	hp = spterms + (spterms*spterms*spterms)/6.;

	rad = hp/radsec;
	rp = 1.;
	semi = .0799 + .272453*(hp/radsec);
	if(dmoon < 0.)
		dmoon += 360.;
	mag = dmoon/360.;

/*
 *	change to equatorial coordinates
 */

	lambda += phi;
	obl2 = obliq + eps;
	xmp = rp*cos(lambda)*cos(beta);
	ymp = rp*(sin(lambda)*cos(beta)*cos(obl2) - sin(obl2)*sin(beta));
	zmp = rp*(sin(lambda)*cos(beta)*sin(obl2) + cos(obl2)*sin(beta));

	alpha = atan2(ymp, xmp);
	delta = atan2(zmp, sqrt(xmp*xmp+ymp*ymp));
	meday = eday;
	mhp = hp;

	geo();
}
コード例 #6
0
ファイル: ModXSec.C プロジェクト: cfantasia/CMGWPrimeGroup
void
ModXSec(string inFile, string outFile, bool removeTaus=true, bool applyKFactors=true){
  bool doTC = inFile.find("TC") != string::npos;
  cout<<"doTC is "<<doTC<<endl;

  TTree* tLimit = new TTree("tLimit", "Limits");
  tLimit->ReadFile(inFile.c_str());

  ofstream out(outFile.c_str());

  if(doTC)  out<<"Rho/F:";
  else      out<<"Mass/F:";
  if(doTC){
    out<<"Pi/F:";
    out<<"SinX/F:";
  }
  out<<"Xsec/F:"
     <<"percentError/F"
     <<endl;

  //kfactors
  TGraph* gK = new TGraph(20);
  gK->SetPoint( 0, 200,1.347);
  gK->SetPoint( 1, 300,1.347);
  gK->SetPoint( 2, 500,1.363);
  gK->SetPoint( 3, 700,1.351);
  gK->SetPoint( 4, 900,1.347);
  gK->SetPoint( 5,1100,1.331);
  gK->SetPoint( 6,1300,1.317);
  gK->SetPoint( 7,1500,1.293);
  gK->SetPoint( 8,1700,1.257);
  gK->SetPoint( 9,1900,1.230);
  gK->SetPoint( 10,2000,1.214);

  //Signal pdf uncertainties
  TGraph* gPerErr = new TGraph(20);
  gPerErr->SetPoint(  0, 200,2.192);
  gPerErr->SetPoint(  1, 300,2.192);
  gPerErr->SetPoint(  2, 500,2.632);
  gPerErr->SetPoint(  3, 700,3.070);
  gPerErr->SetPoint(  4, 900,3.448);
  gPerErr->SetPoint(  5,1100,3.771);
  gPerErr->SetPoint(  6,1300,4.101);
  gPerErr->SetPoint(  7,1500,4.339);
  gPerErr->SetPoint(  8,1700,4.581);
  gPerErr->SetPoint(  9,1900,4.846);
  gPerErr->SetPoint( 10,2000,4.981);
  
  if(doTC) tLimit->Draw("Rho:Xsec:Pi:SinX", "SinX > 0.32 && SinX<0.34", "para goff");
  //if(doTC) tLimit->Draw("Rho:Xsec:Pi:SinX", "(280<=Rho && Rho<=300) && (150<=Pi && Pi<=160)", "para goff");
  else     tLimit->Draw("Mass:Xsec",        "", "para goff");
  float n = tLimit->GetSelectedRows(); 
  for(int isample=0; isample<n; ++isample){
    int idx=0;
    Double_t mass = tLimit->GetVal(idx++)[isample];
    Double_t xsec  = tLimit->GetVal(idx++)[isample];

    Double_t pi(-1), sinx(-1);
    if(doTC){
      pi   = tLimit->GetVal(idx++)[isample];
      sinx = tLimit->GetVal(idx++)[isample];
    }

    //cout<<"For rho: "<<rho<<" the kfactor is "<<gK->Eval(rho)<<endl; 
    
    //xsec *= 1e9; //convert from mb to pb
    if(removeTaus) xsec *= 4./9.; //convert from emt to em
    if(applyKFactors) xsec *= gK->Eval(mass);//apply k factor

    Double_t perErr  = gPerErr->Eval(mass);

    out.precision(0) ;
    out.setf ( ios::fixed, ios::floatfield);
    out  <<mass<<"\t";

    if(doTC){
      out.precision(0) ;
      out.setf ( ios::fixed, ios::floatfield);
      out  <<pi<<"\t";

      out.precision(4) ;
      out.setf ( ios::fixed, ios::floatfield);
      out  <<sinx<<"\t";
    }

    out.precision(4) ;
    out.setf ( ios::scientific, ios::floatfield);
    out  <<xsec<<"\t";
    
    out.precision(3);
    out.setf ( ios::fixed, ios::floatfield);
    out<<perErr<<"\t";
    out<<endl;

  }

}
コード例 #7
0
ファイル: sora_ext_lib.c プロジェクト: travisfcollins/Ziria
int16 __ext_sin_int16 ( int16 y ) {
  return (int16) sinx(y);
}
コード例 #8
0
ファイル: sora_ext_lib.cpp プロジェクト: mainland/Ziria
FORCE_INLINE
int16 __ext_sin_int16 ( int16 y ) {
  return (int16) sinx(y);
}
コード例 #9
0
ファイル: TurboTrig.cpp プロジェクト: ibilux/TurboTrig
float Turbo_Trig::cosx(int deg) {
  return sinx(90-deg);
}