long double tt_to_tdbl(long double tt)
{
    long double d = (tt - MJD2000) / JULIAN_C;
    long double g = GRAD_IN_RAD * (357.258 + 35999.050 * d);
    return tt + ((0.00168 * sinl(g + 0.0167*sinl(g))) / 86400.0);

//    long double mjd = utc_to_mjdl(2003, 3, 7, 2, 45, 0.0);
//    long double t = (mjd + 2400000.5 - 2451545.0) / 36525.0;
//    long double dtr = M_PI / 180;
//    long double corr;
//    corr = 1656.675     * sin(dtr * (35999.3729 * t + 357.5287))
//           + 22.418     * sin(dtr * (32964.467  * t + 246.199))
//           + 13.84      * sin(dtr * (71998.746  * t + 355.057))
//           +  4.77      * sin(dtr * ( 3034.906  * t +  25.463))
//           +  4.677     * sin(dtr * (34777.259  * t + 230.394))
//           + 10.216 * t * sin(dtr * (35999.373  * t + 243.451))
//           +  0.171 * t * sin(dtr * (71998.746  * t + 240.98 ))
//           +  0.027 * t * sin(dtr * ( 1222.114  * t + 194.661))
//           +  0.027 * t * sin(dtr * ( 3034.906  * t + 336.061))
//           +  0.026 * t * sin(dtr * (  -20.186  * t +   9.382))
//           +  0.007 * t * sin(dtr * (29929.562  * t + 264.911))
//           +  0.006 * t * sin(dtr * (  150.678  * t +  59.775))
//           +  0.005 * t * sin(dtr * ( 9037.513  * t + 256.025))
//           +  0.043 * t * sin(dtr * (35999.373  * t + 151.121));
//
//    return tt + (0.000001 * corr / 86400.0);
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    bouncyPhysics(false),
    simulationPaused(false),
    gravityPhysics(true),
    simulationBorder(false),
    deltaT(TIMER_INTERVAL*3)
{
    ui->setupUi(this);
    ui_bouncyToggle = findChild<QPushButton*>("bouncyToggle");
    ui_pauseToggle = findChild<QPushButton*>("pauseToggle");
    ui_gravityToggle = findChild<QPushButton*>("gravityToggle");
    ui_borderToggle = findChild<QPushButton*>("borderToggle");
    this->updateButtons();
    // set black background
    QPalette Pal(palette());
    Pal.setColor(QPalette::Background, Qt::black);
    this->setAutoFillBackground(true);
    this->setPalette(Pal);
    timerID = startTimer(TIMER_INTERVAL);

    //testing
    long double alfa = 0;
    long double v = 70;
    long double promien = 200;
    long double srodekX = 640;
    long double srodekY = 360;
    int NUMBER_OF_ORBS = 20;
    celestialBody cb;
    for (int i = 1; i <= NUMBER_OF_ORBS; i++)
    {

        cb.makePlanet(srodekX+cosl(alfa)*promien,srodekY+sinl(alfa)*promien);
        cb.setVelocity(sinl(alfa)*v,-cosl(alfa)*v);
        cbodies.push_back(cb);
        alfa+=2*M_PI/NUMBER_OF_ORBS;
    }
    alfa = 0;
    v = -30;
    promien = 100;
    srodekX = 640;
    srodekY = 360;
    NUMBER_OF_ORBS = 10;
    for (int i = 1; i <= NUMBER_OF_ORBS; i++)
    {
        cb.makePlanet(srodekX+cosl(alfa)*promien,srodekY+sinl(alfa)*promien);
        cb.setVelocity(sinl(alfa)*v,-cosl(alfa)*v);
        cb.setBrushColor(QColor(Qt::red));
        cb.setPenColor(QColor(200,100,100));
        cbodies.push_back(cb);
        alfa+=2*M_PI/NUMBER_OF_ORBS;
    }
}
Beispiel #3
0
compl compl_resta(const compl a, const compl b){
    compl z;

    real x, y, k, w ;
    x = a.mod * cosl(a.ang);
    y = a.mod * sinl(a.ang);
    w = b.mod * cosl(b.ang);
    k = b.mod * sinl(b.ang);

    z = compl_create((x - w),(y - k));
    return z;

}
Beispiel #4
0
long double complex CLANG_PORT_DECL(cpowl) (long double complex X, long double complex Y)
{
  long double complex Res;
  long double i;
  long double r = hypotl (__real__ X, __imag__ X);
  if (r == 0.0L)
    {
       __real__ Res = __imag__ Res = 0.0L;
    }
  else
    {
      long double rho;
      long double theta;
      i = cargl (X);
      theta = i * __real__ Y;
 
      if (__imag__ Y == 0.0L)
	/* This gives slightly more accurate results in these cases. */
   	rho = powl (r, __real__ Y);
      else
	{
          r = logl (r);
	  /* rearrangement of cexp(X * clog(Y)) */
	  theta += r * __imag__ Y;
	  rho = expl (r * __real__ Y - i * __imag__ Y);
	}

      __real__ Res = rho * cosl (theta);
      __imag__ Res = rho * sinl (theta);
    }
  return  Res;
}
Beispiel #5
0
long double asinl(long double x)
{
  long double y, y_sin, y_cos;

  y = 0;

  while (1)
    {
      y_sin = sinl(y);
      y_cos = cosl(y);

      if (y > M_PI_2 || y < -M_PI_2)
        {
          y = fmodl(y, M_PI);
        }

      if (y_sin + LDBL_EPSILON >= x && y_sin - LDBL_EPSILON <= x)
        {
          break;
        }

      y = y - (y_sin - x) / y_cos;
    }

  return y;
}
Beispiel #6
0
int main(void)
{
	#pragma STDC FENV_ACCESS ON
	long double y;
	float d;
	int e, i, err = 0;
	struct l_l *p;

	for (i = 0; i < sizeof t/sizeof *t; i++) {
		p = t + i;

		if (p->r < 0)
			continue;
		fesetround(p->r);
		feclearexcept(FE_ALL_EXCEPT);
		y = sinl(p->x);
		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);

		if (!checkexcept(e, p->e, p->r)) {
			printf("%s:%d: bad fp exception: %s sinl(%La)=%La, want %s",
				p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e));
			printf(" got %s\n", estr(e));
			err++;
		}
		d = ulperrl(y, p->y, p->dy);
		if (!checkulp(d, p->r)) {
			printf("%s:%d: %s sinl(%La) want %La got %La ulperr %.3f = %a + %a\n",
				p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy);
			err++;
		}
	}
	return !!err;
}
Beispiel #7
0
    D_TYPE _CALLTYPE1 _j0( D_TYPE x )
