Skip to content

Commit 5407287

Browse files
committed
fix strtod indentation and mention it in LICENSE.md
ref #5988
1 parent 028a4b1 commit 5407287

File tree

2 files changed

+79
-89
lines changed

2 files changed

+79
-89
lines changed

LICENSE.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Julia includes code from the following projects, which have their own licenses:
3535
- [MUSL](http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT) (for getopt implementation on Windows) [MIT]
3636
- [MINGW](https://sourceforge.net/p/mingw/mingw-org-wsl/ci/legacy/tree/mingwrt/mingwex/dirname.c) (for dirname implementation on Windows) [MIT]
3737
- [NetBSD](http://www.netbsd.org/about/redistribution.html) (for setjmp, longjmp, and strptime implementations on Windows) [BSD-3]
38+
- [Python](https://docs.python.org/2/license.html) (for strtod implementation on Windows) [BSD-3, effectively]
3839
- [randmtzig.c](https://github.com/JuliaLang/julia/blob/master/test/perf/micro/randmtzig.c) for Gaussian random number generation (for C benchmarks only) [BSD-3]
3940

4041
The Julia language links to the following external libraries, which have their

src/support/strtod.c

+78-89
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@ static locale_t c_locale;
2020

2121
locale_t get_c_locale(void)
2222
{
23-
if(!c_locale_initialized)
24-
{
25-
c_locale_initialized = 1;
26-
c_locale = newlocale(LC_ALL_MASK, "C", NULL);
27-
}
28-
return c_locale;
23+
if (!c_locale_initialized) {
24+
c_locale_initialized = 1;
25+
c_locale = newlocale(LC_ALL_MASK, "C", NULL);
26+
}
27+
return c_locale;
2928
}
3029

3130
JL_DLLEXPORT double jl_strtod_c(const char *nptr, char **endptr)
3231
{
33-
return strtod_l(nptr, endptr, get_c_locale());
32+
return strtod_l(nptr, endptr, get_c_locale());
3433
}
3534

3635
JL_DLLEXPORT float jl_strtof_c(const char *nptr, char **endptr)
3736
{
38-
return strtof_l(nptr, endptr, get_c_locale());
37+
return strtof_l(nptr, endptr, get_c_locale());
3938
}
4039

4140

@@ -58,7 +57,7 @@ JL_DLLEXPORT float jl_strtof_c(const char *nptr, char **endptr)
5857

5958
int case_insensitive_match(const char *s, const char *t)
6059
{
61-
while(*t && tolower(*s) == *t) {
60+
while (*t && tolower(*s) == *t) {
6261
s++;
6362
t++;
6463
}
@@ -147,84 +146,75 @@ JL_DLLEXPORT double jl_strtod_c(const char *nptr, char **endptr)
147146
}
148147

149148
/* This code path is used for hex floats */
150-
if (*p == '0' && (*(p+1) == 'x' || *(p+1) == 'X'))
151-
{
152-
digits_pos = p;
153-
p += 2;
154-
/* Check that what's left begins with a digit or decimal point */
155-
if (!isxdigit(*p) && *p != '.')
156-
goto invalid_string;
157-
158-
159-
if (decimal_point[0] != '.' ||
160-
decimal_point[1] != 0)
161-
{
162-
/* Look for a '.' in the input; if present, it'll need to be
163-
swapped for the current locale's decimal point before we
164-
call strtod. On the other hand, if we find the current
165-
locale's decimal point then the input is invalid. */
166-
while (isxdigit(*p))
167-
p++;
168-
169-
if (*p == '.')
170-
{
171-
decimal_point_pos = p++;
172-
173-
/* locate end of number */
174-
while (isxdigit(*p))
175-
p++;
176-
177-
if (*p == 'p' || *p == 'P')
178-
p++;
179-
if (*p == '+' || *p == '-')
180-
p++;
181-
while (isdigit(*p))
182-
p++;
183-
end = p;
184-
}
185-
else if (strncmp(p, decimal_point, decimal_point_len) == 0)
186-
goto invalid_string;
187-
/* For the other cases, we need not convert the decimal
188-
point */
189-
}
190-
} else
191-
{
192-
/* Check that what's left begins with a digit or decimal point */
193-
if (!isdigit(*p) && *p != '.')
194-
goto invalid_string;
195-
196-
digits_pos = p;
197-
if (decimal_point[0] != '.' ||
198-
decimal_point[1] != 0)
199-
{
200-
/* Look for a '.' in the input; if present, it'll need to be
201-
swapped for the current locale's decimal point before we
202-
call strtod. On the other hand, if we find the current
203-
locale's decimal point then the input is invalid. */
204-
while (isdigit(*p))
205-
p++;
206-
207-
if (*p == '.')
208-
{
209-
decimal_point_pos = p++;
210-
211-
/* locate end of number */
212-
while (isdigit(*p))
213-
p++;
214-
215-
if (*p == 'e' || *p == 'E')
216-
p++;
217-
if (*p == '+' || *p == '-')
218-
p++;
219-
while (isdigit(*p))
220-
p++;
221-
end = p;
222-
}
223-
else if (strncmp(p, decimal_point, decimal_point_len) == 0)
149+
if (*p == '0' && (*(p+1) == 'x' || *(p+1) == 'X')) {
150+
digits_pos = p;
151+
p += 2;
152+
/* Check that what's left begins with a digit or decimal point */
153+
if (!isxdigit(*p) && *p != '.')
154+
goto invalid_string;
155+
156+
157+
if (decimal_point[0] != '.' || decimal_point[1] != 0) {
158+
/* Look for a '.' in the input; if present, it'll need to be
159+
swapped for the current locale's decimal point before we
160+
call strtod. On the other hand, if we find the current
161+
locale's decimal point then the input is invalid. */
162+
while (isxdigit(*p))
163+
p++;
164+
165+
if (*p == '.') {
166+
decimal_point_pos = p++;
167+
168+
/* locate end of number */
169+
while (isxdigit(*p))
170+
p++;
171+
172+
if (*p == 'p' || *p == 'P')
173+
p++;
174+
if (*p == '+' || *p == '-')
175+
p++;
176+
while (isdigit(*p))
177+
p++;
178+
end = p;
179+
}
180+
else if (strncmp(p, decimal_point, decimal_point_len) == 0)
181+
goto invalid_string;
182+
/* For the other cases, we need not convert the decimal point */
183+
}
184+
}
185+
else {
186+
/* Check that what's left begins with a digit or decimal point */
187+
if (!isdigit(*p) && *p != '.')
224188
goto invalid_string;
225-
/* For the other cases, we need not convert the decimal
226-
point */
227-
}
189+
190+
digits_pos = p;
191+
if (decimal_point[0] != '.' || decimal_point[1] != 0) {
192+
/* Look for a '.' in the input; if present, it'll need to be
193+
swapped for the current locale's decimal point before we
194+
call strtod. On the other hand, if we find the current
195+
locale's decimal point then the input is invalid. */
196+
while (isdigit(*p))
197+
p++;
198+
199+
if (*p == '.') {
200+
decimal_point_pos = p++;
201+
202+
/* locate end of number */
203+
while (isdigit(*p))
204+
p++;
205+
206+
if (*p == 'e' || *p == 'E')
207+
p++;
208+
if (*p == '+' || *p == '-')
209+
p++;
210+
while (isdigit(*p))
211+
p++;
212+
end = p;
213+
}
214+
else if (strncmp(p, decimal_point, decimal_point_len) == 0)
215+
goto invalid_string;
216+
/* For the other cases, we need not convert the decimal point */
217+
}
228218
}
229219

230220
if (decimal_point_pos) {
@@ -263,7 +253,6 @@ JL_DLLEXPORT double jl_strtod_c(const char *nptr, char **endptr)
263253
}
264254

265255
free(copy);
266-
267256
}
268257
else {
269258
val = strtod(digits_pos, &fail_pos);
@@ -278,7 +267,7 @@ JL_DLLEXPORT double jl_strtod_c(const char *nptr, char **endptr)
278267

279268
return val;
280269

281-
invalid_string:
270+
invalid_string:
282271
*endptr = (char*)nptr;
283272
errno = EINVAL;
284273
return -1.0;
@@ -287,7 +276,7 @@ JL_DLLEXPORT double jl_strtod_c(const char *nptr, char **endptr)
287276

288277
JL_DLLEXPORT float jl_strtof_c(const char *nptr, char **endptr)
289278
{
290-
return (float) jl_strtod_c(nptr, endptr);
279+
return (float) jl_strtod_c(nptr, endptr);
291280
}
292281

293282
#endif

0 commit comments

Comments
 (0)