Annotation of coherent/b/lib/libc/gen/decvax_d.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * libc/gen/decvax_d.c
                      3:  */
                      4: 
                      5: /*
                      6:  * decvax_d(double *ddp, double *idp)
                      7:  * Convert double from IEEE format to DECVAX format.
                      8:  * idp points to an IEEE format double to convert.
                      9:  * ddp points to a destination for the converted DECVAX value;
                     10:  * ddp may be identical to idp for in-place conversion.
                     11:  * Returns 0 on success, -1 on underflow, 1 on overflow.
                     12:  */
                     13: 
                     14: int
                     15: decvax_d(ddp, idp) double *ddp, *idp;
                     16: {
                     17:        unsigned char a[8];
                     18:        register unsigned char *cp;
                     19:        register int exp, a0123456;
                     20: 
                     21:        /* Extract sign, biased exponent. */
                     22:        cp = (char *)idp;
                     23:        exp = ((cp[7] & 0x7F) << 4) | ((cp[6] & 0xF0) >> 4);
                     24:        if (exp == 0) {
                     25:                a0123456 = (a[6] & 0x0F) | a[5] | a[4] | a[3] | a[2] | a[1] | a[0];
                     26:                memset((char *)ddp, 0, 8);              /* set to 0.0 */
                     27:                return (a0123456 == 0) ? 0 : -1;        /* return -1 for denormals */
                     28:        }
                     29: 
                     30:        /* Adjust exponent bias. */
                     31:        exp -= 1023 - 129;
                     32:        if (exp <= 0) {
                     33:                memset((char *)ddp, 0, 8);      /* set to 0.0 */
                     34:                return -1;                      /* underflow */
                     35:        } else if (exp > 255) {
                     36:                /* Overflow, also used for NaNs. */
                     37:                cp = (char *)ddp;
                     38:                memset(cp, 0xFF, 7);            /* set to max */
                     39:                cp[7] |= 0x7F;                  /* preserving sign bit */
                     40:                return 1;                       /* overflow */
                     41:        }
                     42: 
                     43:        /* Repack. */
                     44:        a[7] = (cp[7] & 0x80) | ((exp & 0xFE) >> 1);
                     45:        a[6] = ((exp & 1) << 7) | ((cp[6] & 0x0F) << 3) | ((cp[5] & 0xE0) >> 5);
                     46:        a[5] = ((cp[5] & 0x1F) << 3) | ((cp[4] & 0xE0) >> 5);
                     47:        a[4] = ((cp[4] & 0x1F) << 3) | ((cp[3] & 0xE0) >> 5);
                     48:        a[3] = ((cp[3] & 0x1F) << 3) | ((cp[2] & 0xE0) >> 5);
                     49:        a[2] = ((cp[2] & 0x1F) << 3) | ((cp[1] & 0xE0) >> 5);
                     50:        a[1] = ((cp[1] & 0x1F) << 3) | ((cp[0] & 0xE0) >> 5);
                     51:        a[0] = ((cp[0] & 0x1F) << 3);
                     52:        memcpy((char *)ddp, a, 8);
                     53:        return 0;
                     54: }
                     55: 
                     56: /* end of libc/gen/decvax_d.c */

unix.superglobalmegacorp.com

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