int main()
{
    const fix_point fp1(6.375f);
    const fix_point fp2 = -4.0f;

    // ----------------------------------------------------------
    // integral and fractional parts
    assert( floor(fp1) ==  6.f  );
    assert( fp1.frac() == .375f );

    assert( frac(fp1)  == .375f );
    assert( floor(fp2) == -4.f  );
    assert( fp2.frac() ==  0.f  );
    assert( frac(fp2)  ==  0.f  );

    // ----------------------------------------------------------
    // comparison and ordering
    assert( fp1 == fix_point(6.375) );
    assert( fp1 == 6.375f);
    assert( fp2 != fp1 );
    assert( fp2 < fp1  );
    assert( fp1 > fp2  );
    assert( fp2 <= fp1 );
    assert( fp1 >= fp2 );
    assert( fp1 <= fix_point(6.375) );
    assert( fp1 >= fix_point(6.375) );

    // ----------------------------------------------------------
    // arithmetics
    assert( fp1 + fp2 ==  2.375f   );
    assert( fp1 - fp2 ==  10.375f  );
    assert( fp1 * fp2 == -25.5f    );
    assert( fp1 / fp2 == -1.59375f );

    // ----------------------------------------------------------
    // arithmetics assignment
    fix_point
    fp3 = fp1;  fp3 += fp2;     assert( fp3 ==  2.375f   );
    fp3 = fp1;  fp3 -= fp2;     assert( fp3 ==  10.375f  );
    fp3 = fp1;  fp3 *= fp2;     assert( fp3 == -25.5f    );
    fp3 = fp1;  fp3 /= fp2;     assert( fp3 == -1.59375f );

    // ----------------------------------------------------------
    // pre/post - increment/decrement
    fp3 = fp1;  assert( ++fp3 ==  7.375f );
    fp3 = fp1;  assert( --fp3 ==  5.375f );
    fp3 = fp1;  assert( fp3++ ==  6.375f  );  assert( fp3 ==  7.375f  );
    fp3 = fp1;  assert( fp3-- ==  6.375f  );  assert( fp3 ==  5.375f  );

    // ----------------------------------------------------------
    // trigonometric functions
    assert( sin(fix_point(0.3f)) == fix_point(sin(0.3f)) );
    assert( cos(fix_point(0.5f)) == fix_point(cos(0.5f)) );

    // ----------------------------------------------------------
    // check some more numbers
    for ( float f = 0.f ; f <= 1.f ; f += 0.25f )   assert( fix_point(f) == f );
}
Exemplo n.º 2
0
/**
 * Sends frame 2 (every 1000ms):
 *   GPS course, latitude, longitude, ground speed, GPS altitude, remaining battery level
 */
