Chameleon

Chameleon Svn Source Tree

Root/branches/valv/branch/i386/libsa/strtod.c

  • Property svn:executable set to
1/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
2
3This library is free software; you can redistribute it and/or modify
4it under theterms of the GNU General Public License as published
5by the Free Software Foundation; either version 2, or (at your option)
6any later version.
7
8This library is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with GNU CC; see the file COPYING. If not, write to
15the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17As a special exception, if you link this library with files
18compiled with a GNU compiler to produce an executable, this does not cause
19the resulting executable to be covered by the GNU General Public License.
20This exception does not however invalidate any other reasons why
21the executable file might be covered by the GNU General Public License. */
22
23#include "libsa.h"
24
25extern double atof ();
26
27double strtod (nptr, enptr)
28char *nptr;
29char **enptr;
30{
31char *p;
32
33if (enptr == (char **)0)
34return atof (nptr);
35
36p = nptr;
37
38while (isspace (*p))
39++p;
40
41if (*p == '+' || *p == '-')
42++p;
43
44/* INF or INFINITY. */
45if ((p[0] == 'i' || p[0] == 'I')
46&& (p[1] == 'n' || p[1] == 'N')
47&& (p[2] == 'f' || p[2] == 'F'))
48{
49if ((p[3] == 'i' || p[3] == 'I')
50&& (p[4] == 'n' || p[4] == 'N')
51&& (p[5] == 'i' || p[5] == 'I')
52&& (p[6] == 't' || p[6] == 'T')
53&& (p[7] == 'y' || p[7] == 'Y'))
54{
55*enptr = p + 7;
56return atof (nptr);
57}
58else
59{
60*enptr = p + 3;
61return atof (nptr);
62}
63}
64
65/* NAN or NAN(foo). */
66if ((p[0] == 'n' || p[0] == 'N')
67&& (p[1] == 'a' || p[1] == 'A')
68&& (p[2] == 'n' || p[2] == 'N'))
69{
70p += 3;
71if (*p == '(')
72{
73++p;
74while (*p != '\0' && *p != ')')
75++p;
76if (*p == ')')
77++p;
78}
79*enptr = p;
80return atof (nptr);
81}
82
83/* digits, with 0 or 1 periods in it. */
84if (isdigit (*p) || *p == '.')
85{
86int got_dot = 0;
87while (isdigit (*p) || (!got_dot && *p == '.'))
88{
89if (*p == '.')
90got_dot = 1;
91++p;
92}
93
94/* Exponent. */
95if (*p == 'e' || *p == 'E')
96{
97int i;
98i = 1;
99if (p[i] == '+' || p[i] == '-')
100++i;
101if (isdigit (p[i]))
102{
103while (isdigit (p[i]))
104++i;
105*enptr = p + i;
106return atof (nptr);
107}
108}
109*enptr = p;
110return atof (nptr);
111}
112/* Didn't find any digits. Doesn't look like a number. */
113*enptr = nptr;
114return 0.0;
115}
116

Archive Download this file

Revision: 661