Skip to content

Commit

Permalink
Don't use fixed format for doubles. Use default format with significant
Browse files Browse the repository at this point in the history
precision.
  • Loading branch information
abellgithub committed Oct 7, 2015
1 parent df3c502 commit 8ba8dae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
19 changes: 15 additions & 4 deletions include/pdal/util/Utils.hpp
Expand Up @@ -43,6 +43,7 @@
#include <stdexcept>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <istream>
#include <limits>
#include <cstring>
Expand Down Expand Up @@ -382,13 +383,23 @@ namespace Utils
std::string toString(const T& from)
{
std::ostringstream oss;
oss << std::fixed << from;
oss << from;
return oss.str();
}

// There is an overload of std::to_string() for float and double, but
// its behavior is different from streaming and doesn't match what
// we have been doing historically.
inline std::string toString(double from)
{
std::ostringstream oss;
oss << std::setprecision(10) << from;
return oss.str();
}

inline std::string toString(float from)
{
std::ostringstream oss;
oss << std::setprecision(8) << from;
return oss.str();
}

inline std::string toString(long long from)
{ return std::to_string(from); }
Expand Down
31 changes: 7 additions & 24 deletions test/unit/MetadataTest.cpp
Expand Up @@ -283,30 +283,13 @@ TEST(MetadataTest, sanitize)
}
**/

TEST(MetadataTest, test_metadata_stage)
// Make sure that we handle double-precision values to 10 decimal places.
TEST(MetadataTest, test_float)
{
//ABELL
/**
PointTable table;
LasReader reader(Support::datapath("interesting.las"));
reader.prepare(table);
MetadataNode file_metadata = table->metadata();
MetadataNode n("top");
MetadataNode n2 = n.add("test", 1e-20);
EXPECT_DOUBLE_EQ(n2.value<double>(), 1e-20);

EXPECT_EQ(file_metadata.toPTree().get_child("metadata").size(),
32);
PointTable readerTable;
PipelineManager mgr;
PipelineReader specReader(mgr);
specReader.readPipeline(
Support::datapath("pipeline/pipeline_metadata_reader.xml"));
std::shared_ptr<Stage> stage(mgr.getStage());
stage->prepare(readerTable);
MetadataNode pipeline_metadata = readerTable->metadata();
EXPECT_EQ(
pipeline_metadata.toPTree().get_child("metadata").size(), 32);
**/
n2 = n.add("test2", 1.12345678);
EXPECT_DOUBLE_EQ(n2.value<double>(), 1.12345678);
}

0 comments on commit 8ba8dae

Please sign in to comment.