Exemplo n.º 1
0
  void test_divmod_with_a_float() {
    Fixnum* one = as<Fixnum>(Fixnum::from(15));

    Array* ary1 = one->divmod(state, Float::create(state, -3.3));
    Object* o1 = ary1->get(state, 0);
    Object* o2 = ary1->get(state, 1);
    TS_ASSERT(o1->fixnum_p());
    TS_ASSERT_EQUALS(as<Integer>(o1)->to_native(), -5);
    check_float(as<Float>(o2), Float::create(state, -1.5));
  }
TInt CTestFloat_blr::fma_test()
	{
 	// Create temporary variables in stack
  	char chParam[MAX_SIZE];
  	FLOAT input1;
  	FLOAT input2;
  	FLOAT input3;
  	FLOAT expected;
  	FLOAT max_ulp;
  	FLOAT gen_ulp;
  	
  	// Read parameters
  	
  	ReadStringParam ( chParam);
    ReadFloatParam ( input1);
    ReadFloatParam ( input2);
    ReadFloatParam ( input3);
    ReadFloatParam ( expected);
    ReadFloatParam ( max_ulp);
    
    //
    TBuf<MAX_SIZE> buf;
    TInt len = strlen(chParam);
    
    for (TInt j =0; j<len;j++)
    	{
    	buf.Append(chParam[j]);
		}
    
    // Do some testing
    FLOAT res = FUNC(fma) (input1, input2, input3);
        
    if(check_float(res, expected, max_ulp, gen_ulp))
    	{
    	INFO_PRINTF1(_L("Test passed."));
    	}
    else    
    	{
    	ERR_PRINTF1(_L("Test Failed."));
   		return KErrGeneral;
    	}
    
    INFO_PRINTF1(_L("_________________________________________\n"));
    INFO_PRINTF2(_L("TestCase		  : %S\n"), &buf );
    INFO_PRINTF2(_L("Input Value  1 : %f\n"), input1 );
    INFO_PRINTF2(_L("Input Value  2 : %f\n"), input2 );
    INFO_PRINTF2(_L("Input Value  3 : %f\n"), input3 );
    INFO_PRINTF2(_L("Expected Value : %f\n"), expected );
	INFO_PRINTF2(_L("Max ULP value  : %f\n"), max_ulp );
	INFO_PRINTF2(_L("Result  		  : %f\n"), res );
	INFO_PRINTF2(_L("Generated Ulp  : %f\n"), gen_ulp );
	INFO_PRINTF1(_L("_________________________________________\n"));
     
    return KErrNone;
	}
