Mon, 01 Jul 2013 17:27:37 +0300
Added an atof overload to convert from string to float, hopefully without any precision error
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions |
--- a/src/file.cpp Thu Jun 27 14:55:32 2013 +0300 +++ b/src/file.cpp Mon Jul 01 17:27:37 2013 +0300 @@ -570,15 +570,11 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -static vertex parseVertex (QStringList& s, const ushort n) { - // Disable the locale while parsing the line or atof's behavior changes - // between locales (i.e. fails to read decimals properly). That is - // quite undesired... - setlocale (LC_NUMERIC, "C"); - +static vertex parseVertex( QStringList& s, const ushort n ) +{ vertex v; - for (const Axis ax : g_Axes) - v[ax] = s[n + ax].toFloat (); + for( const Axis ax : g_Axes ) + v[ax] = atof( s[n + ax] ); return v; }
--- a/src/misc.cpp Thu Jun 27 14:55:32 2013 +0300 +++ b/src/misc.cpp Mon Jul 01 17:27:37 2013 +0300 @@ -249,6 +249,23 @@ return list.join (delim); } +double atof( str val ) +{ + // Disable the locale while parsing the line or atof's behavior changes + // between locales (i.e. fails to read decimals properly). That is + // quite undesired... + setlocale( LC_NUMERIC, "C" ); + char* buf = new char[val.length()]; + char* bufptr = &buf[0]; + + for( qchar& c : val ) + *bufptr++ = c.toAscii(); + *bufptr = '\0'; + + double fval = atof( buf ); + delete[] buf; + return fval; +} // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *