1112158Sdas/****************************************************************
2112158Sdas
3112158SdasThe author of this software is David M. Gay.
4112158Sdas
5112158SdasCopyright (C) 1998, 2000 by Lucent Technologies
6112158SdasAll Rights Reserved
7112158Sdas
8112158SdasPermission to use, copy, modify, and distribute this software and
9112158Sdasits documentation for any purpose and without fee is hereby
10112158Sdasgranted, provided that the above copyright notice appear in all
11112158Sdascopies and that both that the copyright notice and this
12112158Sdaspermission notice and warranty disclaimer appear in supporting
13112158Sdasdocumentation, and that the name of Lucent or any of its entities
14112158Sdasnot be used in advertising or publicity pertaining to
15112158Sdasdistribution of the software without specific, written prior
16112158Sdaspermission.
17112158Sdas
18112158SdasLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19112158SdasINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20112158SdasIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21112158SdasSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22112158SdasWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23112158SdasIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24112158SdasARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25112158SdasTHIS SOFTWARE.
26112158Sdas
27112158Sdas****************************************************************/
28112158Sdas
29165743Sdas/* Please send bug reports to David M. Gay (dmg at acm dot org,
30165743Sdas * with " at " changed at "@" and " dot " changed to ".").	*/
31112158Sdas
32174679Sdas/* $FreeBSD$ */
33174679Sdas
34112158Sdas#include "gdtoaimp.h"
35112158Sdas
36112158Sdas float
37112158Sdas#ifdef KR_headers
38227753Stheravenstrtof_l(s, sp, loc) CONST char *s; char **sp; locale_t loc;
39112158Sdas#else
40227753Stheravenstrtof_l(CONST char *s, char **sp, locale_t loc)
41112158Sdas#endif
42112158Sdas{
43182710Sdas	static FPI fpi0 = { 24, 1-127-24+1,  254-127-24+1, 1, SI };
44112158Sdas	ULong bits[1];
45112158Sdas	Long exp;
46112158Sdas	int k;
47112158Sdas	union { ULong L[1]; float f; } u;
48187808Sdas#ifdef Honor_FLT_ROUNDS
49187808Sdas#include "gdtoa_fltrnds.h"
50187808Sdas#else
51187808Sdas#define fpi &fpi0
52187808Sdas#endif
53112158Sdas
54227753Stheraven	k = strtodg_l(s, sp, fpi, &exp, bits, loc);
55112158Sdas	switch(k & STRTOG_Retmask) {
56112158Sdas	  case STRTOG_NoNumber:
57112158Sdas	  case STRTOG_Zero:
58112158Sdas		u.L[0] = 0;
59112158Sdas		break;
60112158Sdas
61112158Sdas	  case STRTOG_Normal:
62219557Sdas		u.L[0] = (bits[0] & 0x7fffff) | ((exp + 0x7f + 23) << 23);
63112158Sdas		break;
64112158Sdas
65174679Sdas	  case STRTOG_NaNbits:
66174679Sdas		/* FreeBSD local: always return a quiet NaN */
67174679Sdas		u.L[0] = bits[0] | 0x7fc00000;
68174679Sdas		break;
69174679Sdas
70112158Sdas	  case STRTOG_Denormal:
71112158Sdas		u.L[0] = bits[0];
72112158Sdas		break;
73112158Sdas
74112158Sdas	  case STRTOG_Infinite:
75112158Sdas		u.L[0] = 0x7f800000;
76112158Sdas		break;
77112158Sdas
78112158Sdas	  case STRTOG_NaN:
79165743Sdas		u.L[0] = f_QNAN;
80112158Sdas	  }
81112158Sdas	if (k & STRTOG_Neg)
82112158Sdas		u.L[0] |= 0x80000000L;
83112158Sdas	return u.f;
84112158Sdas	}
85227753Stheraven float
86227753Stheraven#ifdef KR_headers
87227753Stheravenstrtof(s, sp) CONST char *s; char **sp;
88227753Stheraven#else
89227753Stheravenstrtof(CONST char *s, char **sp)
90227753Stheraven#endif
91227753Stheraven{
92227753Stheraven	return strtof_l(s, sp, __get_locale());
93227753Stheraven}
94227753Stheraven
95