void frsky_send_frame2(int uart)
{
	/* get a local copy of the global position data */
	struct vehicle_global_position_s global_pos;
	memset(&global_pos, 0, sizeof(global_pos));
	orb_copy(ORB_ID(vehicle_global_position), global_position_sub, &global_pos);

	/* get a local copy of the vehicle status data */
	struct vehicle_status_s vehicle_status;
	memset(&vehicle_status, 0, sizeof(vehicle_status));
	orb_copy(ORB_ID(vehicle_status), vehicle_status_sub, &vehicle_status);

	/* send formatted frame */
	float course = 0, lat = 0, lon = 0, speed = 0, alt = 0;
	char lat_ns = 0, lon_ew = 0;
	int sec = 0;
	if (global_pos.global_valid) {
		time_t time_gps = global_pos.time_gps_usec / 1000000;
		struct tm *tm_gps = gmtime(&time_gps);

		course = (global_pos.yaw + M_PI_F) / M_PI_F * 180.0f;
		lat    = frsky_format_gps(abs(global_pos.lat));
		lat_ns = (global_pos.lat < 0) ? 'S' : 'N';
		lon    = frsky_format_gps(abs(global_pos.lon));
		lon_ew = (global_pos.lon < 0) ? 'W' : 'E';
		speed  = sqrtf(global_pos.vel_n * global_pos.vel_n + global_pos.vel_e * global_pos.vel_e)
				* 25.0f / 46.0f;
		alt    = global_pos.alt;
		sec    = tm_gps->tm_sec;
	}

	frsky_send_data(uart, FRSKY_ID_GPS_COURS_BP, course);
	frsky_send_data(uart, FRSKY_ID_GPS_COURS_AP, frac(course) * 1000.0f);

	frsky_send_data(uart, FRSKY_ID_GPS_LAT_BP, lat);
	frsky_send_data(uart, FRSKY_ID_GPS_LAT_AP, frac(lat) * 10000.0f);
	frsky_send_data(uart, FRSKY_ID_GPS_LAT_NS, lat_ns);

	frsky_send_data(uart, FRSKY_ID_GPS_LONG_BP, lon);
	frsky_send_data(uart, FRSKY_ID_GPS_LONG_AP, frac(lon) * 10000.0f);
	frsky_send_data(uart, FRSKY_ID_GPS_LONG_EW, lon_ew);

	frsky_send_data(uart, FRSKY_ID_GPS_SPEED_BP, speed);
	frsky_send_data(uart, FRSKY_ID_GPS_SPEED_AP, frac(speed) * 100.0f);

	frsky_send_data(uart, FRSKY_ID_GPS_ALT_BP, alt);
	frsky_send_data(uart, FRSKY_ID_GPS_ALT_AP, frac(alt) * 100.0f);

	frsky_send_data(uart, FRSKY_ID_FUEL,
			roundf(vehicle_status.battery_remaining * 100.0f));

	frsky_send_data(uart, FRSKY_ID_GPS_SEC, sec);

	frsky_send_startstop(uart);
}
Exemplo n.º 3
0
ShGeneric<N, T> hashmrg(const ShGeneric<N, T>& p) {
  ShAttrib<N, SH_TEMP, T> result = frac(p * 0.01);
  ShGeneric<N, T> a = fillcast<N>(
      ShConstAttrib4f(M_PI * M_PI * M_PI * M_PI, std::exp(4.0), 
          std::pow(13.0, M_PI / 2.0), std::sqrt(1997.0)));

  for(int i = 0; i < MRG_REPS; ++i) {
    for(int j = 0; j < N; ++j) { 
      result(j) = frac(dot(result, a));
    }
  }
  return result;
}
Exemplo n.º 4
0
ShGeneric<N, T> hashlcg(const ShGeneric<N, T>& p) {
  ShAttrib<N, SH_TEMP, T> result = frac(p * 0.01);

  // TODO fix this for long tuples
  ShGeneric<N, T> a = fillcast<N>(
      ShConstAttrib4f(M_PI * M_PI * M_PI * M_PI, std::exp(4.0), 
          std::pow(13.0, M_PI / 2.0), std::sqrt(1997.0)));
  ShGeneric<N, T> m = fillcast<N>(
      ShConstAttrib4f(std::sqrt(2.0), 1.0 / M_PI, std::sqrt(3.0), 
          std::exp(-1.0)));

  for(int i = 0; i < LCG_REPS; ++i) result = frac(mad(result, a, m)); 
  return result;
}
Exemplo n.º 5
0
BOOL SingleSampler::NextSample( Point2* pOut, float* pSampleSz )
{
	if ( n ) return FALSE;
#ifdef CENTER_OF_PIXEL
	pOut->x = pOut->y = 0.5f;
#else
	*pOut = pSC->SurfacePtScreen();	// center of fragment
    pOut->x = frac( pOut->x ); pOut->y = frac( pOut->y );
#endif
	*pSampleSz = 1.0f;	// entire pixel

	++n;
	return TRUE;
}
Exemplo n.º 6
0
AColor plBMSampler::Sample(ShadeContext& sc, float u,float v) 
{
    AColor none(0.0f, 0.0f, 0.0f, 0.0f);

    if (!fInitialized)
        return none;

    BMM_Color_64 c;
    int x,y;
    float fu,fv;
    fu = frac(u);
    fv = 1.0f-frac(v);
    if (fData.fEnableCrop)
    {
        if (fData.fCropPlacement)
        {
            if (!PlaceUV(sc,fu, fv, int(u), int(v)))
                return AColor(0,0,0,0);
            x = (int)(fu*fbmw+0.5f);
            y = (int)(fv*fbmh+0.5f);
        }
        else
        {
            x = mod(clipx + (int)(fu*fclipw+0.5f),bmw);
            y = mod(clipy + (int)(fv*fcliph+0.5f),bmh);
        }
    }
    else
    {
        x = (int)(fu*fbmw+0.5f);
        y = (int)(fv*fbmh+0.5f);
    }
    fBM->GetLinearPixels(x,y,1,&c);
    switch(fData.fAlphaSource)
    {
    case plBMSamplerData::kDiscard:
        c.a = 0xffff; 
        break;
    case plBMSamplerData::kFromRGB:
        c.a = (c.r+c.g+c.b)/3; 
        break;
        //  TBD
        // XPCOL needs to be handled in bitmap for filtering. 
        // Need to open a bitmap with this property.
        //  case ALPHA_XPCOL:  break; 
    }
    return c;
}
Exemplo n.º 7
0
Fraction& Fraction::operator = (const float& f)
{
    Fraction frac(f);
    num = frac.num;
    den = frac.den;
    return *this;
}
Exemplo n.º 8
0
/**
 * Sends frame 1 (every 200ms):
 *   acceleration values, barometer altitude, temperature, battery voltage & current
 */