static int gritobj_update_sphere (lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(GritObjectPtr,self,1,GRITOBJ_TAG);
        Vector3 pos = check_v3(L,2);
        float r = check_float(L,3);
        self->updateSphere(pos, r);
        return 0;
TRY_END
}
Exemplo n.º 4
0
int
main (int argc, char *argv[])
{
  tests_start_mpfr ();

  check_nans ();
  check_exact ();
  check_float ();

  check53("6.9314718055994530941514e-1", "0.0", MPFR_RNDZ, "0.0");
  check53("0.0", "6.9314718055994530941514e-1", MPFR_RNDZ, "0.0");
  check_sign();
  check53("-4.165000000e4", "-0.00004801920768307322868063274915", MPFR_RNDN,
          "2.0");
  check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165",
          MPFR_RNDZ, "-1.8251348697787782844e-172");
  check53("2.71331408349172961467e-08", "-6.72658901114033715233e-165",
          MPFR_RNDA, "-1.8251348697787786e-172");
  check53("0.31869277231188065", "0.88642843322303122", MPFR_RNDZ,
          "2.8249833483992453642e-1");
  check("8.47622108205396074254e-01", "3.24039313247872939883e-01", MPFR_RNDU,
        28, 45, 2, "0.375");
  check("8.47622108205396074254e-01", "3.24039313247872939883e-01", MPFR_RNDA,
        28, 45, 2, "0.375");
  check("2.63978122803639081440e-01", "6.8378615379333496093e-1", MPFR_RNDN,
        34, 23, 31, "0.180504585267044603");
  check("1.0", "0.11835170935876249132", MPFR_RNDU, 6, 41, 36,
        "0.1183517093595583");
  check53("67108865.0", "134217729.0", MPFR_RNDN, "9.007199456067584e15");
  check("1.37399642157394197284e-01", "2.28877275604219221350e-01", MPFR_RNDN,
        49, 15, 32, "0.0314472340833162888");
  check("4.03160720978664954828e-01", "5.854828e-1"
        /*"5.85483042917246621073e-01"*/, MPFR_RNDZ,
        51, 22, 32, "0.2360436821472831");
  check("3.90798504668055102229e-14", "9.85394674650308388664e-04", MPFR_RNDN,
        46, 22, 12, "0.385027296503914762e-16");
  check("4.58687081072827851358e-01", "2.20543551472118792844e-01", MPFR_RNDN,
        49, 3, 2, "0.09375");
  check_max();
  check_min();

  check_regression ();
  test_generic (2, 500, 100);

  data_check ("data/mulpi", mpfr_mulpi, "mpfr_mulpi");

  valgrind20110503 ();

  tests_end_mpfr ();
  return 0;
}
static int global_physics_sweep_cylinder (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        float radius = check_float(L, 1);
        float height = check_float(L, 2);
        Quaternion q = check_quat(L, 3);
        Vector3 start = check_v3(L, 4);
        Vector3 ray = check_v3(L, 5);
        bool nearest_only = check_bool(L, 6);
        unsigned long flags = check_t<unsigned long>(L, 7);

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_cylinder(start, q, start+ray, lcb, radius, height);

        return lcb.pushResults(L);

TRY_END
}
Exemplo n.º 6
0
int main(int argc, char const* argv[])
{
  srand((unsigned)time(NULL));
  int i;
  for ( int i = 0; i < 100000; i++ ) {
    if ( !check_float( rand_float() ) ) {
      printf( "失敗\n" );
      return 0; 
    } 
  }
  printf( "成功\n" );
  return 0;
   
}
Exemplo n.º 7
0
bool 
Sol_MultigridPressure3DBase::initialize_base_storage(int nx_val, int ny_val, int nz_val, double hx_val, double hy_val, double hz_val)
{
  // pre-validate
  if (!check_float(hx_val) || !check_float(hy_val) || !check_float(hz_val)) {
    printf("[ERROR] Sol_MultigridPressure3DBase::initialize_storage - garbage hx,hy,hz value %f %f %f\n", hx_val, hy_val, hz_val);
    return false;
  }

  // do allocation and initialization
  _num_levels = num_levels(nx_val, ny_val, nz_val);

  _h = new double[_num_levels];
  _dim = new int3[_num_levels];
  _h[0] = min3(hx_val, hy_val, hz_val);
  _fx = (_h[0] * _h[0]) / (hx_val * hx_val);
  _fy = (_h[0] * _h[0]) / (hy_val * hy_val);
  _fz = (_h[0] * _h[0]) / (hz_val * hz_val);
  _omega = optimal_omega(_fx, _fy, _fz);
  _dim[0].x = nx_val;
  _dim[0].y = ny_val;
  _dim[0].z = nz_val;

  int level;
  for (level=1; level < _num_levels; level++) {
    int this_nx = nx(level-1)/2;
    int this_ny = ny(level-1)/2;
    int this_nz = nz(level-1)/2;

    _h[level] = get_h(level-1)*2;
    _dim[level].x = this_nx;
    _dim[level].y = this_ny;
    _dim[level].z = this_nz;
  }

  return true;
}
int plot_v3_make (lua_State *L)
{
TRY_START
        PlotV3 *self = new PlotV3();
        check_args(L,1);
        int table = lua_gettop(L);
        if (!lua_istable(L,table))
                my_lua_error(L,"Parameter should be a table");
        for (lua_pushnil(L) ; lua_next(L,table)!=0 ; lua_pop(L,1)) {
                // the name is held in the object anyway
                float k = check_float(L,-2);
                Vector3 v = check_v3(L,-1);
                self->addPoint(k,v);
        }
        self->commit();
        push(L,self,PLOT_V3_TAG);
        return 1;
TRY_END
}
Exemplo n.º 9
0
/*---CONVERT ARRAY OF CHAR TO NUMBER---*/
float get_num(char a[])
{
	int i=0,n,j,l;
	float f=0;

	l = strlen(a);

	if(check_float(a)==1)
	{
		n = get_point(a);

		for(j = 0; j < n; j++)
		{
			i = i*10;
			i += a[j] - 48;
		}

		for(j = n+1;j<l;j++)
		{
			f = f*10;
			f += a[j]-48;
		}

		for(j = 0; j<(l-n-1);j++)
		{
			f = f/10;
		}

		f = i+f;

		return f;
	}
	else
	{
		for(j=0;j<l;j++)
		{
			i = i*10;
			i += a[j]-48;
		}
		f = i;
		return f;
	}
}
Exemplo n.º 10
0
void adjust_ra(FL_OBJECT *ob, long data)
{
    char tbuf[50];
    char *p;

    strcpy (tbuf, fl_get_input(ob));
    p = strchr(tbuf, '\n');
    if (p != NULL)
    {
        *p = '\0';
    }
    if (check_float (tbuf) < 0)
    {
        fl_set_input (ob, "Format Error");
    }
    else
    {
        ra = atof(tbuf);
    }
}
Exemplo n.º 11
0
bool 
Sol_MultigridPressure3DBase::solve(double &residual, double tolerance, int max_iter)
{
  if (!check_float(tolerance)) {
    printf("[ERROR] Sol_MultigridPressure3DDevice::solve - garbage tolerance value %f\n", tolerance);
    return false;
  }

  if (tolerance < 0) {
    printf("[ERROR] Sol_MultigridPressure3DDevice::solve - negative tolerance value %f\n", tolerance);
    return false;
  }

  if (max_iter <= 0) {
    printf("[WARNING] Sol_MultigridPressure3DDevice::solve - non-positive max_iter %d\n", max_iter);
    return false;
  }

  double l2, linf;
  if (!do_fmg(tolerance, max_iter, l2, linf)) {

    // try again with initual solution vector set to 0.  This can fix the problem
    // of certain error modes growing when resuing the previous solution as a
    // starting point.
    printf("[WARNING] Sol_MultigridPressure3DBase::solve - do_fmg did not converge, retrying with zeroed initial search vector\n");
    clear_zero(0);
    if (!do_fmg(tolerance, max_iter, l2, linf)) {

      printf("[WARNING] Sol_MultigridPressure3DBase::solve - do_fmg failed\n");
      residual = (convergence == CONVERGENCE_L2) ? l2 : linf;
      return false;

    }
  }
  residual = (convergence == CONVERGENCE_L2) ? l2 : linf;
  //printf("residual = %g\n", residual);

  return true;
}
static int plot_index(lua_State *L)
{
TRY_START
        typedef Plot::Map Map;
        typedef Plot::MI MI;
        check_args(L,2);
        GET_UD_MACRO(Plot,self,1,PLOT_TAG);
        if (lua_type(L,2)==LUA_TNUMBER) {
                float k = check_float(L,2);
                lua_pushnumber(L,self[k]);
        } else {
                std::string key  = luaL_checkstring(L,2);
                if (key=="minX") {
                        lua_pushnumber(L,self.minX());
                } else if (key=="maxX") {
                        lua_pushnumber(L,self.maxX());
                } else if (key=="points") {
                        Map data = self.getPoints();
                        lua_createtable(L, data.size(), 0);
                        for (MI i=data.begin(), i_=data.end() ; i!=i_ ; ++i) {
                                lua_pushnumber(L,i->first);
                                lua_pushnumber(L,i->second);
                                lua_settable(L,-3);
                        }
                } else if (key=="tangents") {
                        Map data = self.getTangents();
                        lua_createtable(L, data.size(), 0);
                        for (MI i=data.begin(), i_=data.end() ; i!=i_ ; ++i) {
                                lua_pushnumber(L,i->first);
                                lua_pushnumber(L,i->second);
                                lua_settable(L,-3);
                        }
                } else {
                        my_lua_error(L,"Not a readable Plot member: "+key);
                }
        }
        return 1;
TRY_END
}
Exemplo n.º 13
0
void
adjust_sky_frequency (FL_OBJECT *ob, long data)
{
    char *p;
    char tbuf[128];

    p = (char *)fl_get_input (ob);
    strcpy (tbuf, p);
    if ((p = strchr (tbuf, '\n')) != NULL)
    {
        *p = '\0';
    }
    if (strcmp (tbuf, "lock") == 0 ||
            strcmp (tbuf, "locked") == 0 ||
            strcmp (tbuf, "tuner") == 0 ||
            strncmp (tbuf, "----", 4) == 0)
    {
        char d[128];
        sky_locked = 1;
        sky_freq = frequency;
        sprintf (d, "%f", sky_freq);
        fl_set_input (ob, d);
        fl_set_button (fd_receiver_main->sky_lock_button, 1);
    }
    else
    {
        if (check_float (tbuf) < 0)
        {
            fl_set_input (ob, "Format Error");
        }
        else
        {
            sky_freq = atof(tbuf);
            sky_locked = 0;
        }
        write_rcvr_params ("skyfreq", sky_freq);
    }
}
Exemplo n.º 14
0
void adjust_pulsar_rate(FL_OBJECT *ob, long data)
{
    char tbuf[50];
    char *p;
    double real_rate;
    int int_rate;
    double err;
    char str[64];

    strcpy (tbuf, fl_get_input(ob));
    p = strchr(tbuf, '\n');
    if (p != NULL)
    {
        *p = '\0';
    }
    if ((p = strchr(tbuf, '\r')) != NULL)
    {
        *p = '\0';
    }
    if (check_float (tbuf) < 0)
    {
        fl_set_input (ob, "Format Error");
    }
    else
    {
        pulsar_rate = (double)atof(tbuf);

        real_rate = (1.0/pulsar_rate)*(double)psr_rate;
        int_rate = (int)(real_rate);
        err = fabsf(real_rate - int_rate);
        err = err / real_rate;
        sprintf (str, "%8.2f", err*1.0e6);
        fl_set_object_label (fd_receiver_main->phase_display, str);
    }

}
Exemplo n.º 15
0
 void test_mod_with_a_float() {
   Float* f = Fixnum::from(4)->mod(state, Float::create(state, -1.7));
   check_float(f, Float::create(state, -1.1));
 }
