コード例 #1
0
ファイル: scat.c プロジェクト: npe9/harvey
int
loadngc(int32_t index)
{
    static int failed;
    int32_t j;

    ngcopen();
    j = (index-1)*sizeof(NGCrec);
    grow();
    cur->type = NGC;
    cur->index = index;
    seek(ngcdb, j, 0);
    /* special case: NGC data may not be available */
    if(read(ngcdb, &cur->ngc, sizeof(NGCrec)) != sizeof(NGCrec)) {
        if(!failed) {
            fprint(2, "scat: NGC database not available\n");
            failed++;
        }
        cur->type = NONGC;
        cur->ngc.ngc = 0;
        cur->ngc.ra = 0;
        cur->ngc.dec = 0;
        cur->ngc.diam = 0;
        cur->ngc.mag = 0;
        return 0;
    }
    cur->ngc.ngc = Short(&cur->ngc.ngc);
    cur->ngc.ra = Long(&cur->ngc.ra);
    cur->ngc.dec = Long(&cur->ngc.dec);
    cur->ngc.diam = Long(&cur->ngc.diam);
    cur->ngc.mag = Short(&cur->ngc.mag);
    return 1;
}
コード例 #2
0
ファイル: DoubleTest.cpp プロジェクト: itsubaki/viola
int main() {
	int ret = 0;

	_Double d1 = std::make_shared<Double>(1.2);
	_Double d2 = std::make_shared<Double>(3.4);

	System::out::println("d1.class: " + d1->getClassName());
	System::out::println("d1.long: " + Long(d1->doubleToLongBits()).toString());
	System::out::println("d2.long: " + Long(d2->doubleToLongBits()).toString());
	System::out::println("d1.hash: " + Integer(d1->hashCode()).toString());
	System::out::println("d2.hash: " + Integer(d2->hashCode()).toString());

	Double* d3 = new Double(1.2);
	Object* d4 = new Double(1.2);
	ret = ret + !d1.get()->equals(1.2);
	ret = ret + !d1.get()->equals(d3);
	ret = ret + !d1.get()->equals(d1);
	ret = ret + !d1.get()->equals(d4);
	delete d3;
	delete d4;

	ret = ret + Assert::assertEquals(d1, d1);
	ret = ret + !Assert::assertEquals(d1, d2);

	return ret;
}
コード例 #3
0
ファイル: scat.c プロジェクト: npe9/harvey
int
loadabell(int32_t index)
{
    int32_t j;

    abellopen();
    j = index-1;
    grow();
    cur->type = Abell;
    cur->index = index;
    seek(abelldb, j*sizeof(Abellrec), 0);
    Eread(abelldb, "abell", &cur->abell, sizeof(Abellrec));
    cur->abell.abell = Short(&cur->abell.abell);
    if(cur->abell.abell != index) {
        fprint(2, "bad format in abell catalog\n");
        exits("abell");
    }
    cur->abell.ra = Long(&cur->abell.ra);
    cur->abell.dec = Long(&cur->abell.dec);
    cur->abell.glat = Long(&cur->abell.glat);
    cur->abell.glong = Long(&cur->abell.glong);
    cur->abell.rad = Long(&cur->abell.rad);
    cur->abell.mag10 = Short(&cur->abell.mag10);
    cur->abell.pop = Short(&cur->abell.pop);
    cur->abell.dist = Short(&cur->abell.dist);
    return 1;
}
コード例 #4
0
/*
 * adfGetCacheEntry
 *
 * Returns a cache entry, starting from the offset p (the index into records[])
 * This offset is updated to the end of the returned entry.
 */