void frsky_send_frame1(int uart)
{
	/* get a local copy of the current sensor values */
	struct sensor_combined_s raw;
	memset(&raw, 0, sizeof(raw));
	orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw);

	/* get a local copy of the battery data */
	struct battery_status_s battery;
	memset(&battery, 0, sizeof(battery));
	orb_copy(ORB_ID(battery_status), battery_sub, &battery);

	/* send formatted frame */
	frsky_send_data(uart, FRSKY_ID_ACCEL_X,
			roundf(raw.accelerometer_m_s2[0] * 1000.0f));
	frsky_send_data(uart, FRSKY_ID_ACCEL_Y,
			roundf(raw.accelerometer_m_s2[1] * 1000.0f));
	frsky_send_data(uart, FRSKY_ID_ACCEL_Z,
			roundf(raw.accelerometer_m_s2[2] * 1000.0f));

	frsky_send_data(uart, FRSKY_ID_BARO_ALT_BP,
			raw.baro_alt_meter);
	frsky_send_data(uart, FRSKY_ID_BARO_ALT_AP,
			roundf(frac(raw.baro_alt_meter) * 100.0f));

	frsky_send_data(uart, FRSKY_ID_TEMP1,
			roundf(raw.baro_temp_celcius));

	frsky_send_data(uart, FRSKY_ID_VFAS,
			roundf(battery.voltage_v * 10.0f));
	frsky_send_data(uart, FRSKY_ID_CURRENT,
			(battery.current_a < 0) ? 0 : roundf(battery.current_a * 10.0f));

	frsky_send_startstop(uart);
}
Exemplo n.º 9
0
/**
 * Sends frame 1 (every 200ms):
 *   acceleration values, barometer altitude, temperature, battery voltage & current
 */
void frsky_send_frame1(int uart)
{
	/* send formatted frame */
	frsky_send_data(uart, FRSKY_ID_ACCEL_X,
			roundf(sensor_combined->accelerometer_m_s2[0] * 1000.0f));
	frsky_send_data(uart, FRSKY_ID_ACCEL_Y,
			roundf(sensor_combined->accelerometer_m_s2[1] * 1000.0f));
	frsky_send_data(uart, FRSKY_ID_ACCEL_Z,
			roundf(sensor_combined->accelerometer_m_s2[2] * 1000.0f));

	frsky_send_data(uart, FRSKY_ID_BARO_ALT_BP,
			sensor_combined->baro_alt_meter[0]);
	frsky_send_data(uart, FRSKY_ID_BARO_ALT_AP,
			roundf(frac(sensor_combined->baro_alt_meter[0]) * 100.0f));

	frsky_send_data(uart, FRSKY_ID_TEMP1,
			roundf(sensor_combined->baro_temp_celcius[0]));

	frsky_send_data(uart, FRSKY_ID_VFAS,
			roundf(battery_status->voltage_v * 10.0f));
	frsky_send_data(uart, FRSKY_ID_CURRENT,
			(battery_status->current_a < 0) ? 0 : roundf(battery_status->current_a * 10.0f));

	frsky_send_startstop(uart);
}
Exemplo n.º 10
0
// RAMC, zu der der Ekliptikpunkt der Länge l die mund. Pos. m erhält
double t_placidus(  double m, double ee, double l, double phi ) {
  double ascdiff,ra,d,a;
  ekq( ee, l, 0., &ra, &d);
  ascdiff = ad(d,phi);
  a = (m < 180) ? ((m - 90.)/90.) : ((m-270.)/90.);  
  return frac(ra-(m+a*ascdiff-270.),360.);
  }
Exemplo n.º 11
0
/**
 * Sends frame 2 (every 1000ms):
 *   GPS course, latitude, longitude, ground speed, GPS altitude, remaining battery level
 */
