167754Smsmith/**************************************************************** 267754Smsmith 367754SmsmithThe author of this software is David M. Gay. 4107325Siwasaki 567754SmsmithCopyright (C) 1998, 2000 by Lucent Technologies 667754SmsmithAll Rights Reserved 767754Smsmith 867754SmsmithPermission to use, copy, modify, and distribute this software and 967754Smsmithits documentation for any purpose and without fee is hereby 1067754Smsmithgranted, provided that the above copyright notice appear in all 1167754Smsmithcopies and that both that the copyright notice and this 1291116Smsmithpermission notice and warranty disclaimer appear in supporting 1370243Smsmithdocumentation, and that the name of Lucent or any of its entities 1467754Smsmithnot be used in advertising or publicity pertaining to 1567754Smsmithdistribution of the software without specific, written prior 1667754Smsmithpermission. 1767754Smsmith 1867754SmsmithLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1967754SmsmithINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 2067754SmsmithIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 2167754SmsmithSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 2267754SmsmithWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 2367754SmsmithIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 2467754SmsmithARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 2567754SmsmithTHIS SOFTWARE. 2667754Smsmith 2767754Smsmith****************************************************************/ 2867754Smsmith 2967754Smsmith/* Please send bug reports to David M. Gay (dmg at acm dot org, 3067754Smsmith * with " at " changed at "@" and " dot " changed to "."). */ 3167754Smsmith 3267754Smsmith#include "gdtoaimp.h" 3367754Smsmith 3467754Smsmith void 3567754Smsmith#ifdef KR_headers 3667754SmsmithULtod(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; 3767754Smsmith#else 3867754SmsmithULtod(ULong *L, ULong *bits, Long exp, int k) 3967754Smsmith#endif 4067754Smsmith{ 4167754Smsmith switch(k & STRTOG_Retmask) { 4267754Smsmith case STRTOG_NoNumber: 4367754Smsmith case STRTOG_Zero: 4467754Smsmith L[0] = L[1] = 0; 4567754Smsmith break; 4667754Smsmith 4767754Smsmith case STRTOG_Denormal: 4867754Smsmith L[_1] = bits[0]; 4967754Smsmith L[_0] = bits[1]; 5067754Smsmith break; 5167754Smsmith 5267754Smsmith case STRTOG_Normal: 5367754Smsmith case STRTOG_NaNbits: 5467754Smsmith L[_1] = bits[0]; 5567754Smsmith L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); 5667754Smsmith break; 5767754Smsmith 5867754Smsmith case STRTOG_NoMemory: 5967754Smsmith errno = ERANGE; 6067754Smsmith /* FALLTHROUGH */ 6167754Smsmith case STRTOG_Infinite: 6267754Smsmith L[_0] = 0x7ff00000; 6367754Smsmith L[_1] = 0; 6467754Smsmith break; 6567754Smsmith 6667754Smsmith case STRTOG_NaN: 6767754Smsmith L[0] = d_QNAN0; 6867754Smsmith L[1] = d_QNAN1; 6967754Smsmith } 7067754Smsmith if (k & STRTOG_Neg) 7167754Smsmith L[_0] |= 0x80000000L; 7267754Smsmith } 7367754Smsmith 7467754Smsmith int 7567754Smsmith#ifdef KR_headers 7667754Smsmithstrtord(s, sp, rounding, d) CONST char *s; char **sp; int rounding; double *d; 7767754Smsmith#else 7867754Smsmithstrtord(CONST char *s, char **sp, int rounding, double *d) 7967754Smsmith#endif 8067754Smsmith{ 8167754Smsmith static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; 8267754Smsmith FPI *fpi, fpi1; 8367754Smsmith ULong bits[2]; 8467754Smsmith Long exp; 8567754Smsmith int k; 8667754Smsmith 8767754Smsmith fpi = &fpi0; 8867754Smsmith if (rounding != FPI_Round_near) { 8967754Smsmith fpi1 = fpi0; 9067754Smsmith fpi1.rounding = rounding; 9167754Smsmith fpi = &fpi1; 9267754Smsmith } 9367754Smsmith k = strtodg(s, sp, fpi, &exp, bits); 9467754Smsmith ULtod((ULong*)d, bits, exp, k); 9567754Smsmith return k; 9667754Smsmith } 9767754Smsmith