#endif
{
D_TYPE	z, P0, Q0;

    /* if the argument is negative, take the absolute value */

    if ( x < 0.0 )
	x = - x;

    /* if x <= 7.5  use Hart JZERO 5847 */

    if ( x <= 7.5 )
	return( evaluate( x*x, J0p, 11, J0q, 4) );

    /* else if x >= 7.5  use Hart PZERO 6548 and QZERO 6948, the high range
       approximation */

    else {
	z = 8.0/x;
	P0 = evaluate( z*z, P0p, 5, P0q, 5);
	Q0 = z*evaluate( z*z, Q0p, 5, Q0q, 5);
	return( sqrtl(2.0/(PI*x))*(P0*cosl(x-PI/4) - Q0*sinl(x-PI/4)) );
	}
}
Beispiel #8
0
long double complex CLANG_PORT_DECL(ccosl) (long double complex Z)
{
  long double complex Res;
  __real__ Res = cosl (__real__ Z) * coshl ( __imag__ Z);
  __imag__ Res = -sinl (__real__ Z) * sinhl ( __imag__ Z);
  return Res;
}
Beispiel #9
0
long double complex ccosl (long double complex Z)
{
  long double complex Res;
  __real__ Res = cosl (__real__ Z) * coshl ( __imag__ Z);
  __imag__ Res = -sinl (__real__ Z) * sinhl ( __imag__ Z);
  return Res;
}
Beispiel #10
0
void
cm_float_sin(unsigned argc, obj_t args)
{
  obj_t recvr = CAR(args);

  m_float_new(consts.cl._float, sinl(FLOAT(recvr)->val));
}
Beispiel #11
0
void Game::addAsteroide(){
	Asteroide* asteroide;
	long double x, y, angle;	

	int MAX_VERT = 5 + (rand() % (int)(20 - 5 + 1));
    int diametro = 1 + (rand() % (int)(100 - 1 + 1));

    asteroide = new Asteroide(MAX_VERT);

    int POSICION_X = rand()%800;
	int POSICION_Y = rand()%600;

	

	asteroide -> setDiametro(diametro);
	asteroide -> setTipoDireccion(rand()%7);
	asteroide -> setVelocidad(200 / diametro);

	for( int w = 0; w < asteroide -> getNumeroVertices(); w++)
    {
        angle = 360.0/asteroide -> getNumeroVertices();
        int variacion  = int(0.3 * ( asteroide -> getDiametro() + 1) );
        x = cosl(w * angle*PI/180.0) * (asteroide -> getDiametro()) + POSICION_X + rand()%variacion;
        y = sinl(w * angle*PI/180.0) * (asteroide -> getDiametro()) + POSICION_Y + rand()%variacion;
			        
        asteroide -> addVertice(Vector2D(x, y), w);
		if (w == 0)
			asteroide -> addVertice(Vector2D(x, y), asteroide -> getNumeroVertices());
    }
    asteroides.emplace_back(*asteroide);
}
Beispiel #12
0
void
Coseno (Token ** Pila)
{
  Token *Operando = EntornoEjecucion_BuscaSimbolo (*Pila);
  if (Buzon.GetHuboError ())
    return;
  if (NoEsReal (Operando))
    {
      BorrarTokenSiEsVariable (Operando);
      return;
    }
  long double ValorRetorno;
  long double ValorDominio = Operando->GetDatoReal ();
  BorrarTokenSiEsVariable (Operando);
  ValorDominio = Estado.AngulosEnGrados ? ValorDominio * (M_PI / 180.0L) :
    ValorDominio;
  if (fabsl (sinl (ValorDominio)) == 1.0L)
    ValorRetorno = 0.0L;
  else
    ValorRetorno = cosl (ValorDominio);
  if (Buzon.GetHuboError ())
    return;
  Token *TokenRetorno = ConsigueToken (ValorRetorno);
  if (Buzon.GetHuboError ())
    return;
  delete Desapila (Pila);
  Apila (Pila, TokenRetorno);
  if (FueraDeRango (TokenRetorno))
    return;
  return;
}
Beispiel #13
0
    D_TYPE _CALLTYPE1 _y1( D_TYPE x )