void frsky_send_frame2(int uart)
{
	/* send formatted frame */
	float course = 0, lat = 0, lon = 0, speed = 0, alt = 0;
	char lat_ns = 0, lon_ew = 0;
	int sec = 0;

	if (global_pos->timestamp != 0 && hrt_absolute_time() < global_pos->timestamp + 20000) {
		time_t time_gps = global_pos->time_utc_usec / 1000000ULL;
		struct tm *tm_gps = gmtime(&time_gps);

		course = (global_pos->yaw + M_PI_F) / M_PI_F * 180.0f;
		lat    = frsky_format_gps(fabsf(global_pos->lat));
		lat_ns = (global_pos->lat < 0) ? 'S' : 'N';
		lon    = frsky_format_gps(fabsf(global_pos->lon));
		lon_ew = (global_pos->lon < 0) ? 'W' : 'E';
		speed  = sqrtf(global_pos->vel_n * global_pos->vel_n + global_pos->vel_e * global_pos->vel_e)
			 * 25.0f / 46.0f;
		alt    = global_pos->alt;
		sec    = tm_gps->tm_sec;
	}

	frsky_send_data(uart, FRSKY_ID_GPS_COURS_BP, course);
	frsky_send_data(uart, FRSKY_ID_GPS_COURS_AP, frac(course) * 1000.0f);

	frsky_send_data(uart, FRSKY_ID_GPS_LAT_BP, lat);
	frsky_send_data(uart, FRSKY_ID_GPS_LAT_AP, frac(lat) * 10000.0f);
	frsky_send_data(uart, FRSKY_ID_GPS_LAT_NS, lat_ns);

	frsky_send_data(uart, FRSKY_ID_GPS_LONG_BP, lon);
	frsky_send_data(uart, FRSKY_ID_GPS_LONG_AP, frac(lon) * 10000.0f);
	frsky_send_data(uart, FRSKY_ID_GPS_LONG_EW, lon_ew);

	frsky_send_data(uart, FRSKY_ID_GPS_SPEED_BP, speed);
	frsky_send_data(uart, FRSKY_ID_GPS_SPEED_AP, frac(speed) * 100.0f);

	frsky_send_data(uart, FRSKY_ID_GPS_ALT_BP, alt);
	frsky_send_data(uart, FRSKY_ID_GPS_ALT_AP, frac(alt) * 100.0f);

	frsky_send_data(uart, FRSKY_ID_FUEL,
			roundf(battery_status->remaining * 100.0f));

	frsky_send_data(uart, FRSKY_ID_GPS_SEC, sec);

	frsky_send_startstop(uart);
}
size_t map_count_to_color_historic(int cnt, int num_colors,
                                   const std::vector<int>& distribution,
                                   size_t total_pixles, double P, double Q) {
  auto u = static_cast<double>(distribution[cnt]) /
             static_cast<double>(total_pixles);
  u = frac(u * P + Q); // FRAC substracts the int part from the number
  return static_cast<size_t>(u * static_cast<double>(num_colors));
}
Exemplo n.º 13
0
float interpolated_noise(float x, float y)
{
	int x_ = floor_i(x);
	int y_ = floor_i(y);
	
	float frac_x = frac(x);
	float frac_y = frac(y);
	
	float v1 = smooth_noise_2D(x_, y_);
	float v2 = smooth_noise_2D(x_ + 1, y_);
	float v3 = smooth_noise_2D(x_, y_ + 1);
	float v4 = smooth_noise_2D(x_ + 1, y_ + 1);
	
	float i1 = cos_interp(v1, v2, frac_x);
	float i2 = cos_interp(v3, v4, frac_x);
	
	return cos_interp(i1, i2, frac_y);
}
Exemplo n.º 14
0
void update_fixed_wing_sprite_light_timers (void)
{
	sprite_light_timer += (get_delta_time () * SPRITE_LIGHT_TIMER_FREQUENCY);

	if (sprite_light_timer >= 1.0)
	{
		sprite_light_timer = frac (sprite_light_timer);
	}
}
Exemplo n.º 15
0
int main(int argc, char *argv[]) {
  Fraction frac(8);
  Fraction frac2 = 5;
  frac = 9;
  frac = (Fraction) 7;
  frac = Fraction(6);
  frac = static_cast<Fraction>(6);
  frac = frac2.times(19);
  return 0;
}
Exemplo n.º 16
0
int benchmark()
{
  double error = 1.0e-10;
  int n,d,i;

  for(i = 0; i < 10; ++i)
    frac(nums[i], &n, &d, error);

  return n;
}
Exemplo n.º 17
0
float noise(float x,float y,float z,int d)
{
  int x0,x1,x2,x3;
  int y0,y1,y2,y3;
  int z0,z1,z2,z3;
  float ox,oy,oz;
  float v0,v1,v2,v3;

  x+=1500; y+=1500; z+=1500;

  ox=frac(x); oy=frac(y); oz=frac(z);

  x0=((int)x+0)%MAX_NOISE;
  x1=((int)x+1)%MAX_NOISE;
  x2=((int)x+2)%MAX_NOISE;
  x3=((int)x+3)%MAX_NOISE;
  y0=((int)y+0)%MAX_NOISE;
  y1=((int)y+1)%MAX_NOISE;
  y2=((int)y+2)%MAX_NOISE;
  y3=((int)y+3)%MAX_NOISE;
  z0=((int)z+0)%MAX_NOISE;
  z1=((int)z+1)%MAX_NOISE;
  z2=((int)z+2)%MAX_NOISE;
  z3=((int)z+3)%MAX_NOISE;

  v0=Interpolate2D(noise_t[x0][y0][z0][d],noise_t[x1][y0][z0][d],noise_t[x2][y0][z0][d],noise_t[x3][y0][z0][d],
                   noise_t[x0][y1][z0][d],noise_t[x1][y1][z0][d],noise_t[x2][y1][z0][d],noise_t[x3][y1][z0][d],
                   noise_t[x0][y2][z0][d],noise_t[x1][y2][z0][d],noise_t[x2][y2][z0][d],noise_t[x3][y2][z0][d],
                   noise_t[x0][y3][z0][d],noise_t[x1][y3][z0][d],noise_t[x2][y3][z0][d],noise_t[x3][y3][z0][d],ox,oy);
  v1=Interpolate2D(noise_t[x0][y0][z1][d],noise_t[x1][y0][z1][d],noise_t[x2][y0][z1][d],noise_t[x3][y0][z1][d],
                   noise_t[x0][y1][z1][d],noise_t[x1][y1][z1][d],noise_t[x2][y1][z1][d],noise_t[x3][y1][z1][d],
                   noise_t[x0][y2][z1][d],noise_t[x1][y2][z1][d],noise_t[x2][y2][z1][d],noise_t[x3][y2][z1][d],
                   noise_t[x0][y3][z1][d],noise_t[x1][y3][z1][d],noise_t[x2][y3][z1][d],noise_t[x3][y3][z1][d],ox,oy);
  v2=Interpolate2D(noise_t[x0][y0][z2][d],noise_t[x1][y0][z2][d],noise_t[x2][y0][z2][d],noise_t[x3][y0][z2][d],
                   noise_t[x0][y1][z2][d],noise_t[x1][y1][z2][d],noise_t[x2][y1][z2][d],noise_t[x3][y1][z2][d],
                   noise_t[x0][y2][z2][d],noise_t[x1][y2][z2][d],noise_t[x2][y2][z2][d],noise_t[x3][y2][z2][d],
                   noise_t[x0][y3][z2][d],noise_t[x1][y3][z2][d],noise_t[x2][y3][z2][d],noise_t[x3][y3][z2][d],ox,oy);
  v3=Interpolate2D(noise_t[x0][y0][z3][d],noise_t[x1][y0][z3][d],noise_t[x2][y0][z3][d],noise_t[x3][y0][z3][d],
                   noise_t[x0][y1][z3][d],noise_t[x1][y1][z3][d],noise_t[x2][y1][z3][d],noise_t[x3][y1][z3][d],
                   noise_t[x0][y2][z3][d],noise_t[x1][y2][z3][d],noise_t[x2][y2][z3][d],noise_t[x3][y2][z3][d],
                   noise_t[x0][y3][z3][d],noise_t[x1][y3][z3][d],noise_t[x2][y3][z3][d],noise_t[x3][y3][z3][d],ox,oy);
  return Interpolate1D(v0,v1,v2,v3,oz);
}
Exemplo n.º 18
0
ColorRGB color_field(Point2D point)
{
	ColorRGB colors[] = {
		rgb(0, 0, 64),
		rgb(128, 0, 128),
		rgb(128, 0, 255),
		rgb(128, 64, 255),
		rgb(64, 64, 255),
		rgb(0, 128, 255),
		rgb(0, 192, 255),
		rgb(0, 255, 255),
		rgb(0, 255, 128),
		rgb(0, 255, 64),
		rgb(64, 255, 64),
		rgb(64, 255, 0),
		rgb(128, 255, 0),
		rgb(255, 255, 0),
		rgb(255, 128, 0),
		rgb(128, 0, 0),
		rgb(255, 0, 0),
		rgb(255, 64, 64),
		rgb(255, 128, 128),
		rgb(255, 192, 192),
		rgb(255, 255, 255)
	};
	
	float color_percent = Perlin2D(point.x, point.y, 0.5, 10);
	
	if(color_percent < 0) {
		color_percent = 0.0f;
	}
	
	if(color_percent > 1) {
		color_percent = 1.0f;
	}
	
	color_percent *= ((sizeof(colors) / sizeof(colors[0])) - 1);
	
	int rounded = round_i(color_percent);
	float alpha = frac(color_percent);
	
	int bg, fg;
	
	if(alpha > 0.5) {
		bg = rounded - 1;
		fg = rounded;
		alpha = 1.0f - alpha;
	} else {
		bg = rounded;
		fg = rounded + 1;
	}
	
	return blend(colors[bg], colors[fg], alpha);
}
Exemplo n.º 19
0
// RAMC, zu der der Ekliptikpunkt der Länge l die mund. Pos. m erhält
double t_koch(  double m, double ee, double l, double phi ) {
  int ostpunkt,i;
  double admc,t,t0,ascdiff,ra,d,a,_oa;
  m = frac(m,360.); // Wert auf 0-360 reduzieren
  ostpunkt = (fabs(ArcDiff(m,0))<90.); 
  ekq( ee, l, 0., &ra, &d);
// Hilfsfaktor a  
  a = ostpunkt ? (m/90.) : (m/90.-2.);
// Für Ostpunkte OA, für Westpunkte OD berechnen  
  _oa = oa( ra, d, (ostpunkt ? phi : -phi) );
// Iterativ Formel (58) auflösen
  t0 = frac( (_oa - 90 - m), 360. );
  for (i = 0; i<1000; i++) {
    admc = asn(t1(ee)*t1(phi)*s1(t0));
    t =  frac( (_oa - 90 - m - a*admc), 360. ); 
    if (ArcDiff(t,t0)<PREC) break;
    t0 = frac(t,360.);
    }      
  return frac(t,360.);
  }
