i using library loading wavefront .obj files opengl application (tinyobjloader). noticed there error when loading objects. when load object coordinate of eg. 0.9999999 set 0. debugging found out following method produces behaviour:
static inline float parsefloat(const char*& token) { token += strspn(token, " \t"); float f = (float)atof(token); token += strcspn(token, " \t\r"); return f; } so atof() returns somehow int, not float. read compilers don't throw warning when using atof() without including "stdlib.h" , result atof() returns integer.
the curious thing if include "stdlib.h" error remains. can't figure out causes behaviour.
any idea?
the standard says atof:
except behaviour on error, equivalent strtod(nptr,(char**)null)
so yours returning '0' has nothing float not being able represent or similar.
would use strtod instead (which should when stringstreams not option, able report errors), notice stops parsing @ ..
this strong indication using locale awaits , instead of . s decimal separator. depending on how application works locales, might want run set environment variable (e.g. lc_numeric=c) or setlocale(lc_numeric,"c"); before parsing.
in case should analyze in application using locale dependent things, , for, not collide them. possible route require locale dependent input everywhere, needs give numbers , decimal separator.
Comments
Post a Comment