diff options
author | John Langford <jl@hunch.net> | 2012-08-03 19:02:41 +0400 |
---|---|---|
committer | John Langford <jl@hunch.net> | 2012-08-03 19:02:41 +0400 |
commit | 4c961a7401b8372c30d5304b92ea6ca0a131ee2b (patch) | |
tree | b9d0cbe46928ea2ed7e213b4958215268309680a /vowpalwabbit/parse_primitives.h | |
parent | 551d33f3559fd729f5787d15af971891935a674d (diff) |
NaN sanity check on parse
Diffstat (limited to 'vowpalwabbit/parse_primitives.h')
-rw-r--r-- | vowpalwabbit/parse_primitives.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/vowpalwabbit/parse_primitives.h b/vowpalwabbit/parse_primitives.h index 3dc1edfb..80ea521f 100644 --- a/vowpalwabbit/parse_primitives.h +++ b/vowpalwabbit/parse_primitives.h @@ -153,13 +153,15 @@ inline float parseFloat(char * p, char **end) return strtod(start,end); } +inline bool nanpattern( float value ) { return ((*(uint32_t*)&value) & 0x7fffffff) > 0x7f800000; } + inline float float_of_substring(substring s) { char* endptr = s.end; float f = parseFloat(s.begin,&endptr); - if (endptr == s.begin && s.begin != s.end) + if ((endptr == s.begin && s.begin != s.end) || nanpattern(f)) { - std::cout << "error: " << std::string(s.begin, s.end-s.begin).c_str() << " is not a float" << std::endl; + std::cout << "warning: " << std::string(s.begin, s.end-s.begin).c_str() << " is not a good float, replacing with 0" << std::endl; f = 0; } return f; |