Exemplo n.º 20
0
// Return folded fractional coordinate (i.e. inside current Box)
Vec3<double> OrthorhombicBox::foldFrac(const Vec3<double>& r) const
{
	// Convert coordinate to fractional coords
	Vec3<double> frac(r.x*ra_, r.y*rb_, r.z*rc_);
	
	// Fold into Box and divide by integer Cell sizes
	frac.x -= floor(frac.x);
	frac.y -= floor(frac.y);
	frac.z -= floor(frac.z);
	return frac;
}
Exemplo n.º 21
0
/**
* @brief Perform a single source of the BC calculation per Brandes.
*
* Note that this follows the approach suggested by Green and Bader in which
* parent lists are not maintained, but instead the neighbors are searched
* to rediscover parents.
*
* Note also that found count will not include the source and that increments
* to this array are handled atomically.
*
* Operations to the bc array are NOT ATOMIC
*
* @param S The STINGER graph
* @param nv The maximum vertex ID in the graph plus one.
* @param source The vertex from where this search will start.
* @param bc The array into which the partial BCs will be added.
* @param found_count  An array to track how many times a vertex is found for normalization.
*/
void
single_bc_search(stinger_t * S, int64_t nv, int64_t source, double * bc, int64_t * found_count)
{
  int64_t * paths = (int64_t * )xcalloc(nv * 2, sizeof(int64_t));
  int64_t * q = paths + nv;
  double * partial = (double *)xcalloc(nv, sizeof(double));

  int64_t * d = (int64_t *)xmalloc(nv * sizeof(int64_t));
  for(int64_t i = 0; i < nv; i ++) d[i] = -1;

  int64_t q_front = 1;
  int64_t q_rear = 0;
  q[0] = source;
  d[source] = 0;
  paths[source] = 1;

  while(q_rear != q_front) {
    int64_t v = q[q_rear++];
    int64_t d_next = d[v] + 1;

    STINGER_FORALL_EDGES_OF_VTX_BEGIN(S, v) {

      if(d[STINGER_EDGE_DEST] < 0) {
	d[STINGER_EDGE_DEST]     = d_next;
	paths[STINGER_EDGE_DEST] = paths[v];
	q[q_front++]             = STINGER_EDGE_DEST;

	stinger_int64_fetch_add(found_count + STINGER_EDGE_DEST, 1);
      }

      else if(d[STINGER_EDGE_DEST] == d_next) {
	paths[STINGER_EDGE_DEST] += paths[v];
      }

    } STINGER_FORALL_EDGES_OF_VTX_END();
  }

  /* don't process source */
  while(q_front > 1) {
    int64_t w = q[--q_front];

    /* don't maintain parents, do search instead */
    STINGER_FORALL_EDGES_OF_VTX_BEGIN(S, w) {
      if(d[STINGER_EDGE_DEST] == (d[w] - 1)) {
	partial[STINGER_EDGE_DEST] += frac(paths[STINGER_EDGE_DEST],paths[w]) * (1 + partial[w]);
      }
    } STINGER_FORALL_EDGES_OF_VTX_END();
    bc[w] += partial[w];
  }

  free(d);
  free(partial);
  free(paths);
}
Exemplo n.º 22
0
inline Vec2i nearest_coords(const Texture2D *self, const Vec2f p)
{
  // repeat: get remainder within [0..1] parameter space
  Vec2f tc = frac(p);
  tc = max(tc, Vec2f(0.0f)); // filter out inf/NaN

  // scale by texture size
  tc = tc * self->sizef;

  // nearest
  return Vec2i(tc);
}
Exemplo n.º 23
0
int frac_out0 (double x)
{   long n,d;
	if (x==0.0) output1hold(-1,"0");
	else
	{	if (frac(fabs(x),&n,&d,fraceps)<0) return 0;
		if (x<0) output1hold(-1,"-");
		else output1hold(-1,"");
		if (d>1) output1hold(-1,"%ld/%ld",n,d);
		else output1hold(-1,"%ld",n);
	}
	return 1;
}
size_t map_count_to_color(int cnt, int min, int max, int num_colors,
                          double P, double Q) {
  auto cnt_d = static_cast<double>(cnt);
  auto min_d = static_cast<double>(min);
  auto max_d = static_cast<double>(max);
//  auto u = (cnt_d - min_d) / (max_d - min_d);                         // linear
//  auto u = (sqrt(cnt_d) - sqrt(min_d)) / (sqrt(max_d) - sqrt(min_d)); // sqrt
  auto u = (cbrt(cnt_d) - cbrt(min_d)) / (cbrt(max_d) - cbrt(min_d)); // cbrt
//  auto u = (log(cnt_d) - log(min_d)) / (log(max_d) - log(min_d));     // log
//  auto u = (log(cnt_d / min_d)) / (log(max_d / min_d));               // log
  u = frac(u * P + Q);
  return static_cast<size_t>(u * static_cast<double>(num_colors));
}
Exemplo n.º 25
0
double SinH(int year, int month, int day, double UT){

    double	TU0, TU, TU2, TU3, LambdaMoon, BetaMoon, R, AGE, frac(), jd();
    double	RA_Sun, DEC_Sun, T0, gmst, lmst, Tau, epsilon;
    double	M, DL, L, SL, X, Y, Z, RHO;
    

    TU0 = (jd(year, month, day, 0.0) - 2451545.0)/36525.0;

    TU = (jd(year, month, day, UT+62.0/3600.0) - 2451545.0)/36525.0;
    TU2 = TU*TU;
    TU3 = TU2*TU;

    M = P2*frac(0.993133 + 99.997361*TU);
    DL = 6893.0*sin(M) + 72.0*sin(2.0*M);
    L = P2*frac(0.7859453 + M/P2 + (6191.2*TU+DL)/1296e3);
    SL = sin(L);
    X = cos(L); Y = cosEPS*SL; Z = sinEPS*SL; RHO = sqrt(1.0-Z*Z);
    DEC_Sun = atan2(Z, RHO);
    RA_Sun = (48.0/P2)*atan(Y/(X+RHO));
    if (RA_Sun < 0) RA_Sun += 24.0;

    RA_Sun = RA_Sun*15.0*RadPerDeg;

    /*
     *  Compute Greenwich Mean Sidereal Time (gmst)
     */
    UT = 24.0*frac( UT/24.0 );
/*
    gmst = 6.697374558 + 1.0027379093*UT + (8640184.812866*TU0 +(0.093104-6.2e-6*TU)*TU2)/3600.0;
*/
    gmst = 6.697374558 + 1.0*UT + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0;
    lmst = 24.0*frac( (gmst-Glon/15.0) / 24.0 );

    Tau = 15.0*lmst*RadPerDeg - RA_Sun;
    return( SinGlat*sin(DEC_Sun) + CosGlat*cos(DEC_Sun)*cos(Tau) );


}
Exemplo n.º 26
0
int main(){
	float num, fra;
	int inteiro;

	printf("Insira o numero\n");
	scanf("%f", &num);
	
	frac(num, &inteiro, &fra);
	
	printf("Parte inteira: %d, parte fracionaria: %f\n", inteiro, fra);
	
	return 1;
}
Exemplo n.º 27
0
const char *doubleexp(RooWorkspace *wspace, RooRealVar &x,std::string ext = ""){ 
   // Double exponential model
   RooRealVar frac(Form("f_%s",ext.c_str()),"f",0.9,0.,1.);
   RooRealVar m1(Form("m1_%s",ext.c_str()),"m1",-0.02,-0.2,0.);
   RooRealVar m2(Form("m2_%s",ext.c_str()),"m2",-0.01,-0.2,0.);

   RooExponential exp1(Form("exp1_%s",ext.c_str()),Form("exp1_%s",ext.c_str()),x,m1);
   RooExponential exp2(Form("exp2_%s",ext.c_str()),Form("exp2_%s",ext.c_str()),x,m2);

   RooAddPdf *sumexp = new RooAddPdf(Form("doubleExponential_%s",ext.c_str()), Form("doubleExponential_%s",ext.c_str()),RooArgList(exp1,exp2),RooArgList(frac));
   wspace->import(*sumexp);
   return sumexp->GetName(); 
}
Exemplo n.º 28
0
double SinH(int year, int month, int day, double UT) {

    double	TU, frac(), jd();
    double	RA_Moon, DEC_Moon, gmst, lmst, Tau, Moon();
    double	angle2pi();

    TU = (jd(year, month, day, UT) - 2451545.0)/36525.0;

    /* this is more accurate, but wasteful for this -- use low res approx.
    TU2 = TU*TU;
    TU3 = TU2*TU;
    Moon(TU, &LambdaMoon, &BetaMoon, &R, &AGE);
    LambdaMoon *= RadPerDeg;
    BetaMoon *= RadPerDeg;
    epsilon = (23.43929167 - 0.013004166*TU - 1.6666667e-7*TU2 - 5.0277777778e-7*TU3)*RadPerDeg;
    RA_Moon  = angle2pi(atan2(sin(LambdaMoon)*cos(epsilon)-tan(BetaMoon)*sin(epsilon), cos(LambdaMoon)));
    DEC_Moon = asin( sin(BetaMoon)*cos(epsilon) + cos(BetaMoon)*sin(epsilon)*sin(LambdaMoon));
    */

    MiniMoon(TU, &RA_Moon, &DEC_Moon);
    RA_Moon *= 15.0*RadPerDeg;
    DEC_Moon *= RadPerDeg;

    /*
     *  Compute Greenwich Mean Sidereal Time (gmst)
     */
    UT = 24.0*frac( UT/24.0 );
    /* this is for the ephemeris meridian???
    gmst = 6.697374558 + 1.0027379093*UT + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0;
    */
    gmst = UT + 6.697374558 + (8640184.812866+(0.093104-6.2e-6*TU)*TU)*TU/3600.0;
    lmst = 24.0*frac( (gmst-Glon/15.0) / 24.0 );

    Tau = 15.0*lmst*RadPerDeg - RA_Moon;
    return( SinGlat*sin(DEC_Moon) + CosGlat*cos(DEC_Moon)*cos(Tau) );


}
Exemplo n.º 29
0
float4 __CGsampler_state::minify(int ndx, float4 strq, float1 lod)
{
    assert(lod > 0);  // Otherwise should be in minify
    switch (minFilter) {
    default:
        assert(!"unexpected minification filter");
    case GL_NEAREST:
        return nearestFilter(trueBaseLevel, strq);
    case GL_NEAREST_MIPMAP_NEAREST:
        {
            int level = clamp(int1(trueBaseLevel + round(lod)), trueBaseLevel, effectiveMaxLevel);
            return nearestFilter(level, strq);
        }
    case GL_LINEAR_MIPMAP_NEAREST:
        {
            int level = clamp(int1(trueBaseLevel + round(lod)), trueBaseLevel, effectiveMaxLevel);
            return linearFilter(level, strq);
        }
    case GL_NEAREST_MIPMAP_LINEAR:
        {
            int level0 = max(trueBaseLevel + int(floor(lod)), effectiveMaxLevel);
            int level1 = max(level0 + 1, effectiveMaxLevel);
            float4 tex0 = nearestFilter(level0, strq);
            float4 tex1 = nearestFilter(level1, strq);
            return lerp(tex0, tex1, frac(lod));
        }
    case GL_LINEAR_MIPMAP_LINEAR:
        {
            int level0 = max(trueBaseLevel + int(floor(lod)), effectiveMaxLevel);
            int level1 = max(level0 + 1, effectiveMaxLevel);
            float4 tex0 = linearFilter(level0, strq);
            float4 tex1 = linearFilter(level1, strq);
            return lerp(tex0, tex1, frac(lod));
        }
    case GL_LINEAR:
        return linearFilter(trueBaseLevel, strq);
    }
}
Exemplo n.º 30
-2
Arquivo: draw.c Projeto: ushmal/ugl
void line(struct fb *dst, int x0, int y0, int x1, int y1, int cl)
{
	int len;
	fixed x, y, dx, dy;

	len = imax(iabs(x1 - x0), iabs(y1 - y0));
	if(!len) {
		putpixel(dst, x0, y0, cl);
		return;
	}
	x = itofix(x0);
	y = itofix(y0);
	dx = frac(x1 - x0, len);
	dy = frac(y1 - y0, len);

	for(; len >= 0; len--) {
		putpixel(dst, fixtoi(x), fixtoi(y), cl);
		x += dx;
		y += dy;
	}
}