#endif
{
D_TYPE	z, P1, Q1;


    /* if the argument is negative, set EDOM error, print an error message,
     * and return -HUGE
     */

    if (x < 0.0)
	return( domain_err(OP_Y1, x, LD_IND) );

    /* if x <= 7.5  use Hart YONE 6444, the low range approximation */

    if ( x <= 7.5 )
	return( x*evaluate( x*x, Y1p, 7, Y1q, 8)
			       + (2.0/PI)*(_j1l(x)*logl(x) - 1.0/x) );


    /* else if x > 7.5	use Hart PONE 6749 and QONE 7149, the high range
       approximation */

    else {
	z = 8.0/x;
	P1 = evaluate( z*z, P1p, 5, P1q, 5);
	Q1 = z*evaluate( z*z, Q1p, 5, Q1q, 5);
	return(  sqrtl(2.0/(PI*x))*
			 ( P1*sinl(x-3.0*PI/4.0) + Q1*cosl(x-3.0*PI/4.0) )   );
	}
}
Beispiel #14
0
Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments)
{
    assert(arguments && arguments->dim);
    Expression *arg0 = (Expression *)arguments->data[0];
    Expression *e = NULL;
    switch (builtin)
    {
	case BUILTINsin:
	    if (arg0->op == TOKfloat64)
		e = new RealExp(0, sinl(arg0->toReal()), Type::tfloat80);
	    break;

	case BUILTINcos:
	    if (arg0->op == TOKfloat64)
		e = new RealExp(0, cosl(arg0->toReal()), Type::tfloat80);
	    break;

	case BUILTINtan:
	    if (arg0->op == TOKfloat64)
		e = new RealExp(0, tanl(arg0->toReal()), Type::tfloat80);
	    break;

	case BUILTINsqrt:
	    if (arg0->op == TOKfloat64)
		e = new RealExp(0, sqrtl(arg0->toReal()), Type::tfloat80);
	    break;

	case BUILTINfabs:
	    if (arg0->op == TOKfloat64)
		e = new RealExp(0, fabsl(arg0->toReal()), Type::tfloat80);
	    break;
    }
    return e;
}
Beispiel #15
0
    D_TYPE _CALLTYPE1 _y0( D_TYPE x )