void adfGetCacheEntry(struct bDirCacheBlock *dirc, int *p, struct CacheEntry *cEntry)
{
    int ptr;

    ptr = *p;

/*printf("p=%d\n",ptr);*/

#ifdef LITT_ENDIAN
    cEntry->header = swapLong(dirc->records+ptr);
    cEntry->size = swapLong(dirc->records+ptr+4);
    cEntry->protect = swapLong(dirc->records+ptr+8);
    cEntry->days = swapShort(dirc->records+ptr+16);
    cEntry->mins = swapShort(dirc->records+ptr+18);
    cEntry->ticks = swapShort(dirc->records+ptr+20);
#else
    cEntry->header = Long(dirc->records+ptr);
    cEntry->size = Long(dirc->records+ptr+4);
    cEntry->protect = Long(dirc->records+ptr+8);
    cEntry->days = Short(dirc->records+ptr+16);
    cEntry->mins = Short(dirc->records+ptr+18);
    cEntry->ticks = Short(dirc->records+ptr+20);
#endif
    cEntry->type =(signed char) dirc->records[ptr+22];

    cEntry->nLen = dirc->records[ptr+23];
/*    cEntry->name = (char*)calloc(1,sizeof(char)*(cEntry->nLen+1));
    if (!cEntry->name)
         return;
*/    memcpy(cEntry->name, dirc->records+ptr+24, cEntry->nLen);
    cEntry->name[(int)(cEntry->nLen)]='\0';

    cEntry->cLen = dirc->records[ptr+24+cEntry->nLen];
    if (cEntry->cLen>0) {
/*        cEntry->comm =(char*)calloc(1,sizeof(char)*(cEntry->cLen+1));
        if (!cEntry->comm) {
            free( cEntry->name ); cEntry->name=NULL;
            return;
        }
*/        memcpy(cEntry->comm,dirc->records+ptr+24+cEntry->nLen+1,cEntry->cLen);
    }
        cEntry->comm[(int)(cEntry->cLen)]='\0';
/*printf("cEntry->nLen %d cEntry->cLen %d %s\n",cEntry->nLen,cEntry->cLen,cEntry->name);*/
    *p  = ptr+24+cEntry->nLen+1+cEntry->cLen;

    /* the starting offset of each record must be even (68000 constraint) */ 
    if ((*p%2)!=0)
        *p=(*p)+1;
}
コード例 #5
0
void UnitSphereDistribution::operator () (double &x, double &y, double &z) 
{ 
  for (;;) {
    double d1 = 1.0 - scale * Long(),
           d2 = 1.0 - scale * Long(),
           dd = d1 * d1 + d2 * d2;
    if (dd < 1.0) { 
      z = 1 - 2 * dd;
      dd = 2 * sqrt(1.0-dd);
      x = d1 * dd;
      y = d2 * dd;
      return;
    }
  }
}
コード例 #6
0
xyz geolocation::toxyz() const
{
    // Approach developed by:
    //
    // (Olson, D.K. (1996).
    // "Converting earth-Centered, Earth-Fixed Coordinates to Geodetic Coordinates,"
    // IEEE Transactions on Aerospace and Electronic Systems, Vol. 32, No. 1, January 1996, pp. 473 - 476).
    //
    //
    // Java implementation:
    //
    // D. Rose (2014).
    // "Converting between Earth-Centered, Earth Fixed and Geodetic Coordinates"
    //

    //Convert Lat, Lon, Altitude to Earth-Centered-Earth-Fixed (ECEF)
    //Input is a three element array containing lat, lon (rads) and alt (m)
    //Returned array contains x, y, z in meters
    static const double  a = 6378137.0;                  //WGS-84 semi-major axis
    static const double e2 = 6.6943799901377997e-3;      //WGS-84 first eccentricity squared

    double lat = degreestoradians(Lat());
    double lon = degreestoradians(Long());
    double alt = Alt();
    double n = a / sqrt(1 - e2*sin(lat)*sin(lat));
    double dx = ((n + alt)*cos(lat)*cos(lon));           //ECEF x
    double dy = ((n + alt)*cos(lat)*sin(lon));           //ECEF y
    double dz = ((n*(1 - e2) + alt)*sin(lat));           //ECEF z
    return(xyz(dx, dy, dz));                             //Return x, y, z in ECEF
}
コード例 #7
0
ファイル: ran055.cpp プロジェクト: lucafuji/Gene-Correlation
Ran055::Ran055 (unsigned long the_seed) : RandomGenerator(the_seed)
{
    int i, ii;
    long j, k;

    // requires at least 32 bit arithmetics
    assert( sizeof(unsigned long) >= 4 );

    max_val = MAX;	// initialize the maximum value max_val

    // initialize table

    s55[0] = j = seed^MASK ;	// XORing with MASK allows use of zero
				// and other simple bit patterns for idum.
    k = 1;  
    for (i = 1; i < 55; i++) {
	ii = (21 * i) % 55;
	s55[ii] = k;
	k = j - k;
	j = s55[ii] ;
    }

    j55 = 0;			// invariance (b-a-24)%55 = 0
    k55 = 24;

    for (i = 0; i < 165; i++) Long();  // warm up table three times
}
コード例 #8
0
ファイル: BaseVal.cpp プロジェクト: dakyri/qua
TypedValue	&
TypedValue::operator ! ()
{
	if (type == S_FLOAT) {
		return Int((int32)(! FloatValue(nullptr)));
	}
	if (type == S_LONG)
		return Long((int64)(! LongValue(nullptr)));
	return Int((int32)(! IntValue(nullptr)));
}
コード例 #9
0
ファイル: BaseVal.cpp プロジェクト: dakyri/qua
TypedValue	&
TypedValue::operator - ()
{
	if (type == S_FLOAT) {
		return Float( - FloatValue(nullptr));
	}
	if (type == S_LONG)
		return Long((int64)(- LongValue(nullptr)));
	return Int(- IntValue(nullptr));
}
コード例 #10
0
ファイル: BaseVal.cpp プロジェクト: dakyri/qua
TypedValue	&
TypedValue::operator / (TypedValue &t2)
{
	if (type == S_FLOAT || t2.type == S_FLOAT) {
		return Float( FloatValue(nullptr) / t2.FloatValue(nullptr));
	}
	if (type == S_LONG || t2.type == S_LONG)
		return Long((int64)(LongValue(nullptr) / t2.LongValue(nullptr)));
	return Int( IntValue(nullptr) / t2.IntValue(nullptr));
}
コード例 #11
0
ファイル: BaseVal.cpp プロジェクト: dakyri/qua
TypedValue	&
TypedValue::operator ~ ()
{
	if (type == S_FLOAT) {
		internalError("dodgy bitwise operand");
		return Int((int32)-1);
	}
	if (type == S_LONG)
		return Long((int64)(~ LongValue(nullptr)));
	return Int(~ IntValue(nullptr));
}
コード例 #12
0
ファイル: BaseVal.cpp プロジェクト: dakyri/qua
TypedValue	&
TypedValue::operator % (TypedValue &t2)
{
	if (type == S_FLOAT || t2.type == S_FLOAT) {
		internalError("Dodgy mod: float to float");
		return Int((int32)-1);
	}
	if (type == S_LONG || t2.type == S_LONG)
		return Long((int64)(LongValue(nullptr) % t2.LongValue(nullptr)));
	return Int( IntValue(nullptr) % t2.IntValue(nullptr));
}
コード例 #13
0
ファイル: adf_raw.c プロジェクト: rkujawa/diskimage2hfe
/*
 * adfBitmapSum
 *
 */
	unsigned long 
