1100978Srwatson/****************************************************************
2100978Srwatson
3100978SrwatsonThe author of this software is David M. Gay.
4100978Srwatson
5100978SrwatsonCopyright (C) 1998, 2000 by Lucent Technologies
6100978SrwatsonAll Rights Reserved
7100978Srwatson
8100978SrwatsonPermission to use, copy, modify, and distribute this software and
9100978Srwatsonits documentation for any purpose and without fee is hereby
10100978Srwatsongranted, provided that the above copyright notice appear in all
11100978Srwatsoncopies and that both that the copyright notice and this
12100978Srwatsonpermission notice and warranty disclaimer appear in supporting
13100978Srwatsondocumentation, and that the name of Lucent or any of its entities
14100978Srwatsonnot be used in advertising or publicity pertaining to
15100978Srwatsondistribution of the software without specific, written prior
16100978Srwatsonpermission.
17100978Srwatson
18100978SrwatsonLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19100978SrwatsonINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20100978SrwatsonIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21100978SrwatsonSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22100978SrwatsonWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23100978SrwatsonIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24100978SrwatsonARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25100978SrwatsonTHIS SOFTWARE.
26100978Srwatson
27100978Srwatson****************************************************************/
28100978Srwatson
29100978Srwatson/* Please send bug reports to David M. Gay (dmg at acm dot org,
30100978Srwatson * with " at " changed at "@" and " dot " changed to ".").	*/
31100978Srwatson
32100978Srwatson#include "gdtoaimp.h"
33100978Srwatson
34100978Srwatson int
35100978Srwatson#ifdef KR_headers
36100978Srwatsonstrtopf(s, sp, f) CONST char *s; char **sp; float *f;
37100978Srwatson#else
38100978Srwatsonstrtopf(CONST char *s, char **sp, float *f)
39100978Srwatson#endif
40100978Srwatson{
41100978Srwatson	static FPI fpi0 = { 24, 1-127-24+1,  254-127-24+1, 1, SI };
42100978Srwatson	ULong bits[1], *L;
43100978Srwatson	Long exp;
44100978Srwatson	int k;
45100978Srwatson#ifdef Honor_FLT_ROUNDS
46100978Srwatson#include "gdtoa_fltrnds.h"
47100978Srwatson#else
48101826Srwatson#define fpi &fpi0
49101826Srwatson#endif
50100978Srwatson
51100978Srwatson	k = strtodg(s, sp, fpi, &exp, bits);
52100978Srwatson	L = (ULong*)f;
53100978Srwatson	switch(k & STRTOG_Retmask) {
54100978Srwatson	  case STRTOG_NoNumber:
55100978Srwatson	  case STRTOG_Zero:
56100978Srwatson		L[0] = 0;
57100978Srwatson		break;
58100978Srwatson
59100978Srwatson	  case STRTOG_Normal:
60100978Srwatson	  case STRTOG_NaNbits:
61100978Srwatson		L[0] = (bits[0] & 0x7fffff) | ((exp + 0x7f + 23) << 23);
62100978Srwatson		break;
63100978Srwatson
64100978Srwatson	  case STRTOG_Denormal:
65100978Srwatson		L[0] = bits[0];
66100978Srwatson		break;
67100978Srwatson
68100978Srwatson	  case STRTOG_Infinite:
69100978Srwatson		L[0] = 0x7f800000;
70100978Srwatson		break;
71100978Srwatson
72100978Srwatson	  case STRTOG_NaN:
73100978Srwatson		L[0] = f_QNAN;
74100978Srwatson	  }
75100978Srwatson	if (k & STRTOG_Neg)
76100978Srwatson		L[0] |= 0x80000000L;
77100978Srwatson	return k;
78100978Srwatson	}
79100978Srwatson