14bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/****************************************************************
24bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
34bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesThe author of this software is David M. Gay.
44bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
54bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesCopyright (C) 1998, 2000 by Lucent Technologies
64bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesAll Rights Reserved
74bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
84bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesPermission to use, copy, modify, and distribute this software and
94bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesits documentation for any purpose and without fee is hereby
104bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesgranted, provided that the above copyright notice appear in all
114bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughescopies and that both that the copyright notice and this
124bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughespermission notice and warranty disclaimer appear in supporting
134bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesdocumentation, and that the name of Lucent or any of its entities
144bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesnot be used in advertising or publicity pertaining to
154bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesdistribution of the software without specific, written prior
164bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughespermission.
174bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
184bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
194bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
204bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
214bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
224bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
234bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
244bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
254bd97cee28dd815fff54fc97560be60d566c1fa5Elliott HughesTHIS SOFTWARE.
264bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
274bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes****************************************************************/
284bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
294bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes/* Please send bug reports to David M. Gay (dmg at acm dot org,
304bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes * with " at " changed at "@" and " dot " changed to ".").	*/
314bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
324bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "gdtoaimp.h"
334bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
344bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes float
354bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef KR_headers
364bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesstrtof(s, sp) CONST char *s; char **sp;
374bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
384bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughesstrtof(CONST char *s, char **sp)
394bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
404bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes{
414bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	static FPI fpi0 = { 24, 1-127-24+1,  254-127-24+1, 1, SI };
424bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	ULong bits[1];
434bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	Long exp;
444bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	int k;
454bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	union { ULong L[1]; float f; } u;
464bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#ifdef Honor_FLT_ROUNDS
474bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#include "gdtoa_fltrnds.h"
484bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#else
494bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#define fpi &fpi0
504bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes#endif
514bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
524bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	k = strtodg(s, sp, fpi, &exp, bits);
534bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	switch(k & STRTOG_Retmask) {
544bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_NoNumber:
554bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_Zero:
564bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		u.L[0] = 0;
574bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		break;
584bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
594bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_Normal:
604bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_NaNbits:
614bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		u.L[0] = (bits[0] & 0x7fffff) | ((exp + 0x7f + 23) << 23);
624bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		break;
634bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
644bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_Denormal:
654bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		u.L[0] = bits[0];
664bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		break;
674bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
684bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_NoMemory:
694bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		errno = ERANGE;
704bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		/* FALLTHROUGH */
714bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_Infinite:
724bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		u.L[0] = 0x7f800000;
734bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		break;
744bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes
754bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  case STRTOG_NaN:
764bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		u.L[0] = f_QNAN;
774bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	  }
784bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	if (k & STRTOG_Neg)
794bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes		u.L[0] |= 0x80000000L;
804bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	return u.f;
814bd97cee28dd815fff54fc97560be60d566c1fa5Elliott Hughes	}
82