From 99c666691e3cd47a69219a5e8df14a2c3bac09ab Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Sun, 21 Oct 2012 11:20:39 +0400 Subject: [PATCH] Restore core multiply/divide depth to CV_64F value. After setting depth to CV_32F for non double types this produces difference in results. I've attached test that reproduce this issue.The issue was found during anali broken GPU tests for multiply/device functions. --- modules/core/src/arithm.cpp | 2 +- modules/core/test/test_arithm.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 66d979f..0fa306c 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1281,7 +1281,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, depth2 = CV_32F; } else - depth2 = src1.depth() < CV_32S || src1.depth() == CV_32F ? CV_32F : CV_64F; + depth2 = CV_64F; } int cn = src1.channels(), depth1 = src1.depth(), wtype; diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 875b849..43120cf 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -1522,4 +1522,12 @@ protected: TEST(Core_ArithmMask, uninitialized) { CV_ArithmMaskTest test; test.safe_run(); } +TEST(Multiply, FloatingPointRounding) +{ + cv::Mat src(1, 1, CV_8UC1, cv::Scalar::all(110)), dst; + cv::Scalar s(147.286359696927, 1, 1 ,1); + cv::multiply(src, s, dst, 1, CV_16U); + // with CV_32F this produce result 16202 + ASSERT_EQ(dst.at(0,0), 16201); +} \ No newline at end of file -- 2.7.4