File: strtonum.c

package info (click to toggle)
lcdf-typetools 2.92%2Bdfsg1-0.1
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,884 kB
  • sloc: cpp: 34,407; ansic: 2,106; sh: 1,032; makefile: 306
file content (31 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* -*- related-file-name: "../include/lcdf/strtonum.h" -*- */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <lcdf/strtonum.h>
#include <stdlib.h>
#if HAVE_BROKEN_STRTOD
# define strtod good_strtod
#endif
#ifdef __cplusplus
extern "C" {
#endif

/* A faster strtod which only calls the real strtod if the string has a
   fractional part. */

double
strtonumber(const char *f, char **endf)
{
  long v = strtol((char *)f, endf, 10);

  /* handle any possible decimal part */
  if (**endf == '.' || **endf == 'E' || **endf == 'e')
    return strtod((char *)f, endf);
  else
    return v;
}

#ifdef __cplusplus
}
#endif