Debian Codegraph @

texk/lcdf-typetools/lcdf-typetools-src/liblcdf/strtonum.c

raw
1 /* -*- related-file-name: "../include/lcdf/strtonum.h" -*- */
2 #ifdef HAVE_CONFIG_H
3 # include <config.h>
4 #endif
5 #include <lcdf/strtonum.h>
6 #include <stdlib.h>
7 #if HAVE_BROKEN_STRTOD
8 # define strtod good_strtod
9 #endif
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 /* A faster strtod which only calls the real strtod if the string has a
15 fractional part. */
16
17 double
18 strtonumber(const char *f, char **endf)
19 {
20 long v = strtol((char *)f, endf, 10);
21
22 /* handle any possible decimal part */
23 if (**endf == '.' || **endf == 'E' || **endf == 'e')
24 return strtod((char *)f, endf);
25 else
26 return v;
27 }
28
29 #ifdef __cplusplus
30 }
31 #endif