From ad338d3e46eac0d0277a7000c48972d47f6c0091 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 9 Jan 2012 01:44:01 +0100 Subject: Another try at fixing double-to-text conversion for testing diff --git a/src/value.cc b/src/value.cc index c9440ae..47fac1e 100644 --- a/src/value.cc +++ b/src/value.cc @@ -368,11 +368,17 @@ std::string Value::toString() const // across platforms for testing purposes. { std::stringstream tmp; - tmp.precision(16); + tmp.precision(12); tmp.setf(std::ios_base::fixed); tmp << this->num; std::string tmpstr = tmp.str(); - if (tmpstr.size() > 16) tmpstr.erase(16); + size_t endpos = tmpstr.find_last_not_of('0'); + if (endpos >= 0 && tmpstr[endpos] == '.') endpos--; + tmpstr = tmpstr.substr(0, endpos+1); + size_t dotpos = tmpstr.find('.'); + if (dotpos != std::string::npos) { + if (tmpstr.size() - dotpos > 12) tmpstr.erase(dotpos + 12); + } stream << tmpstr; } #else diff --git a/testdata/scad/functions/inf-tests.scad b/testdata/scad/functions/inf-tests.scad new file mode 100644 index 0000000..87b6823 --- /dev/null +++ b/testdata/scad/functions/inf-tests.scad @@ -0,0 +1,23 @@ +echo(1/0); +echo(-1/0); +echo(sin(1/0)); +echo(cos(1/0)); +echo(tan(1/0)); +echo(asin(1/0)); +echo(acos(1/0)); +echo(atan(1/0)); +echo(atan(-1/0)); +echo(atan2(1/0, -1/0)); +echo(ceil(1/0)); +echo(floor(1/0)); +echo(exp(2, 1/0)); +echo(ln(1/0)); +echo(log(1/0)); +echo(max(-1/0, 1/0)); +echo(min(-1/0, 1/0)); +echo(pow(2, 1/0)); +echo(round(1/0)); +echo(sign(1/0)); +echo(sign(-1/0)); +echo(sqrt(1/0)); +echo(sqrt(-1/0)); \ No newline at end of file diff --git a/testdata/scad/misc/inf-tests.scad b/testdata/scad/misc/inf-tests.scad deleted file mode 100644 index 87b6823..0000000 --- a/testdata/scad/misc/inf-tests.scad +++ /dev/null @@ -1,23 +0,0 @@ -echo(1/0); -echo(-1/0); -echo(sin(1/0)); -echo(cos(1/0)); -echo(tan(1/0)); -echo(asin(1/0)); -echo(acos(1/0)); -echo(atan(1/0)); -echo(atan(-1/0)); -echo(atan2(1/0, -1/0)); -echo(ceil(1/0)); -echo(floor(1/0)); -echo(exp(2, 1/0)); -echo(ln(1/0)); -echo(log(1/0)); -echo(max(-1/0, 1/0)); -echo(min(-1/0, 1/0)); -echo(pow(2, 1/0)); -echo(round(1/0)); -echo(sign(1/0)); -echo(sign(-1/0)); -echo(sqrt(1/0)); -echo(sqrt(-1/0)); \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e2f5699..6a3b432 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -600,8 +600,7 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES} ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/builtin-tests.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/dim-all.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-test.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/inf-tests.scad) + ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/string-indexing.scad) list(APPEND DUMPTEST_FILES ${MINIMAL_FILES} ${FEATURES_FILES} ${EXAMPLE_FILES}) list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test.scad) diff --git a/tests/regression/echotest/builtin-tests-expected.txt b/tests/regression/echotest/builtin-tests-expected.txt index 0e8d1a7..385b0dc 100644 --- a/tests/regression/echotest/builtin-tests-expected.txt +++ b/tests/regression/echotest/builtin-tests-expected.txt @@ -1 +1 @@ -ECHO: 3.14159265358979 +ECHO: 3.14159265359 diff --git a/tests/regression/echotest/dim-all-expected.txt b/tests/regression/echotest/dim-all-expected.txt index d8c3269..60f36d5 100644 --- a/tests/regression/echotest/dim-all-expected.txt +++ b/tests/regression/echotest/dim-all-expected.txt @@ -1,16 +1,16 @@ WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: linearX = 51.4495755427526 +ECHO: linearX = 51.44957554275 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: linearY = 29.1302546743484 +ECHO: linearY = 29.13025467434 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: aligned = 60.0000000000000 +ECHO: aligned = 60 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: ordinateX = -49.175424457247 +ECHO: ordinateX = -49.17542445724 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: ordinateY = 30.8697453256515 +ECHO: ordinateY = 30.86974532565 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. ECHO: radius = 60 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. ECHO: diameter = 120 WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'. -ECHO: arc = 59.0362434679264 +ECHO: arc = 59.03624346792 diff --git a/tests/regression/echotest/inf-tests-expected.txt b/tests/regression/echotest/inf-tests-expected.txt index adac240..7ac4fe9 100644 --- a/tests/regression/echotest/inf-tests-expected.txt +++ b/tests/regression/echotest/inf-tests-expected.txt @@ -1,13 +1,13 @@ ECHO: inf ECHO: -inf -ECHO: -nan -ECHO: -nan -ECHO: -nan ECHO: nan ECHO: nan -ECHO: 90.0000000000000 -ECHO: -90.000000000000 -ECHO: 135.000000000000 +ECHO: nan +ECHO: nan +ECHO: nan +ECHO: 90 +ECHO: -90 +ECHO: 135 ECHO: inf ECHO: inf ECHO: undef @@ -17,7 +17,7 @@ ECHO: inf ECHO: -inf ECHO: inf ECHO: inf -ECHO: 1.00000000000000 -ECHO: -1.0000000000000 +ECHO: 1 +ECHO: -1 ECHO: inf -ECHO: -nan +ECHO: nan diff --git a/tests/regression/echotest/parser-tests-expected.txt b/tests/regression/echotest/parser-tests-expected.txt index fb04907..615726a 100644 --- a/tests/regression/echotest/parser-tests-expected.txt +++ b/tests/regression/echotest/parser-tests-expected.txt @@ -2,4 +2,4 @@ ECHO: 0.1 ECHO: 2 ECHO: 1100 ECHO: 0.021 -ECHO: 1.1e-13 +ECHO: 0 -- cgit v0.10.1