static int gritobj_newindex (lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(GritObjectPtr,self,1,GRITOBJ_TAG);
        std::string key = check_string(L,2);

        if (key=="destroy") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="near") {
                if (lua_isnil(L,3)) {
                        self->setNearObj(self,GritObjectPtr());
                } else {
                        GET_UD_MACRO(GritObjectPtr,v,3,GRITOBJ_TAG);
                        self->setNearObj(self,v);
                }
        } else if (key=="far") {
                if (lua_isnil(L,3)) {
                        self->setNearObj(self,GritObjectPtr());
                } else {
                        GET_UD_MACRO(GritObjectPtr,v,3,GRITOBJ_TAG);
                        self->setFarObj(self,v);
                }
        } else if (key=="fade") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="updateSphere") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="pos") {
                self->updateSphere(check_v3(L,3));
        } else if (key=="renderingDistance") {
                self->updateSphere(check_float(L,3));
        } else if (key=="getSphere") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="activated") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="deactivate") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="activate") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="instance") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="hintAdvancePrepare") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="getAdvancePrepareHints") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="destroyed") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="class") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="className") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="name") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="needsFrameCallbacks") {
                self->setNeedsFrameCallbacks(self, check_bool(L,3));
        } else if (key=="needsStepCallbacks") {
                self->setNeedsStepCallbacks(self, check_bool(L,3));
        } else {
                GritClass *c = self->getClass();
                if (c==NULL) my_lua_error(L,"GritObject destroyed");
                const char *err = self->userValues.luaSet(L);
                if (err) my_lua_error(L, err);
        }

        return 0;
