Qt中qRound的实现,在负数的情况下不同于一般的四舍五入。如果负数尾数<=.5的情况下,则舍弃尾数。(注意,=的情况下也舍弃o) 如果负数尾数 >0.5的情况下,则负小数整数部分-1。
Q_DECL_CONSTEXPR inline int qRound(double d)
{ return d >= 0.0 ? int(d + 0.5) : int(d - double(int(d-1)) + 0.5) + int(d-1); }
/**
* Qt中通过模板获取qptrdiff的类型
* TODO: 知识点:我能力有限,暂时不清楚模板应用底层原理。
* 通过模板参数直接获取相关类型
* 似乎与工厂设计模式有些相近(只是个人理解,如有误请留言指正)
*/
template <int> struct QIntegerForSize;
template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };
template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
template <class