]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /* $NetBSD: strtopx.c,v 1.3.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 "gdtoaimp.h"\r | |
36 | \r | |
37 | #undef _0\r | |
38 | #undef _1\r | |
39 | \r | |
40 | /* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */\r | |
41 | \r | |
42 | #ifdef IEEE_BIG_ENDIAN\r | |
43 | #define _0 0\r | |
44 | #define _1 1\r | |
45 | #define _2 2\r | |
46 | #define _3 3\r | |
47 | #define _4 4\r | |
48 | #endif\r | |
49 | #ifdef IEEE_LITTLE_ENDIAN\r | |
50 | #define _0 4\r | |
51 | #define _1 3\r | |
52 | #define _2 2\r | |
53 | #define _3 1\r | |
54 | #define _4 0\r | |
55 | #endif\r | |
56 | \r | |
57 | int\r | |
58 | #ifdef KR_headers\r | |
59 | strtopx(s, sp, V) CONST char *s; char **sp; void *V;\r | |
60 | #else\r | |
61 | strtopx(CONST char *s, char **sp, void *V)\r | |
62 | #endif\r | |
63 | {\r | |
64 | static CONST FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };\r | |
65 | ULong bits[2];\r | |
66 | Long expt;\r | |
67 | int k;\r | |
68 | UShort *L = (UShort*)V;\r | |
69 | \r | |
70 | k = strtodg(s, sp, &fpi, &expt, bits);\r | |
71 | if (k == STRTOG_NoMemory)\r | |
72 | return k;\r | |
73 | switch(k & STRTOG_Retmask) {\r | |
74 | case STRTOG_NoNumber:\r | |
75 | case STRTOG_Zero:\r | |
76 | L[0] = L[1] = L[2] = L[3] = L[4] = 0;\r | |
77 | break;\r | |
78 | \r | |
79 | case STRTOG_Denormal:\r | |
80 | L[_0] = 0;\r | |
81 | goto normal_bits;\r | |
82 | \r | |
83 | case STRTOG_Normal:\r | |
84 | case STRTOG_NaNbits:\r | |
85 | L[_0] = (UShort)(expt + 0x3fff + 63);\r | |
86 | normal_bits:\r | |
87 | L[_4] = (UShort)bits[0];\r | |
88 | L[_3] = (UShort)(bits[0] >> 16);\r | |
89 | L[_2] = (UShort)bits[1];\r | |
90 | L[_1] = (UShort)(bits[1] >> 16);\r | |
91 | break;\r | |
92 | \r | |
93 | case STRTOG_Infinite:\r | |
94 | L[_0] = 0x7fff;\r | |
95 | L[_1] = L[_2] = L[_3] = L[_4] = 0;\r | |
96 | break;\r | |
97 | \r | |
98 | case STRTOG_NaN:\r | |
99 | L[0] = ldus_QNAN0;\r | |
100 | L[1] = ldus_QNAN1;\r | |
101 | L[2] = ldus_QNAN2;\r | |
102 | L[3] = ldus_QNAN3;\r | |
103 | L[4] = ldus_QNAN4;\r | |
104 | }\r | |
105 | if (k & STRTOG_Neg)\r | |
106 | L[_0] |= 0x8000;\r | |
107 | return k;\r | |
108 | }\r |