TRY_END
}
int
main (void)
{
  mpfr_prec_t p;
  int k;

  tests_start_mpfr ();

  for (p = MPFR_PREC_MIN; p <= 128; p++)
    {
      test_property1 (p, MPFR_RNDN, 0);
      test_property1 (p, MPFR_RNDU, 0);
      test_property1 (p, MPFR_RNDA, 0);
      test_property1 (p, MPFR_RNDN, 1);
      test_property1 (p, MPFR_RNDU, 1);
      test_property1 (p, MPFR_RNDA, 1);
      test_property2 (p, MPFR_RNDN);
    }

  check_diverse ("635030154261163106768013773815762607450069292760790610550915652722277604820131530404842415587328", 160, "796887792767063979679855997149887366668464780637");
  special ();
  check_nan ();

  for (p=2; p<200; p++)
    for (k=0; k<200; k++)
      check_inexact (p);
  check_float();

  check3 ("-0.0", MPFR_RNDN, "0.0");
  check4 ("6.37983013646045901440e+32", MPFR_RNDN, "5.9bc5036d09e0c@13");
  check4 ("1.0", MPFR_RNDN, "1");
  check4 ("1.0", MPFR_RNDZ, "1");
  check4 ("3.725290298461914062500000e-9", MPFR_RNDN, "4@-4");
  check4 ("3.725290298461914062500000e-9", MPFR_RNDZ, "4@-4");
  check4 ("1190456976439861.0", MPFR_RNDZ, "2.0e7957873529a@6");
  check4 ("1219027943874417664.0", MPFR_RNDZ, "4.1cf2af0e6a534@7");
  /* the following examples are bugs in Cygnus compiler/system, found by
     Fabrice Rouillier while porting mpfr to Windows */
  check4 ("9.89438396044940256501e-134", MPFR_RNDU, "8.7af7bf0ebbee@-56");
  check4 ("7.86528588050363751914e+31", MPFR_RNDZ, "1.f81fc40f32062@13");
  check4 ("0.99999999999999988897", MPFR_RNDN, "f.ffffffffffff8@-1");
  check4 ("1.00000000000000022204", MPFR_RNDN, "1");
  /* the following examples come from the paper "Number-theoretic Test
   Generation for Directed Rounding" from Michael Parks, Table 4 */

  check4 ("78652858805036375191418371571712.0", MPFR_RNDN,
          "1.f81fc40f32063@13");
  check4 ("38510074998589467860312736661504.0", MPFR_RNDN,
          "1.60c012a92fc65@13");
  check4 ("35318779685413012908190921129984.0", MPFR_RNDN,
          "1.51d17526c7161@13");
  check4 ("26729022595358440976973142425600.0", MPFR_RNDN,
          "1.25e19302f7e51@13");
  check4 ("22696567866564242819241453027328.0", MPFR_RNDN,
          "1.0ecea7dd2ec3d@13");
  check4 ("22696888073761729132924856434688.0", MPFR_RNDN,
          "1.0ecf250e8e921@13");
  check4 ("36055652513981905145251657416704.0", MPFR_RNDN,
          "1.5552f3eedcf33@13");
  check4 ("30189856268896404997497182748672.0", MPFR_RNDN,
          "1.3853ee10c9c99@13");
  check4 ("36075288240584711210898775080960.0", MPFR_RNDN,
          "1.556abe212b56f@13");
  check4 ("72154663483843080704304789585920.0", MPFR_RNDN,
          "1.e2d9a51977e6e@13");

  check4 ("78652858805036375191418371571712.0", MPFR_RNDZ,
          "1.f81fc40f32062@13");
  check4 ("38510074998589467860312736661504.0", MPFR_RNDZ,
          "1.60c012a92fc64@13");
  check4 ("35318779685413012908190921129984.0", MPFR_RNDZ, "1.51d17526c716@13");
  check4 ("26729022595358440976973142425600.0", MPFR_RNDZ, "1.25e19302f7e5@13");
  check4 ("22696567866564242819241453027328.0", MPFR_RNDZ,
          "1.0ecea7dd2ec3c@13");
  check4 ("22696888073761729132924856434688.0", MPFR_RNDZ, "1.0ecf250e8e92@13");
  check4 ("36055652513981905145251657416704.0", MPFR_RNDZ,
          "1.5552f3eedcf32@13");
  check4 ("30189856268896404997497182748672.0", MPFR_RNDZ,
          "1.3853ee10c9c98@13");
  check4 ("36075288240584711210898775080960.0", MPFR_RNDZ,
          "1.556abe212b56e@13");
  check4 ("72154663483843080704304789585920.0", MPFR_RNDZ,
          "1.e2d9a51977e6d@13");

  check4 ("78652858805036375191418371571712.0", MPFR_RNDU,
          "1.f81fc40f32063@13");
  check4 ("38510074998589467860312736661504.0", MPFR_RNDU,
          "1.60c012a92fc65@13");
  check4 ("35318779685413012908190921129984.0", MPFR_RNDU,
          "1.51d17526c7161@13");
  check4 ("26729022595358440976973142425600.0", MPFR_RNDU,
          "1.25e19302f7e51@13");
  check4 ("22696567866564242819241453027328.0", MPFR_RNDU,
          "1.0ecea7dd2ec3d@13");
  check4 ("22696888073761729132924856434688.0", MPFR_RNDU,
          "1.0ecf250e8e921@13");
  check4 ("36055652513981905145251657416704.0", MPFR_RNDU,
          "1.5552f3eedcf33@13");
  check4 ("30189856268896404997497182748672.0", MPFR_RNDU,
          "1.3853ee10c9c99@13");
  check4 ("36075288240584711210898775080960.0", MPFR_RNDU,
          "1.556abe212b56f@13");
  check4 ("72154663483843080704304789585920.0", MPFR_RNDU,
          "1.e2d9a51977e6e@13");

  check4 ("78652858805036375191418371571712.0", MPFR_RNDD,
          "1.f81fc40f32062@13");
  check4 ("38510074998589467860312736661504.0", MPFR_RNDD,
          "1.60c012a92fc64@13");
  check4 ("35318779685413012908190921129984.0", MPFR_RNDD, "1.51d17526c716@13");
  check4 ("26729022595358440976973142425600.0", MPFR_RNDD, "1.25e19302f7e5@13");
  check4 ("22696567866564242819241453027328.0", MPFR_RNDD,
          "1.0ecea7dd2ec3c@13");
  check4 ("22696888073761729132924856434688.0", MPFR_RNDD, "1.0ecf250e8e92@13");
  check4 ("36055652513981905145251657416704.0", MPFR_RNDD,
          "1.5552f3eedcf32@13");
  check4 ("30189856268896404997497182748672.0", MPFR_RNDD,
          "1.3853ee10c9c98@13");
  check4 ("36075288240584711210898775080960.0", MPFR_RNDD,
          "1.556abe212b56e@13");
  check4 ("72154663483843080704304789585920.0", MPFR_RNDD,
          "1.e2d9a51977e6d@13");

  /* check that rounding away is just rounding toward plus infinity */
  check4 ("72154663483843080704304789585920.0", MPFR_RNDA,
          "1.e2d9a51977e6e@13");

  test_generic (2, 300, 15);
  data_check ("data/sqrt", mpfr_sqrt, "mpfr_sqrt");
  bad_cases (mpfr_sqrt, mpfr_sqr, "mpfr_sqrt", 8, -256, 255, 4, 128, 800, 50);

  tests_end_mpfr ();
  return 0;
}
Exemplo n.º 18
0
/**
 * This function executes vertex programs
 */
