1cc36ccd1SDavid Schultz /****************************************************************
2cc36ccd1SDavid Schultz
3cc36ccd1SDavid Schultz The author of this software is David M. Gay.
4cc36ccd1SDavid Schultz
5cc36ccd1SDavid Schultz Copyright (C) 1998, 2000 by Lucent Technologies
6cc36ccd1SDavid Schultz All Rights Reserved
7cc36ccd1SDavid Schultz
8cc36ccd1SDavid Schultz Permission to use, copy, modify, and distribute this software and
9cc36ccd1SDavid Schultz its documentation for any purpose and without fee is hereby
10cc36ccd1SDavid Schultz granted, provided that the above copyright notice appear in all
11cc36ccd1SDavid Schultz copies and that both that the copyright notice and this
12cc36ccd1SDavid Schultz permission notice and warranty disclaimer appear in supporting
13cc36ccd1SDavid Schultz documentation, and that the name of Lucent or any of its entities
14cc36ccd1SDavid Schultz not be used in advertising or publicity pertaining to
15cc36ccd1SDavid Schultz distribution of the software without specific, written prior
16cc36ccd1SDavid Schultz permission.
17cc36ccd1SDavid Schultz
18cc36ccd1SDavid Schultz LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19cc36ccd1SDavid Schultz INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20cc36ccd1SDavid Schultz IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21cc36ccd1SDavid Schultz SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22cc36ccd1SDavid Schultz WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23cc36ccd1SDavid Schultz IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24cc36ccd1SDavid Schultz ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25cc36ccd1SDavid Schultz THIS SOFTWARE.
26cc36ccd1SDavid Schultz
27cc36ccd1SDavid Schultz ****************************************************************/
28cc36ccd1SDavid Schultz
29c88250a5SDavid Schultz /* Please send bug reports to David M. Gay (dmg at acm dot org,
30c88250a5SDavid Schultz * with " at " changed at "@" and " dot " changed to "."). */
31cc36ccd1SDavid Schultz
3210a381e5SDavid Schultz /* $FreeBSD$ */
3310a381e5SDavid Schultz
34cc36ccd1SDavid Schultz #include "gdtoaimp.h"
35cc36ccd1SDavid Schultz
36cc36ccd1SDavid Schultz float
37cc36ccd1SDavid Schultz #ifdef KR_headers
strtof_l(s,sp,loc)38*3c87aa1dSDavid Chisnall strtof_l(s, sp, loc) CONST char *s; char **sp; locale_t loc;
39cc36ccd1SDavid Schultz #else
40*3c87aa1dSDavid Chisnall strtof_l(CONST char *s, char **sp, locale_t loc)
41cc36ccd1SDavid Schultz #endif
42cc36ccd1SDavid Schultz {
439fb02073SDavid Schultz static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
44cc36ccd1SDavid Schultz ULong bits[1];
45cc36ccd1SDavid Schultz Long exp;
46cc36ccd1SDavid Schultz int k;
47cc36ccd1SDavid Schultz union { ULong L[1]; float f; } u;
484848dd08SDavid Schultz #ifdef Honor_FLT_ROUNDS
494848dd08SDavid Schultz #include "gdtoa_fltrnds.h"
504848dd08SDavid Schultz #else
514848dd08SDavid Schultz #define fpi &fpi0
524848dd08SDavid Schultz #endif
53cc36ccd1SDavid Schultz
54*3c87aa1dSDavid Chisnall k = strtodg_l(s, sp, fpi, &exp, bits, loc);
55cc36ccd1SDavid Schultz switch(k & STRTOG_Retmask) {
56cc36ccd1SDavid Schultz case STRTOG_NoNumber:
57cc36ccd1SDavid Schultz case STRTOG_Zero:
58cc36ccd1SDavid Schultz u.L[0] = 0;
59cc36ccd1SDavid Schultz break;
60cc36ccd1SDavid Schultz
61cc36ccd1SDavid Schultz case STRTOG_Normal:
6250dad48bSDavid Schultz u.L[0] = (bits[0] & 0x7fffff) | ((exp + 0x7f + 23) << 23);
63cc36ccd1SDavid Schultz break;
64cc36ccd1SDavid Schultz
6510a381e5SDavid Schultz case STRTOG_NaNbits:
6610a381e5SDavid Schultz /* FreeBSD local: always return a quiet NaN */
6710a381e5SDavid Schultz u.L[0] = bits[0] | 0x7fc00000;
6810a381e5SDavid Schultz break;
6910a381e5SDavid Schultz
70cc36ccd1SDavid Schultz case STRTOG_Denormal:
71cc36ccd1SDavid Schultz u.L[0] = bits[0];
72cc36ccd1SDavid Schultz break;
73cc36ccd1SDavid Schultz
74cc36ccd1SDavid Schultz case STRTOG_Infinite:
75cc36ccd1SDavid Schultz u.L[0] = 0x7f800000;
76cc36ccd1SDavid Schultz break;
77cc36ccd1SDavid Schultz
78cc36ccd1SDavid Schultz case STRTOG_NaN:
79c88250a5SDavid Schultz u.L[0] = f_QNAN;
80cc36ccd1SDavid Schultz }
81cc36ccd1SDavid Schultz if (k & STRTOG_Neg)
82cc36ccd1SDavid Schultz u.L[0] |= 0x80000000L;
83cc36ccd1SDavid Schultz return u.f;
84cc36ccd1SDavid Schultz }
85*3c87aa1dSDavid Chisnall float
86*3c87aa1dSDavid Chisnall #ifdef KR_headers
strtof(s,sp)87*3c87aa1dSDavid Chisnall strtof(s, sp) CONST char *s; char **sp;
88*3c87aa1dSDavid Chisnall #else
89*3c87aa1dSDavid Chisnall strtof(CONST char *s, char **sp)
90*3c87aa1dSDavid Chisnall #endif
91*3c87aa1dSDavid Chisnall {
92*3c87aa1dSDavid Chisnall return strtof_l(s, sp, __get_locale());
93*3c87aa1dSDavid Chisnall }
94*3c87aa1dSDavid Chisnall
95