Qt下常用的数值计算(绝对值qAbs,最大qMax,最小qMin,开根号Sqrt,N次方是pow,断言宏Q_ASSERT和Q_ASSERT_X )

来源:互联网 发布:青岛知行国际真实么 编辑:IT博客网 时间:2019/07/20 17:10

TqAbs(constT &value)

Comparesvalue to the 0 of type T and returns the absolute value. Thus if T isdouble, thenvalue is compared to(double) 0.

Example:

  int absoluteValue;
  int myValue = -4;
  absoluteValue = qAbs(myValue);
  // absoluteValue == 4

constT &qMax(constT &value1, constT &value2)

Returns the maximum ofvalue1 andvalue2.

Example:

  int myValue = 6;
  int yourValue = 4;
  int maxValue = qMax(myValue, yourValue);
  // maxValue == myValue

const T &qMin(const T &value1, const T &value2)

Returns the minimum ofvalue1 andvalue2.

Example:

  int myValue = 6;
  int yourValue = 4;
  int minValue = qMin(myValue, yourValue);
  // minValue == yourValue



开根号Sqrt(),比如Sqrt(100) = 10。pow(2,3) = 8


1、 void Q_ASSERT ( bool test )
当test为假时打印出警告信息。
2、void Q_ASSERT_X ( bool test, const char * where, const char * what )
当test为假时打印出警告信息,警告信息中包含自定义信息。
举例说明:
int test(int a, int b)  
{  
Q_ASSERT_X(b != 0, "test", "test by zero");  
return a / b;  
}  


                                             
0 0