ZHCU876Z July 2001 – October 2023 SM320F28335-EP
以下方法提供了对 C/C++ 语言中 16 位乘法的上 16 位的访问:
int m1, m2;
int result;
result = ((long) m1 * (long) m2) >> 16;
unsigned m1, m2;
unsigned result;
result = ((unsigned long) m1 * (unsigned long) m2) >> 16;
编译器必须识别表达式的结构才能返回预期结果。避免使用复杂的表达式,如以下示例:
((long)((unsigned)((a*b)+c)<5)*(long)(z*sin(w)>6))>>16