adfBitmapSum(unsigned char *buf)
{
	unsigned long newSum;
	int i;
	
	newSum = 0L;
	for(i=1; i<128; i++)
		newSum-=Long(buf+i*4);
	return(newSum);
}
コード例 #14
0
ファイル: scat.c プロジェクト: npe9/harvey
int
loadsao(int index)
{
    if(index<=0 || index>NSAO)
        return 0;
    saoopen();
    grow();
    cur->type = SAO;
    cur->index = index;
    seek(saodb, (index-1)*sizeof(SAOrec), 0);
    Eread(saodb, "sao", &cur->sao, sizeof(SAOrec));
    cur->sao.ra = Long(&cur->sao.ra);
    cur->sao.dec = Long(&cur->sao.dec);
    cur->sao.dra = Long(&cur->sao.dra);
    cur->sao.ddec = Long(&cur->sao.ddec);
    cur->sao.mag = Short(&cur->sao.mag);
    cur->sao.mpg = Short(&cur->sao.mpg);
    cur->sao.hd = Long(&cur->sao.hd);
    return 1;
}
コード例 #15
0
ファイル: adf_raw.c プロジェクト: rkujawa/diskimage2hfe
/*
 * NormalSum
 *
 * buf = where the block is stored
 * offset = checksum place (in bytes)
 * bufLen = buffer length (in bytes)
 */
    unsigned long
