Merge pull request #10269 from terfendail:softdouble_round

This commit is contained in:
Alexander Alekhin
2017-12-11 12:48:03 +00:00
3 changed files with 233 additions and 1 deletions
@@ -401,6 +401,9 @@ CV_EXPORTS int cvTrunc(const cv::softdouble& a);
CV_EXPORTS int cvRound(const cv::softfloat& a);
CV_EXPORTS int cvRound(const cv::softdouble& a);
/** @brief Rounds a number to nearest even long long integer */
CV_EXPORTS int64_t cvRound64(const cv::softdouble& a);
/** @brief Rounds a number down to integer */
CV_EXPORTS int cvFloor(const cv::softfloat& a);
CV_EXPORTS int cvFloor(const cv::softdouble& a);
@@ -430,12 +433,18 @@ template<> inline short saturate_cast<short>(softdouble a) { return (short)std::
template<> inline int saturate_cast<int>(softfloat a) { return cvRound(a); }
template<> inline int saturate_cast<int>(softdouble a) { return cvRound(a); }
/** @brief Saturate cast to unsigned integer
template<> inline int64_t saturate_cast<int64_t>(softfloat a) { return cvRound(a); }
template<> inline int64_t saturate_cast<int64_t>(softdouble a) { return cvRound64(a); }
/** @brief Saturate cast to unsigned integer and unsigned long long integer
We intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
*/
template<> inline unsigned saturate_cast<unsigned>(softfloat a) { return cvRound(a); }
template<> inline unsigned saturate_cast<unsigned>(softdouble a) { return cvRound(a); }
template<> inline uint64_t saturate_cast<uint64_t>(softfloat a) { return cvRound(a); }
template<> inline uint64_t saturate_cast<uint64_t>(softdouble a) { return cvRound64(a); }
/** @brief Min and Max functions */
inline softfloat min(const softfloat& a, const softfloat& b) { return (a > b) ? b : a; }
inline softdouble min(const softdouble& a, const softdouble& b) { return (a > b) ? b : a; }