|
|
1.1 ! root 1: /* ! 2: * libc/gen/ieee_d.c ! 3: */ ! 4: ! 5: /* ! 6: * ieee_d(double *idp, double *ddp) ! 7: * Convert double from DECVAX format to IEEE format. ! 8: * ddp points to a DECVAX format double to convert. ! 9: * idp points to a destination for the converted IEEE value; ! 10: * idp may be identical to ddp for in-place conversion. ! 11: * The DECVAX significand is truncated, not rounded. ! 12: * Always returns 0, because the conversion always succeeds. ! 13: */ ! 14: ! 15: int ! 16: ieee_d(idp, ddp) double *idp, *ddp; ! 17: { ! 18: unsigned char a[8]; ! 19: register unsigned char *cp; ! 20: register int exp; ! 21: ! 22: /* Extract biased exponent. */ ! 23: cp = (char *)ddp; ! 24: exp = ((cp[7] & 0x7F) << 1) | ((cp[6] & 0x80) >> 7); ! 25: ! 26: if (exp == 0) { ! 27: memset((char *)idp, 0, 8); /* set idp to 0.0 */ ! 28: return 0; ! 29: } ! 30: ! 31: /* Adjust exponent bias and repack. */ ! 32: exp += 1023 - 129; ! 33: a[7] = (cp[7] & 0x80) | (exp >> 4); ! 34: a[6] = ((exp & 0x0F) << 4) | ((cp[6] & 0x78) >> 3); ! 35: a[5] = ((cp[6] & 0x7) << 5) | ((cp[5] & 0x7F) >> 3); ! 36: a[4] = ((cp[5] & 0x7) << 5) | ((cp[4] & 0x7F) >> 3); ! 37: a[3] = ((cp[4] & 0x7) << 5) | ((cp[3] & 0x7F) >> 3); ! 38: a[2] = ((cp[3] & 0x7) << 5) | ((cp[2] & 0x7F) >> 3); ! 39: a[1] = ((cp[2] & 0x7) << 5) | ((cp[1] & 0x7F) >> 3); ! 40: a[0] = ((cp[1] & 0x7) << 5) | ((cp[0] & 0x7F) >> 3); ! 41: ! 42: /* Done, copy to destination. */ ! 43: memcpy((char *)idp, a, 8); ! 44: return 0; ! 45: } ! 46: ! 47: /* end of libc/gen/ieee_d.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.