adfNormalSum( UCHAR* buf, int offset, int bufLen )
{
    long newsum;
    int i;

    newsum=0L;
    for(i=0; i < (bufLen/4); i++)
        if ( i != (offset/4) )       /* old chksum */
            newsum+=Long(buf+i*4);
    newsum=(-newsum);	/* WARNING */

    return(newsum);
}
コード例 #16
0
ファイル: scat.c プロジェクト: npe9/harvey
int
loadpatch(int32_t index)
{
    int i;

    patchopen();
    if(index<=0 || index>Npatch)
        return 0;
    grow();
    cur->type = Patch;
    cur->index = index;
    seek(patchdb, patchaddr[index-1], 0);
    cur->patch.nkey = (patchaddr[index]-patchaddr[index-1])/4;
    Eread(patchdb, "patch", cur->patch.key, cur->patch.nkey*4);
    for(i=0; i<cur->patch.nkey; i++)
        cur->patch.key[i] = Long(&cur->patch.key[i]);
    return 1;
}
コード例 #17
0
ファイル: scat.c プロジェクト: npe9/harvey
void
nameopen(void)
{
    Biobuf b;
    int i;
    char *l, *p;

    if(namedb == 0) {
        namedb = eopen("name");
        Binit(&b, namedb, OREAD);
        for(i=0; i<NName; i++) {
            l = Brdline(&b, '\n');
            if(l == 0)
                break;
            p = strchr(l, '\t');
            if(p == 0) {
Badformat:
                Bprint(&bout, "warning: name.scat bad format; line %d\n", i+1);
                break;
            }
            *p++ = 0;
            strcpy(name[i].name, l);
            if(strncmp(p, "ngc", 3) == 0)
                name[i].ngc = atoi(p+3);
            else if(strncmp(p, "ic", 2) == 0)
                name[i].ngc = atoi(p+2)+NNGC;
            else if(strncmp(p, "sao", 3) == 0)
                name[i].sao = atoi(p+3);
            else if(strncmp(p, "abell", 5) == 0)
                name[i].abell = atoi(p+5);
            else
                goto Badformat;
        }
        if(i == NName)
            Bprint(&bout, "warning: too many names in name.scat (max %d); extra ignored\n", NName);
        close(namedb);

        bayerdb = eopen("bayer");
        Eread(bayerdb, "bayer", bayer, sizeof bayer);
        close(bayerdb);
        for(i=0; i<NBayer; i++)
            bayer[i].sao = Long(&bayer[i].sao);
    }
}
コード例 #18
0
ファイル: adf_raw.c プロジェクト: rkujawa/diskimage2hfe
    unsigned long 
adfBootSum2(unsigned char *buf)
{
    unsigned long prevsum, newSum;
    int i;

    prevsum = newSum=0L;
    for(i=0; i<1024/sizeof(unsigned long); i++) {
        if (i!=1) {
            prevsum = newSum;
            newSum += Long(buf+i*4);
            if (newSum < prevsum)
                newSum++;
        }
    }
    newSum = ~newSum;	/* not */

    return(newSum);
}
コード例 #19
0
ファイル: adf_raw.c プロジェクト: rkujawa/diskimage2hfe
/*
 * adfBootSum
 *
 */
    unsigned long 
adfBootSum(unsigned char *buf)
{
    unsigned long d, newSum;
    int i;
	
    newSum=0L;
    for(i=0; i<256; i++) {
        if (i!=1) {
            d = Long(buf+i*4);
            if ( (ULONG_MAX-newSum)<d )
                newSum++;
            newSum+=d;
        }
    }
    newSum = ~newSum;	/* not */

    return(newSum);
}
コード例 #20
0
ファイル: adf_raw.c プロジェクト: rkujawa/diskimage2hfe
    void
