Annotation of researchv9/jtools/src/sunlib/cos.c, revision 1.1

1.1     ! root        1: static
        !             2: short costab[91]={
        !             3:        1024,   1024,   1023,   1023,   1022,
        !             4:        1020,   1018,   1016,   1014,   1011,
        !             5:        1008,   1005,   1002,   998,    994,
        !             6:        989,    984,    979,    974,    968,
        !             7:        962,    956,    949,    943,    935,
        !             8:        928,    920,    912,    904,    896,
        !             9:        887,    878,    868,    859,    849,
        !            10:        839,    828,    818,    807,    796,
        !            11:        784,    773,    761,    749,    737,
        !            12:        724,    711,    698,    685,    672,
        !            13:        658,    644,    630,    616,    602,
        !            14:        587,    573,    558,    543,    527,
        !            15:        512,    496,    481,    465,    449,
        !            16:        433,    416,    400,    384,    367,
        !            17:        350,    333,    316,    299,    282,
        !            18:        265,    248,    230,    213,    195,
        !            19:        178,    160,    143,    125,    107,
        !            20:        89,     71,     54,     36,     18,
        !            21:        0,
        !            22: };
        !            23: cos (x)
        !            24: register x;
        !            25: {
        !            26:        x %= 360;
        !            27:        if(x<0)
        !            28:                x+=360;
        !            29:        if(x<=180)
        !            30:                return(x<90? costab[x] : -costab[180-x]);
        !            31:        return(x<180+90? -costab[x-180] : costab[360-x]);
        !            32: }
        !            33: 
        !            34: sin (x)
        !            35: register x;
        !            36: {
        !            37:        return(cos(x-90));
        !            38: }
        !            39: 
        !            40: static
        !            41: qatan2 (x, y)
        !            42: register x, y;
        !            43: {
        !            44:        if(x<y)
        !            45:                return(90-(45*((long)x)/y));
        !            46:        if(y==0)
        !            47:                return(0);
        !            48:        return(45*((long)y)/x);
        !            49: }
        !            50: 
        !            51: atan2 (xx, yy){
        !            52:        register x, y;
        !            53:        x = abs(xx);
        !            54:        y = abs(yy);
        !            55:        if(xx>=0 && yy>=0)
        !            56:                return(qatan2(x, y));
        !            57:        if(xx<0 && yy<=0)
        !            58:                return(180+qatan2(x, y));
        !            59:        if(xx<0 && yy>0)
        !            60:                return(180-qatan2(x, y));
        !            61:        return(360-qatan2(x, y));
        !            62: }
        !            63: 
        !            64: norm (x,y,z)
        !            65: {
        !            66:        return (sqrt(x*x + y*y + z*z));
        !            67: }
        !            68: 
        !            69: sqrtryz (x,y,z)
        !            70: {
        !            71:        register long sumsq;
        !            72: 
        !            73:        sumsq = x*x - y*y - z*z;
        !            74:        if(sumsq <= 0)
        !            75:                return 0;
        !            76:        return(sqrt(sumsq));
        !            77: }
        !            78: 
        !            79: #define MAXROOT 0xb504
        !            80: sqrt (x)
        !            81: register long x;
        !            82: {
        !            83:        register long high = MAXROOT;
        !            84:        register long low = 0;
        !            85:        register long current = MAXROOT/2;
        !            86:        if(x <= 0)
        !            87:                return 0;
        !            88:        if(x >= MAXROOT*MAXROOT)
        !            89:                return(MAXROOT);
        !            90:        while(high>low+1){
        !            91:                if(current*current==x)
        !            92:                        return (current);
        !            93:                if(current*current>x)
        !            94:                        high=current;
        !            95:                else
        !            96:                        low=current;
        !            97:                current=(high+low)>>1;
        !            98:        }
        !            99:        return(current);
        !           100: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.