]>
Commit | Line | Data |
---|---|---|
1 | /* $NetBSD: strtof.c,v 1.2.14.1 2008/04/08 21:10:55 jdc Exp $ */\r | |
2 | \r | |
3 | /****************************************************************\r | |
4 | \r | |
5 | The author of this software is David M. Gay.\r | |
6 | \r | |
7 | Copyright (C) 1998, 2000 by Lucent Technologies\r | |
8 | All Rights Reserved\r | |
9 | \r | |
10 | Permission to use, copy, modify, and distribute this software and\r | |
11 | its documentation for any purpose and without fee is hereby\r | |
12 | granted, provided that the above copyright notice appear in all\r | |
13 | copies and that both that the copyright notice and this\r | |
14 | permission notice and warranty disclaimer appear in supporting\r | |
15 | documentation, and that the name of Lucent or any of its entities\r | |
16 | not be used in advertising or publicity pertaining to\r | |
17 | distribution of the software without specific, written prior\r | |
18 | permission.\r | |
19 | \r | |
20 | LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r | |
21 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r | |
22 | IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r | |
23 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r | |
24 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r | |
25 | IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r | |
26 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r | |
27 | THIS SOFTWARE.\r | |
28 | \r | |
29 | ****************************************************************/\r | |
30 | \r | |
31 | /* Please send bug reports to David M. Gay (dmg at acm dot org,\r | |
32 | * with " at " changed at "@" and " dot " changed to "."). */\r | |
33 | #include <LibConfig.h>\r | |
34 | \r | |
35 | #include "namespace.h"\r | |
36 | #include "gdtoaimp.h"\r | |
37 | \r | |
38 | #ifdef __weak_alias\r | |
39 | __weak_alias(strtof, _strtof)\r | |
40 | #endif\r | |
41 | \r | |
42 | float\r | |
43 | #ifdef KR_headers\r | |
44 | strtof(s, sp) CONST char *s; char **sp;\r | |
45 | #else\r | |
46 | strtof(CONST char *s, char **sp)\r | |
47 | #endif\r | |
48 | {\r | |
49 | static CONST FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI };\r | |
50 | ULong bits[1];\r | |
51 | Long expt;\r | |
52 | int k;\r | |
53 | union { ULong L[1]; float f; } u = { { 0 } };\r | |
54 | \r | |
55 | k = strtodg(s, sp, &fpi, &expt, bits);\r | |
56 | if (k == STRTOG_NoMemory) {\r | |
57 | errno = ERANGE;\r | |
58 | return HUGE_VALF;\r | |
59 | }\r | |
60 | switch(k & STRTOG_Retmask) {\r | |
61 | case STRTOG_NoNumber:\r | |
62 | case STRTOG_Zero:\r | |
63 | u.L[0] = 0;\r | |
64 | break;\r | |
65 | \r | |
66 | case STRTOG_Normal:\r | |
67 | case STRTOG_NaNbits:\r | |
68 | u.L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23);\r | |
69 | break;\r | |
70 | \r | |
71 | case STRTOG_Denormal:\r | |
72 | u.L[0] = bits[0];\r | |
73 | break;\r | |
74 | \r | |
75 | case STRTOG_Infinite:\r | |
76 | u.L[0] = 0x7f800000;\r | |
77 | break;\r | |
78 | \r | |
79 | case STRTOG_NaN:\r | |
80 | u.L[0] = f_QNAN;\r | |
81 | }\r | |
82 | if (k & STRTOG_Neg)\r | |
83 | u.L[0] |= 0x80000000L;\r | |
84 | return u.f;\r | |
85 | }\r |