#endif
{
D_TYPE	z, P0, Q0;


    /* if the argument is negative, set EDOM error, print an error message,
     * and return -HUGE
     */

    if (x < 0.0)
	return( domain_err(OP_Y0 , x, LD_IND) );


    /* if x <= 7.5 use Hart YZERO 6245, the low range approximation */

    if ( x <= 7.5 )
	return( evaluate( x*x, Y0p, 8, Y0q, 8) + (2.0/PI)*_j0l(x)*logl(x) );


    /* else if x > 7.5 use Hart PZERO 6548 and QZERO 6948, the high range
       approximation */

    else {
	z = 8.0/x;
	P0 = evaluate( z*z, P0p, 5, P0q, 5);
	Q0 = z*evaluate( z*z, Q0p, 5, Q0q, 5);
	return( sqrtl(2.0/(PI*x))*(P0*sinl(x-PI/4) + Q0*cosl(x-PI/4)) );
	}
}
Beispiel #16
0
    D_TYPE _CALLTYPE1 _j1( D_TYPE x )
#endif
{
D_TYPE	z, P1, Q1;
int	sign;

     /* if the argument is negative, take the absolute value and set sign */

     sign = 1;
     if( x < 0.0 ){
	x = -x;
	sign = -1;
	}

     /* if x <= 7.5  use Hart JONE 6047 */

     if ( x <= 7.5 )
	return( sign*x*evaluate( x*x, J1p, 10, J1q, 4) );


    /* else if x > 7.5	use Hart PONE 6749 and QONE 7149, the high range
       approximation */

    else {
	z = 8.0/x;
	P1 = evaluate( z*z, P1p, 5, P1q, 5);
	Q1 = z*evaluate( z*z, Q1p, 5, Q1q, 5);
	return( sign*sqrtl(2.0/(PI*x))*
			   ( P1*cosl(x-3.0*PI/4.0) - Q1*sinl(x-3.0*PI/4.0) )  );
	}
}
Beispiel #17
0
void test_sin()
{
    static_assert((std::is_same<decltype(sin((double)0)), double>::value), "");
    static_assert((std::is_same<decltype(sinf(0)), float>::value), "");
    static_assert((std::is_same<decltype(sinl(0)), long double>::value), "");
    assert(sin(0) == 0);
}
Beispiel #18
0
long double complex cexpl (long double complex Z)
{
  long double complex  Res;
  long double rho = expl (__real__ Z);
  __real__ Res = rho * cosl(__imag__ Z);
  __imag__ Res = rho * sinl(__imag__ Z);
  return Res;
}
Beispiel #19
0
void testFunc(long double *x, long double *y, 
        int nx, int ny, long double *z, void *info)
{
    int ix, iy;
    for (iy=0; iy < ny; iy++)
        for (ix=0; ix < nx; ix++)
            *(z++) =  0.5*x[ix] + 0.1*sinl(x[ix]) + 0.7*y[iy]+0.1*y[iy]*y[iy];
}
Beispiel #20
0
void compl_print(const compl c){
    /* DESC: Imprime en pantalla c con formato a + i b. */
    real x,y;
    x = c.mod * cosl(c.ang); 
    y = c.mod * sinl(c.ang);

    printf("el numero complejo es : \t %Lf + i * %Lf \n",x ,y);
}
Beispiel #21
0
/* Equ 20.2, 20.4 pg 126 */
void ln_get_equ_prec2 (struct ln_equ_posn * mean_position, double fromJD, double toJD, struct ln_equ_posn * position)
{
	long double t, t2, t3, A, B, C, zeta, eta, theta, ra, dec, mean_ra, mean_dec, T, T2;
	
	/* change original ra and dec to radians */
	mean_ra = ln_deg_to_rad (mean_position->ra);
	mean_dec = ln_deg_to_rad (mean_position->dec);

	/* calc t, T, zeta, eta and theta Equ 20.2 */
	T = ((long double) (fromJD - JD2000)) / 36525.0;
	T *= 1.0 / 3600.0;
	t = ((long double) (toJD - fromJD)) / 36525.0;
	t *= 1.0 / 3600.0;
	T2 = T * T;
	t2 = t * t;
	t3 = t2 *t;
	zeta = (2306.2181 + 1.39656 * T - 0.000139 * T2) * t + (0.30188 - 0.000344 * T) * t2 + 0.017998 * t3;
	eta = (2306.2181 + 1.39656 * T - 0.000139 * T2) * t + (1.09468 + 0.000066 * T) * t2 + 0.018203 * t3;
	theta = (2004.3109 - 0.85330 * T - 0.000217 * T2) * t - (0.42665 + 0.000217 * T) * t2 - 0.041833 * t3;
	zeta = ln_deg_to_rad (zeta);
	eta = ln_deg_to_rad (eta);
	theta = ln_deg_to_rad (theta); 

	/* calc A,B,C equ 20.4 */
	A = cosl (mean_dec) * sinl (mean_ra + zeta);
	B = cosl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) - sinl (theta) * sinl (mean_dec);
	C = sinl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) + cosl (theta) * sinl (mean_dec);
	
	ra = atan2l (A,B) + eta;
	
	/* check for object near celestial pole */
	if (mean_dec > (0.4 * M_PI) || mean_dec < (-0.4 * M_PI)) {
		/* close to pole */
		dec = acosl (sqrt(A * A + B * B));
		if (mean_dec < 0.)
		  dec *= -1; /* 0 <= acos() <= PI */
	} else {
		/* not close to pole */
		dec = asinl (C);
	}

	/* change to degrees */
	position->ra = ln_range_degrees (ln_rad_to_deg (ra));
	position->dec = ln_rad_to_deg (dec);
}
Beispiel #22
0
long double test1l(long double x)
{
	long double y1, y2;

	y1 = sinl(x);
	y2 = cosl(x);

	return y1 - y2;
}
Beispiel #23
0
void gensine32(int32_t * buf, unsigned count)
{
	long double interval = (2 * ((long double)M_PI)) / count;
	unsigned i;
	for (i = 0; i < count; ++i) {
		buf[i] =
		    (int32_t) (MAX_SAMPLE_VALUE * sinl(i * interval) * GAIN);
	}
}
Beispiel #24
0
float impulse_error(int N, int sign, float *data) {
#ifdef __ANDROID__
	double delta_sum = 0.0f;
	double sum = 0.0f;
#else
	long double delta_sum = 0.0f;
	long double sum = 0.0f;
#endif 

	int i;
	for(i=0;i<N;i++) {
#ifdef __ANDROID__
		double re, im;
		if(sign < 0) {
			re = cos(2 * PI * (double)i / (double)N); 
			im = -sin(2 * PI * (double)i / (double)N); 
		}else{
			re = cos(2 * PI * (double)i / (double)N); 
			im = sin(2 * PI * (double)i / (double)N); 
		}
#else
		long double re, im;
		if(sign < 0) {
			re = cosl(2 * PI * (long double)i / (long double)N); 
			im = -sinl(2 * PI * (long double)i / (long double)N); 
		}else{
			re = cosl(2 * PI * (long double)i / (long double)N); 
			im = sinl(2 * PI * (long double)i / (long double)N); 
		}
#endif
		sum += re * re + im * im;

		re = re - data[2*i];
		im = im - data[2*i+1];
		
		delta_sum += re * re + im * im;

	}
#ifdef __ANDROID__
	return sqrt(delta_sum) / sqrt(sum);
#else
	return sqrtl(delta_sum) / sqrtl(sum);
#endif
}
Beispiel #25
0
long double complex
ccosl(long double complex z)
{
	long double complex w;
	long double ch, sh;

	_cchshl(cimagl(z), &ch, &sh);
	w = cosl(creall(z)) * ch - (sinl(creall(z)) * sh) * I;
	return w;
}
Beispiel #26
0
long double complex
csinl(long double complex z)
{
	long double complex w;
	long double ch, sh;

	cchshl(cimagl(z), &ch, &sh);
	w = sinl(creall(z)) * ch + (cosl(creall(z)) * sh) * I;
	return (w);
}
Beispiel #27
0
/**
 * Calculate the distance between two geodetic location in miles.
 */
