diff --git a/src/pugixml.cpp b/src/pugixml.cpp index aa8296e..e487c85 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -5338,6 +5338,13 @@ namespace pugi return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); } + PUGI__FN bool xml_attribute::set_value(double rhs) + { + if (!_attr) return false; + + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision); + } + PUGI__FN bool xml_attribute::set_value(double rhs, int precision) { if (!_attr) return false; @@ -5345,6 +5352,13 @@ namespace pugi return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, precision); } + PUGI__FN bool xml_attribute::set_value(float rhs) + { + if (!_attr) return false; + + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision); + } + PUGI__FN bool xml_attribute::set_value(float rhs, int precision) { if (!_attr) return false; diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 0226524..6a79cae 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -263,8 +263,8 @@ namespace pugi // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. const unsigned int format_default = format_indent; - const unsigned int default_double_precision = 17; - const unsigned int default_float_precision = 9; + const int default_double_precision = 17; + const int default_float_precision = 9; // Forward declarations struct xml_attribute_struct; @@ -412,8 +412,10 @@ namespace pugi bool set_value(unsigned int rhs); bool set_value(long rhs); bool set_value(unsigned long rhs); - bool set_value(double rhs, int precision=default_double_precision); - bool set_value(float rhs, int precision=default_float_precision); + bool set_value(double rhs); + bool set_value(double rhs, int precision); + bool set_value(float rhs); + bool set_value(float rhs, int precision); bool set_value(bool rhs); #ifdef PUGIXML_HAS_LONG_LONG diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index ebeabe1..0c4e564 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -1771,6 +1771,11 @@ TEST(dom_fp_double_custom_precision) attr.set_value(std::numeric_limits::min(), 20); CHECK(fp_equal(attr.as_double(), std::numeric_limits::min())); + attr.set_value(1.0f, 5); + CHECK(fp_equal(attr.as_double(), static_cast(1.0f))); + attr.set_value(3.1415926f, 3); + CHECK(!fp_equal(attr.as_double(), static_cast(3.1415926f))); + node.text().set(std::numeric_limits::max()); CHECK(fp_equal(node.text().as_double(), std::numeric_limits::max())); }