1.整数函数分为三类来讨论;加法运算和减法运算,乘法运算,以及其余类型的函数。在各种整数函数的运算中,integer数据类型指代范围包含有符号整数和无符号整数:uchar,char,ushort,short,uint,int,ulong和long.uinteger型指代范围仅仅是无符号整数:uchar,ushort,uint和ulong.
2.加法和减法函数:
(1)integern add_sat(integern x,integern y)--返回的x+y,饱和结果;
(2)integern hadd(integern x, integern y)--返回的x+y,结果右移一位,防止溢出;
(3)integern rhadd(integern x,integern y)--返回x+y+1,结果右移一位,防止溢出;
(4)integern sub_sat(integern x,integern y)--返回x-y,饱和结果。
考虑的问题:计算结果占用的空间大于操作数所占的空间,这种情况也被称为算数溢出。
如果对两个有符号正整数求和,结果大于最大值时,溢出的发生将会导致返回值为负值。但是add_sat和sub_sat这两个函数会在上溢出发生时,将饱和结果返回,也就是直接返回所能表示的最大值。以32位int型为例,最大值返回将是0x7FFFFFFF.
3.乘法运算:整数相乘所得到的结果也会比操作数需要更多的存储空间,最差的情况就是乘积所要的空间是操作数的两倍。
(1)integern mad_hi(integern a,integern b, integern c)