double shgeo_dist(shgeo_t *f_geo, shgeo_t *t_geo)
{
  static const shnum_t mile_mod = 90.9;
  shnum_t theta, dist;
  shnum_t lat1, lat2;
  shnum_t lon1, lon2;

  shgeo_loc(f_geo, &lat1, &lon1, NULL);
  shgeo_loc(t_geo, &lat2, &lon2, NULL);

  theta = lon1 - lon2;
  dist = (sinl(_deg2rad(lat1)) * sinl(_deg2rad(lat2))) + 
    (cosl(_deg2rad(lat1)) * cosl(_deg2rad(lat2)) * cosl(_deg2rad(theta)));
  dist = acosl(dist);
  dist = _rad2deg(dist);
  dist = dist * mile_mod;

  return ((double)dist);
}
Beispiel #28
0
__complex__ long double cexpl(__complex__ long double z)
{
	__complex__ long double ret;
	long double r_exponent = expl(__real__ z);

	__real__ ret = r_exponent * cosl(__imag__ z);
	__imag__ ret = r_exponent * sinl(__imag__ z);

	return ret;
}
Beispiel #29
0
long double complex
cexpl(long double complex z)
{
	long double complex w;
	long double r;

	r = expl(creall(z));
	w = r * cosl(cimagl(z)) + (r * sinl(cimagl(z))) * I;
	return (w);
}
Beispiel #30
0
/* Equ 20.3, 20.4 pg 126 
*/
void ln_get_equ_prec (struct ln_equ_posn * mean_position, double JD, struct ln_equ_posn * position)
{
	long double t, t2, t3, A, B, C, zeta, eta, theta, ra, dec, mean_ra, mean_dec;
	
	/* change original ra and dec to radians */
	mean_ra = ln_deg_to_rad (mean_position->ra);
	mean_dec = ln_deg_to_rad (mean_position->dec);

	/* calc t, zeta, eta and theta for J2000.0 Equ 20.3 */
	t = (JD - JD2000) / 36525.0;
	t *= 1.0 / 3600.0;
	t2 = t * t;
	t3 = t2 *t;
	zeta = 2306.2181 * t + 0.30188 * t2 + 0.017998 * t3;
	eta = 2306.2181 * t + 1.09468 * t2 + 0.041833 * t3;
	theta = 2004.3109 * t - 0.42665 * t2 - 0.041833 * t3;
	zeta = ln_deg_to_rad (zeta);
	eta = ln_deg_to_rad (eta);
	theta = ln_deg_to_rad (theta); 

	/* calc A,B,C equ 20.4 */
	A = cosl (mean_dec) * sinl (mean_ra + zeta);
	B = cosl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) - sinl (theta) * sinl (mean_dec);
	C = sinl (theta) * cosl (mean_dec) * cosl (mean_ra + zeta) + cosl (theta) * sinl (mean_dec);
	
	ra = atan2l (A,B) + eta;
	
	/* check for object near celestial pole */
	if (mean_dec > (0.4 * M_PI) || mean_dec < (-0.4 * M_PI)) {
		/* close to pole */
		dec = acosl (sqrt(A * A + B * B));
		if (mean_dec < 0.)
		  dec *= -1; /* 0 <= acos() <= PI */
	} else {
		/* not close to pole */
		dec = asinl (C);
	}

	/* change to degrees */
	position->ra = ln_range_degrees (ln_rad_to_deg (ra));
	position->dec = ln_rad_to_deg (dec);
}