swapEndian( unsigned char *buf, int type )
{
    int i,j;
    int p;

    i=0;
    p=0;

    if (type>MAX_SWTYPE || type<0)
        adfEnv.eFct("SwapEndian: type do not exist");

    while( swapTable[type][i]!=0 ) {
        for(j=0; j<swapTable[type][i]; j++) {
            switch( swapTable[type][i+1] ) {
            case SW_LONG:
                *(unsigned long*)(buf+p)=Long(buf+p);
                p+=4;
                break;
            case SW_SHORT:
                *(unsigned short*)(buf+p)=Short(buf+p);
                p+=2;
                break;
            case SW_CHAR:
                p++;
                break;
            default:
                ;
            }
        }
    i+=2;
    }
    if (p!=swapTable[type][i+1]) 
        (*adfEnv.wFct)("Warning: Endian Swapping length");		/* BV */
    

}
コード例 #21
0
ファイル: BaseVal.cpp プロジェクト: dakyri/qua
TypedValue	&
TypedValue::operator - (TypedValue &t2)
{
	if (type == S_TIME && t2.type == S_TIME) {
		Time	*ti1 = TimeValue();
		Time	*ti2 = t2.TimeValue();
		return TimeV(*ti1 - *ti2);
	}
	if (type == S_TIME) {
		Time	*ti1 = TimeValue();
		int		ti2 = t2.IntValue(nullptr);
		return TimeV(*ti1 - ti2);
	}
	if (t2.type == S_TIME) {
		int		ti1 = IntValue(nullptr);
		Time	*ti2 = t2.TimeValue();
		return TimeV(Time(ti1) - *ti2);
	}
	if (type == S_FLOAT || t2.type == S_FLOAT)
		return Float( FloatValue(nullptr) - t2.FloatValue(nullptr));
	if (type == S_LONG || t2.type == S_LONG)
		return Long((int64)(LongValue(nullptr) - t2.LongValue(nullptr)));
	return Int( IntValue(nullptr) - t2.IntValue(nullptr));
}
コード例 #22
0
ファイル: SpLong.cpp プロジェクト: MuhammadAttia/ICPCLibrary
Long convert(long long a) {
  return normal(Long(1, a));
}
コード例 #23
0
int _tmain(int argc, _TCHAR* argv[])
{
	/*int width = 1024,height=600;
	SDL_Surface* screen = enableScreen(width,height,24);
	Color white = Color(255,255,255);
	float red=255,green=255,blue=255,posx=200,posy=200;
	white.SetNewColor(red,green,blue);
	while (true) 
		{
				SDL_Event keyEvent ; SDL_PollEvent(&keyEvent);
			for (int x=posx;x<posx+100;x++) for (int y=posy;y<posy+100;y++)
				{
					putpixel(screen,x,y,Color(0,0,0).GetUint32());
				}
			if(keyEvent.type == SDL_KEYDOWN) switch (keyEvent.key.keysym.sym)
			{
			case SDLK_ESCAPE: return 0;
			case SDLK_1: if(red<255) red+=1; break;
			case SDLK_2: if(red>0) red-=1; break;
			case SDLK_3: if(green<255) green+=1; break;
			case SDLK_4: if(green>0) green-=1; break;
			case SDLK_5: if(blue<255) blue+=1; break;
			case SDLK_6: if(blue>0) blue-=1; break;
			case SDLK_UP: posy-=1; break;
			case SDLK_DOWN: posy+=1; break;
			case SDLK_LEFT: posx-=1; break;
			case SDLK_RIGHT: posx+=1; break;
			}
			white.SetNewColor(red,green,blue);
			for (int x=posx;x<posx+100;x++) for (int y=posy;y<posy+100;y++)
				{
					putpixel(screen,x,y,white.GetUint32());
				}
			SDL_UpdateRect(screen,0,0,width,height);





		}*/

	Sphere s1 = Sphere(Vector(0,200,0),Color(255,0,0),20);
	SDL_Surface* screen = enableScreen(1024,600,24);
	LightSource light(150,50,0,20000);
	DrawSphere(screen,s1,1024,600,light);
	//SmartDrawSphere(screen,light,s1,1024,600);
	float a = Skalar(s1.center_,s1.center_);
	int b = Long(s1.center_);
	while (true) 
		{
			SDL_Event keyEvent ; SDL_PollEvent(&keyEvent);
			if(keyEvent.type == SDL_KEYDOWN) switch (keyEvent.key.keysym.sym)
				{
					case SDLK_ESCAPE: return 0;
					case SDLK_LEFT: 
						{
							DrawScreen(screen,1024,600,Color(0,0,0));
							light.x_-=5;
							DrawSphere(screen,s1,1024,600,light);
							break;
						}
					case SDLK_RIGHT: 
						{
							DrawScreen(screen,1024,600,Color(0,0,0));
							light.x_+=5;
							DrawSphere(screen,s1,1024,600,light);
							break;
						}
					case SDLK_UP: 
						{
							DrawScreen(screen,1024,600,Color(0,0,0));
							light.y_+=5;
							DrawSphere(screen,s1,1024,600,light);
							break;
						}
					case SDLK_DOWN: 
						{
							DrawScreen(screen,1024,600,Color(0,0,0));
							light.y_-=5;
							DrawSphere(screen,s1,1024,600,light);
							break;
						}
					case SDLK_PAGEUP:
						{
							DrawScreen(screen,1024,600,Color(0,0,0));
							light.density_+=1000;
							DrawSphere(screen,s1,1024,600,light);
							break;
						}
					case SDLK_PAGEDOWN:
						{
							DrawScreen(screen,1024,600,Color(0,0,0));
							light.density_-=1000;
							DrawSphere(screen,s1,1024,600,light);
							break;
						}
				}
			//DrawScreen(screen,1024,600,Color(0,0,0));
			//DrawSphere(screen,s1,1024,600,light);
		}
	return 0;
}
コード例 #24
0
ファイル: creal.cpp プロジェクト: gatgui/myst
void RealClass::ToInt(Context *ctx, Long n) throw(Exception) {
    Real *r = (Real*) ctx->at(-n);
    ctx->pop(n);
    ctx->push(new Integer(Long(r->data)));
}