Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Langford <jl@hunch.net>2012-06-21 02:24:57 +0400
committerJohn Langford <jl@hunch.net>2012-06-21 02:24:57 +0400
commit5ba0c15e112b14f9afb0c30680c7c11dc343b0ca (patch)
treea6023eea721b8d8d3a47375594a69124fe39ba17 /vowpalwabbit/parse_primitives.h
parenta572a38b66b4348717fd18d8b90bc243a6ab0277 (diff)
tweaked float parser to have strtof semantics but raw speed as Michael Radford suggests
Diffstat (limited to 'vowpalwabbit/parse_primitives.h')
-rw-r--r--vowpalwabbit/parse_primitives.h71
1 files changed, 39 insertions, 32 deletions
diff --git a/vowpalwabbit/parse_primitives.h b/vowpalwabbit/parse_primitives.h
index 73afc3ae..de09119d 100644
--- a/vowpalwabbit/parse_primitives.h
+++ b/vowpalwabbit/parse_primitives.h
@@ -108,42 +108,49 @@ inline void print_substring(substring s)
// in charge of error detection.
inline float parseFloat(char * p, char **end)
{
- if (!*p || *p == '?')
- return 0;
- int s = 1;
- while (*p == ' ') p++;
-
+ char* start = p;
+
+ if (!*p)
+ return 0;
+ int s = 1;
+ while (*p == ' ') p++;
+
+ if (*p == '-') {
+ s = -1; p++;
+ }
+
+ double acc = 0;
+ while (*p >= '0' && *p <= '9')
+ acc = acc * 10 + *p++ - '0';
+
+ int num_dec = 0;
+ if (*p == '.') {
+ p++;
+ while (*p >= '0' && *p <= '9') {
+ acc = acc *10 + (*p++ - '0') ;
+ num_dec++;
+ }
+ }
+ int exp_acc = 0;
+ if(*p == 'e' || *p == 'E'){
+ p++;
+ int exp_s = 1;
if (*p == '-') {
- s = -1; p++;
+ exp_s = -1; p++;
}
-
- double acc = 0;
while (*p >= '0' && *p <= '9')
- acc = acc * 10 + *p++ - '0';
-
- int num_dec = 0;
- if (*p == '.') {
- p++;
- while (*p >= '0' && *p <= '9') {
- acc = acc *10 + (*p++ - '0') ;
- num_dec++;
- }
- }
- int exp_acc = 0;
- if(*p == 'e' || *p == 'E'){
- p++;
- int exp_s = 1;
- if (*p == '-') {
- exp_s = -1; p++;
- }
- while (*p >= '0' && *p <= '9')
- exp_acc = exp_acc * 10 + *p++ - '0';
- exp_acc *= exp_s;
-
+ exp_acc = exp_acc * 10 + *p++ - '0';
+ exp_acc *= exp_s;
+
+ }
+ if (*p == ' ')//easy case succeeded.
+ {
+ acc *= pow(10,exp_acc-num_dec);
+ *end = p;
+ return s * acc;
}
- acc *= pow(10,exp_acc-num_dec);
- *end = p;
- return s * acc;
+ else
+ return strtof(start,end);
}
inline float float_of_substring(substring s)