diff --git a/src/codecs2/field_codec_default.h b/src/codecs2/field_codec_default.h index 4e2914f0..5127f097 100644 --- a/src/codecs2/field_codec_default.h +++ b/src/codecs2/field_codec_default.h @@ -129,12 +129,22 @@ namespace dccl // allowable epsilon for min / max to diverge from nearest quantile const double min_max_eps = 1e-10; - + bool min_multiple_of_res = std::abs(quantize(min(), resolution()) - min()) < min_max_eps; + bool max_multiple_of_res = std::abs(quantize(max(), resolution()) - max()) < min_max_eps; if(FieldCodecBase::dccl_field_options().has_resolution()) { // ensure that max and min are multiples of the resolution chosen - FieldCodecBase::require(std::abs(quantize(min(), resolution()) - min()) < min_max_eps, "(dccl.field).min must be an exact multiple of (dccl.field).resolution"); - FieldCodecBase::require(std::abs(quantize(max(), resolution()) - max()) < min_max_eps, "(dccl.field).max must be an exact multiple of (dccl.field).resolution"); + FieldCodecBase::require(min_multiple_of_res, "(dccl.field).min must be an exact multiple of (dccl.field).resolution"); + FieldCodecBase::require(max_multiple_of_res, "(dccl.field).max must be an exact multiple of (dccl.field).resolution"); + } + else + { + auto res = resolution(); + // this was previously allowed so we will only give a warning not throw an exception + if(!min_multiple_of_res) + dccl::dlog.is(dccl::logger::WARN, dccl::logger::GENERAL) && dccl::dlog << "Warning: (dccl.field).min should be an exact multiple of 10^(-(dccl.field).precision), i.e. " << res << ": " << this->this_field()->DebugString() << std::endl; + if(!max_multiple_of_res) + dccl::dlog.is(dccl::logger::WARN, dccl::logger::GENERAL) && dccl::dlog << "Warning: (dccl.field).max should be an exact multiple of 10^(-(dccl.field).precision), i.e. " << res << ": " << this->this_field()->DebugString() << std::endl; } // ensure value fits into double diff --git a/src/test/dccl_resolution/test.cpp b/src/test/dccl_resolution/test.cpp index ba8acc17..8064e72c 100644 --- a/src/test/dccl_resolution/test.cpp +++ b/src/test/dccl_resolution/test.cpp @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) msg_in.set_u3(10.2); msg_in.set_u4(5.6); msg_in.set_u5(1.95); - msg_in.set_u6(100); + msg_in.set_u6(25500); std::string encoded; codec.encode(&encoded, msg_in); diff --git a/src/test/dccl_resolution/test.proto b/src/test/dccl_resolution/test.proto index 8a4560c7..49f0936f 100644 --- a/src/test/dccl_resolution/test.proto +++ b/src/test/dccl_resolution/test.proto @@ -56,7 +56,7 @@ message NumericMsg // old precision field did not require min and max to be a multiple of resolution required int32 u6 = 8 [ (dccl.field).min = 0, - (dccl.field).max = 16383, + (dccl.field).max = 25599, (dccl.field).precision = -2 ]; }