1/**************************************************************** 2 3The author of this software is David M. Gay. 4 5Copyright (C) 2004 by David M. Gay. 6All Rights Reserved 7Based on material in the rest of /netlib/fp/gdota.tar.gz, 8which is copyright (C) 1998, 2000 by Lucent Technologies. 9 10Permission to use, copy, modify, and distribute this software and 11its documentation for any purpose and without fee is hereby 12granted, provided that the above copyright notice appear in all 13copies and that both that the copyright notice and this 14permission notice and warranty disclaimer appear in supporting 15documentation, and that the name of Lucent or any of its entities 16not be used in advertising or publicity pertaining to 17distribution of the software without specific, written prior 18permission. 19 20LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 21INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 22IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 23SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 24WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 25IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 26ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 27THIS SOFTWARE. 28 29****************************************************************/ 30 31/* This is a variant of strtod that works on Intel ia32 systems */ 32/* with the default extended-precision arithmetic -- it does not */ 33/* require setting the precision control to 53 bits. */ 34 35/* Please send bug reports to David M. Gay (dmg at acm dot org, 36 * with " at " changed at "@" and " dot " changed to "."). */ 37 38#include "gdtoaimp.h" 39 40 double 41#ifdef KR_headers 42strtod(s, sp) CONST char *s; char **sp; 43#else 44strtod(CONST char *s, char **sp) 45#endif 46{ 47 static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; 48 ULong bits[2]; 49 Long exp; 50 int k; 51 union { ULong L[2]; double d; } u; 52 53 k = strtodg(s, sp, &fpi, &exp, bits); 54 switch(k & STRTOG_Retmask) { 55 case STRTOG_NoNumber: 56 case STRTOG_Zero: 57 u.L[0] = u.L[1] = 0; 58 break; 59 60 case STRTOG_Normal: 61 u.L[_1] = bits[0]; 62 u.L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); 63 break; 64 65 case STRTOG_Denormal: 66 u.L[_1] = bits[0]; 67 u.L[_0] = bits[1]; 68 break; 69 70 case STRTOG_Infinite: 71 u.L[_0] = 0x7ff00000; 72 u.L[_1] = 0; 73 break; 74 75 case STRTOG_NaN: 76 u.L[0] = d_QNAN0; 77 u.L[1] = d_QNAN1; 78 break; 79 80 case STRTOG_NaNbits: 81 u.L[_0] = 0x7ff00000 | bits[1]; 82 u.L[_1] = bits[0]; 83 } 84 if (k & STRTOG_Neg) 85 u.L[_0] |= 0x80000000L; 86 return u.d; 87 } 88