diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp
index 8e32b0fbee09ac861eaef528133aa9f4d0efccdc..57abffc3ca52c8620bfde23dc1514744c59eb5bf 100644
--- a/modules/core/src/matrix.cpp
+++ b/modules/core/src/matrix.cpp
@@ -3439,7 +3439,7 @@ ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a)
     if( a.m != b.m )
         return INT_MAX;
     if( a.sliceEnd == b.sliceEnd )
-        return (b.ptr - a.ptr)/b.elemSize;
+        return (b.ptr - a.ptr)/static_cast<ptrdiff_t>(b.elemSize);
 
     return b.lpos() - a.lpos();
 }