static GLboolean
run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage )
{
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct vp_stage_data *store = VP_STAGE_DATA(stage);
   struct vertex_buffer *VB = &tnl->vb;
   struct gl_vertex_program *program = ctx->VertexProgram._Current;
   struct gl_program_machine *machine = &store->machine;
   GLuint outputs[VARYING_SLOT_MAX], numOutputs;
   GLuint i, j;

   if (!program)
      return GL_TRUE;

   /* ARB program or vertex shader */
   _mesa_load_state_parameters(ctx, program->Base.Parameters);

   /* make list of outputs to save some time below */
   numOutputs = 0;
   for (i = 0; i < VARYING_SLOT_MAX; i++) {
      if (program->Base.OutputsWritten & BITFIELD64_BIT(i)) {
         outputs[numOutputs++] = i;
      }
   }

   /* Allocate result vectors.  We delay this until now to avoid allocating
    * memory that would never be used if we don't run the software tnl pipeline.
    */
   if (!store->results[0].storage) {
      for (i = 0; i < VARYING_SLOT_MAX; i++) {
         assert(!store->results[i].storage);
         _mesa_vector4f_alloc( &store->results[i], 0, VB->Size, 32 );
         store->results[i].size = 4;
      }
   }

   map_textures(ctx, program);

   for (i = 0; i < VB->Count; i++) {
      GLuint attr;

      init_machine(ctx, machine, tnl->CurInstance);

#if 0
      printf("Input  %d: %f, %f, %f, %f\n", i,
             VB->AttribPtr[0]->data[i][0],
             VB->AttribPtr[0]->data[i][1],
             VB->AttribPtr[0]->data[i][2],
             VB->AttribPtr[0]->data[i][3]);
      printf("   color: %f, %f, %f, %f\n",
             VB->AttribPtr[3]->data[i][0],
             VB->AttribPtr[3]->data[i][1],
             VB->AttribPtr[3]->data[i][2],
             VB->AttribPtr[3]->data[i][3]);
      printf("  normal: %f, %f, %f, %f\n",
             VB->AttribPtr[2]->data[i][0],
             VB->AttribPtr[2]->data[i][1],
             VB->AttribPtr[2]->data[i][2],
             VB->AttribPtr[2]->data[i][3]);
#endif

      /* the vertex array case */
      for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
	 if (program->Base.InputsRead & BITFIELD64_BIT(attr)) {
	    const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data;
	    const GLuint size = VB->AttribPtr[attr]->size;
	    const GLuint stride = VB->AttribPtr[attr]->stride;
	    const GLfloat *data = (GLfloat *) (ptr + stride * i);
#ifdef NAN_CHECK
            check_float(data[0]);
            check_float(data[1]);
            check_float(data[2]);
            check_float(data[3]);
#endif
	    COPY_CLEAN_4V(machine->VertAttribs[attr], size, data);
	 }
      }

      /* execute the program */
      _mesa_execute_program(ctx, &program->Base, machine);

      /* copy the output registers into the VB->attribs arrays */
      for (j = 0; j < numOutputs; j++) {
         const GLuint attr = outputs[j];
#ifdef NAN_CHECK
         check_float(machine->Outputs[attr][0]);
         check_float(machine->Outputs[attr][1]);
         check_float(machine->Outputs[attr][2]);
         check_float(machine->Outputs[attr][3]);
#endif
         COPY_4V(store->results[attr].data[i], machine->Outputs[attr]);
      }

      /* FOGC is a special case.  Fragment shader expects (f,0,0,1) */
      if (program->Base.OutputsWritten & BITFIELD64_BIT(VARYING_SLOT_FOGC)) {
         store->results[VARYING_SLOT_FOGC].data[i][1] = 0.0;
         store->results[VARYING_SLOT_FOGC].data[i][2] = 0.0;
         store->results[VARYING_SLOT_FOGC].data[i][3] = 1.0;
      }
#ifdef NAN_CHECK
      ASSERT(machine->Outputs[0][3] != 0.0F);
#endif
#if 0
      printf("HPOS: %f %f %f %f\n",
             machine->Outputs[0][0], 
             machine->Outputs[0][1], 
             machine->Outputs[0][2], 
             machine->Outputs[0][3]);
#endif
   }

   unmap_textures(ctx, program);

   if (program->IsPositionInvariant) {
      /* We need the exact same transform as in the fixed function path here
       * to guarantee invariance, depending on compiler optimization flags
       * results could be different otherwise.
       */
      VB->ClipPtr = TransformRaw( &store->results[0],
				  &ctx->_ModelProjectMatrix,
				  VB->AttribPtr[0] );

      /* Drivers expect this to be clean to element 4...
       */
      switch (VB->ClipPtr->size) {
      case 1:
	 /* impossible */
      case 2:
	 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 2 );
	 /* fall-through */
      case 3:
	 _mesa_vector4f_clean_elem( VB->ClipPtr, VB->Count, 3 );
	 /* fall-through */
      case 4:
	 break;
      }
   }
   else {
      /* Setup the VB pointers so that the next pipeline stages get
       * their data from the right place (the program output arrays).
       */
      VB->ClipPtr = &store->results[VARYING_SLOT_POS];
      VB->ClipPtr->size = 4;
      VB->ClipPtr->count = VB->Count;
   }

   VB->AttribPtr[VERT_ATTRIB_COLOR0] = &store->results[VARYING_SLOT_COL0];
   VB->AttribPtr[VERT_ATTRIB_COLOR1] = &store->results[VARYING_SLOT_COL1];
   VB->AttribPtr[VERT_ATTRIB_FOG] = &store->results[VARYING_SLOT_FOGC];
   VB->AttribPtr[_TNL_ATTRIB_POINTSIZE] = &store->results[VARYING_SLOT_PSIZ];
   VB->BackfaceColorPtr = &store->results[VARYING_SLOT_BFC0];
   VB->BackfaceSecondaryColorPtr = &store->results[VARYING_SLOT_BFC1];

   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
      VB->AttribPtr[_TNL_ATTRIB_TEX0 + i]
         = &store->results[VARYING_SLOT_TEX0 + i];
   }

   for (i = 0; i < ctx->Const.MaxVarying; i++) {
      if (program->Base.OutputsWritten & BITFIELD64_BIT(VARYING_SLOT_VAR0 + i)) {
         /* Note: varying results get put into the generic attributes */
	 VB->AttribPtr[VERT_ATTRIB_GENERIC0+i]
            = &store->results[VARYING_SLOT_VAR0 + i];
      }
   }


   /* Perform NDC and cliptest operations:
    */
   return do_ndc_cliptest(ctx, store);
}
Exemplo n.º 19
0
char* check_option(char **in,int n,int which,int type)
{
  char test,*ret=NULL,wasfound=0,ok=1;
  int i;
  
  for (i=1;i<n;i++) {
    if (in[i] != NULL) {
      test= (in[i][0] == '-') && (in[i][1] == which);
      if (test) {
	wasfound=1;
	if (type != 'n') {
	  if (strlen(in[i]) > 2) {
	    switch(type) {
	    case 'u': check_unsigned(in[i]+2,which);break;
	    case 'd': check_integer(in[i]+2,which);break;
	    case 'f': check_float(in[i]+2,which);break;
	    case '2': check_two(in[i]+2,which);break;
	    case '3': check_three(in[i]+2,which);break;
	    }
	    if (ret != NULL)
	      free(ret);
	    check_alloc(ret=(char*)calloc(strlen(in[i]+2)+1,(size_t)1));
	    strcpy(ret,in[i]+2);
	    in[i]=NULL;
	  }
	  else {
	    in[i]=NULL;
	    i++;
	    if (i < n) {
	      if (in[i] != NULL) {
		switch(type) {
		case 'u': check_unsigned(in[i],which);break;
		case 'd': check_integer(in[i],which);break;
		case 'f': check_float(in[i],which);break;
		case '2': check_two(in[i],which);break;
   	        case '3': check_three(in[i]+2,which);break;
		case 'o': ok=check_optional(in[i],which);break;
		}
		if (ok) {
		  if (ret != NULL)
		    free(ret);
		  check_alloc(ret=(char*)calloc(strlen(in[i])+1,(size_t)1));
		  strcpy(ret,in[i]);
		  in[i]=NULL;
		}
		else {
		  i--;
		  if (ret != NULL)
		    free(ret);
		  ret=NULL;
		}
	      }
	    }
	    else {
	      if (ret != NULL) {
		free(ret);
		ret=NULL;
	      }
	    }
	  }
	}
	else {
	  in[i]=NULL;
	}
      }
    }
  }
  
  if (((type == 'o') || (type == 'n')) && (ret == NULL) && wasfound)
    return "";

  if (wasfound && (ret == NULL)) {
    fprintf(stderr,"The option -%c needs some value. Exiting!\n",which);
    exit(CHECK_OPTION_C_NO_VALUE);
  }
  return ret;
}
Exemplo n.º 20
0
int main(int argc, char **argv)
{
  char *daemon_dir = NULL;
  char *socket_name = NULL;
  const char *inpath=NULL;
  int input_fd = STDIN_FILENO;
  const char *outpath=NULL;
  int output_fd = STDOUT_FILENO;

  {
    int c, i;
    const char *short_opts = "i:o:d:c:hVr:p:v:w:W:t:P::lL";
    while ((c=getopt_long(argc, argv, short_opts, program_options, &i)) != -1)
      {
        switch (c)
          {
          case 'V':
            show_version(argv[0]);
            return 0;
          case 'h':
            show_help(argv[0]);
            return 0;
          case 'r':
            check_float("rate", optarg);
            record_param("rate", optarg);
            break;
          case 'p':
            check_float("pitch", optarg);
            record_param("pitch", optarg);
            break;
          case 'v':
            check_float("volume", optarg);
            record_param("volume", optarg);
            break;
          case 't':
            if (strcmp(optarg, "text") == 0
                || strcmp(optarg, "ssml") == 0
                || strcmp(optarg, "characters") == 0)
              record_param("type", optarg);
            else
              {
                fprintf(stderr, "Incorrect value of --type: `%s'\n", optarg);
                exit(1);
              }
            break;
          case 'w':
            record_param("variant", optarg);
            break;
          case 'W':
            record_param("voice", optarg);
            break;
          case 'i':
            inpath = optarg;
            break;
          case 'o':
            outpath = optarg;
            break;
          case 'P':
            record_param("punct", optarg ? optarg : "");
            break;
          case 'D':
            daemon_dir = optarg;
            break;
          case 0:
            break;
          default:
            show_help(argv[0]);
            return 1;
          }
      }
  }

  if (daemon_dir)
    add_path(&socket_name, daemon_dir);
  else
    {
      add_path(&socket_name, getenv("HOME"));
      add_path(&socket_name, ".rhvoice");
    }
  add_path(&socket_name, "socket");

  // Creates a socket and connects to it.
  int sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock == -1)
    {
      perror("socket");
      exit(1);
    }

  struct sockaddr_un addr;
  memset(&addr, 0, sizeof(addr));
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, socket_name, sizeof(addr.sun_path) - 1);

  if (connect(sock, (struct sockaddr *) &addr, sizeof(addr)) == -1)
    {
      perror("connect");
      exit(1);
    }

  // Opens input/output files.
  if (inpath && (input_fd = open(inpath, O_RDONLY)) == -1)
    {
      perror(inpath);
      exit(1);
    }
  if (outpath && (output_fd = open(outpath, O_WRONLY|O_TRUNC, 0666)) == -1)
    {
      perror(outpath);
      exit(1);
    }
  if (isatty(output_fd))
    {
      fprintf(stderr, "Cannot write to a terminal.\n");
      exit(1);
    }

  int n, nw;			/* number of read/written bytes */
  if (used >= sizeof(buf)/2)
    {
      // The header is large so write it first.
      nw = 0;
      while (nw < used && (n = write(sock, buf+nw, used-nw)) != -1)
        nw += n;
      used = 0;
    }
  buf[used++] = '\n';

  // First copies whole input to socket.
  while ((n = read(input_fd, buf+used, sizeof(buf)-used)) > 0)
    {
      used += n;
      nw = 0;
      while (nw < used && (n = write(sock, buf+nw, used-nw)) != -1)
        nw += n;
      used = 0;
    }
  shutdown(sock, SHUT_WR);

  // Copies response to output.
  while ((used = read(sock, buf, sizeof(buf))) > 0)
    {
      nw = 0;
      while (nw < used && (n = write(STDOUT_FILENO, buf+nw, used-nw)) != -1)
        nw += n;
  }

  return 0;
}
static int rbody_newindex (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        const char *key = luaL_checkstring(L, 2);
        if (!::strcmp(key, "linearVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setLinearVelocity(v);
        } else if (!::strcmp(key, "angularVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setAngularVelocity(v);
        } else if (!::strcmp(key, "worldPosition")) {
                Vector3 v = check_v3(L, 3);
                self.setPosition(v);
        } else if (!::strcmp(key, "worldOrientation")) {
                Quaternion v = check_quat(L, 3);
                self.setOrientation(v);
        } else if (!::strcmp(key, "contactProcessingThreshold")) {
                float v = check_float(L, 3);
                self.setContactProcessingThreshold(v);
        } else if (!::strcmp(key, "linearDamping")) {
                float v = check_float(L, 3);
                self.setLinearDamping(v);
        } else if (!::strcmp(key, "angularDamping")) {
                float v = check_float(L, 3);
                self.setAngularDamping(v);
        } else if (!::strcmp(key, "linearSleepThreshold")) {
                float v = check_float(L, 3);
                self.setLinearSleepThreshold(v);
        } else if (!::strcmp(key, "angularSleepThreshold")) {
                float v = check_float(L, 3);
                self.setAngularSleepThreshold(v);
        } else if (!::strcmp(key, "mass")) {
                float v = check_float(L, 3);
                self.setMass(v);
        } else if (!::strcmp(key, "ghost")) {
                bool v = check_bool(L, 3);
                self.setGhost(v);
        } else if (!::strcmp(key, "updateCallback")) {
                self.updateCallbackPtr.set(L);
        } else if (!::strcmp(key, "stepCallback")) {
                self.stepCallbackPtr.set(L);
        } else if (!::strcmp(key, "collisionCallback")) {
                self.collisionCallbackPtr.set(L);
        } else if (!::strcmp(key, "stabiliseCallback")) {
                self.stabiliseCallbackPtr.set(L);
        } else if (!::strcmp(key, "inertia")) {
                Vector3 v = check_v3(L, 3);
                self.setInertia(v);
        } else if (!::strcmp(key, "owner")) {
                if (lua_isnil(L, 3)) {
                        self.owner.setNull();
                } else {
                        GET_UD_MACRO(GritObjectPtr, v, 3, GRITOBJ_TAG);
                        self.owner = v;
                }

        } else {
               my_lua_error(L, "Not a writeable RigidBody member: "+std::string(key));
        }
        return 0;
TRY_END
}
Exemplo n.º 22
0
 void test_add_a_float() {
   Fixnum* one = Fixnum::from(13);
   Float* res = one->add(state, Float::create(state, 1.4));
   check_float(res, Float::create(state, 14.4));
 }
Exemplo n.º 23
0
 void test_to_f() {
   Float* f = Fixnum::from(5)->to_f(state);
   check_float(f, Float::create(state, 5.0));
   f = Fixnum::from(-2)->to_f(state);
   check_float(f, Float::create(state, -2.0));
 }
Exemplo n.º 24
0
void TestApp::test_matrix_mat4()
{
	Console::write_line("  Class: Mat4");

	Console::write_line("   Function: inverse()");
	{

		Mat4f test_src = Mat4f::rotate((Angle(30, angle_degrees)), 1.0, 0.0, 0.0, true);
		Mat4f test_inv;
		Mat4f test_dest;
		Mat4f test_ident = Mat4f::identity();

		test_dest = test_src;
		test_dest.inverse();
		test_dest = test_dest * test_src;

		if (test_ident != test_dest) fail();

	}

	static int test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2};
	static int test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2};

	Mat4i test_a(test_a_values);
	Mat4i test_b(test_b_values);

	Console::write_line("   Function: add() and operator");
	{
		int answer_values[] = {7, 8, 4, 9, 8, 11, 6, 11, 4, 7, 12, 16, 8, 7, 13, 4};
		Mat4i answer(answer_values);

		Mat4i result = test_a + test_b;
		if (result != answer) fail();

		result = Mat4i::add(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: subtract() and operator");
	{
		int answer_values[] = {-1, -6, 0, -1, 2, 1, 2, -7, -2, 1, 0, -2, 4, -1, 1, 0};
		Mat4i answer(answer_values);

		Mat4i result = test_a - test_b;
		if (result != answer) fail();

		result = Mat4i::subtract(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: translate()");
	{
		int answer_values[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, 4, 1};
		Mat4i answer(answer_values);

		Mat4i result = Mat4i::translate(2, 3, 4);
		if (result != answer) fail();
	}

	Console::write_line("   Function: translate_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::translate(2, 3, 4);

		Mat4i result2 = test_a;
		result2.translate_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: scale_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::scale(2, 3, 4);

		Mat4i result2 = test_a;
		result2.scale_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: rotate (using euler angles) and get_euler");
	{
		Angle angle_x(20, angle_degrees);
		Angle angle_y(30, angle_degrees);
		Angle angle_z(40, angle_degrees);

		Mat4f test_matrix;
		test_matrix = Mat4f::rotate(angle_x, angle_y, angle_z, order_YXZ);

		Vec3f angles = test_matrix.get_euler(order_YXZ);

		check_float(angles.x, angle_x.to_radians());
		check_float(angles.y, angle_y.to_radians());
		check_float(angles.z, angle_z.to_radians());
	}
}
Exemplo n.º 25
0
 void test_mul_a_float() {
   Fixnum* one = Fixnum::from(13);
   Float* res = one->mul(state, Float::create(state, 1.4));
   check_float(res, Float::create(state, 18.2));
 }
Exemplo n.º 26
0
 void test_sub_a_float() {
   Fixnum* one = Fixnum::from(13);
   Float* res = one->sub(state, Float::create(state, 1.4));
   check_float(res, Float::create(state, 11.6));
 }