diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-02-16 01:42:45 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-02-16 01:42:45 (GMT) |
commit | 61a4fc30317717769240602095af531a7e297fa2 (patch) | |
tree | d4c6cf50dc176180d36e6c24ab5320ea68ff9698 | |
parent | 5138dca395adb11753080017361d69abb82666a1 (diff) |
solve some floating point comparison issues in multmatrix dump().
also indent some stuff properly
-rw-r--r-- | src/transform.cc | 4 | ||||
-rw-r--r-- | src/value.cc | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/transform.cc b/src/transform.cc index d94e0d4..b01827f 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -190,8 +190,8 @@ std::string TransformNode::toString() const for (int j=0;j<4;j++) { stream << "["; for (int i=0;i<4;i++) { - // FIXME: The 0 test is to avoid a leading minus before a single 0 (cosmetics) - stream << two_digit_exp_format((this->matrix(j, i)==0)?0:this->matrix(j, i)); + Value v( this->matrix(j, i) ); + stream << v; if (i != 3) stream << ", "; } stream << "]"; diff --git a/src/value.cc b/src/value.cc index 98a7eca..46b7e6f 100644 --- a/src/value.cc +++ b/src/value.cc @@ -186,10 +186,11 @@ public: if (op1 != op1) { // Fix for avoiding nan vs. -nan across platforms return "nan"; } + double tmpop = ( op1 == 0 ) ? 0 : op1; // Fix '-0' to '0' std::stringstream tmp; tmp.precision(12); tmp.setf(std::ios_base::fixed); - tmp << op1; + tmp << tmpop; std::string tmpstr = tmp.str(); size_t endpos = tmpstr.find_last_not_of('0'); if (endpos >= 0 && tmpstr[endpos] == '.') endpos--; @@ -197,16 +198,17 @@ public: size_t dotpos = tmpstr.find('.'); if (dotpos != std::string::npos) { if (tmpstr.size() - dotpos > 12) tmpstr.erase(dotpos + 12); + while (tmpstr[tmpstr.size()-1] == '0') tmpstr.erase(tmpstr.size()-1); } tmpstr = two_digit_exp_format( tmpstr ); return tmpstr; #else - // attempt to emulate Qt's QString.sprintf("%g"); from old OpenSCAD. - // see https://github.com/openscad/openscad/issues/158 - std::stringstream tmp; - tmp.unsetf(std::ios::floatfield); - tmp << op1; - return tmp.str(); + // attempt to emulate Qt's QString.sprintf("%g"); from old OpenSCAD. + // see https://github.com/openscad/openscad/issues/158 + std::stringstream tmp; + tmp.unsetf(std::ios::floatfield); + tmp << op1; + return tmp.str(); #endif } |