说明:这是一个整数开方函数,返回结果也是整数。
问题:用51单片机采集ADC,交流电,然后进行均方根求有效值,开方调用 #include <math.h> float sqrt (float val); 开方是浮点运算。
有些时候我们要开方的数据是整数,需要的结果也是整数,如果调用数学库自带的开方函数(参数返回值均是 浮点数)处理速度较慢,程序在这个地方停顿的时间比较长。
参考连接 https://blog.csdn.net/weixin_44212493/article/details/104330540
/*
/Function: 开根号处理 /
/入口参数:被开方数,长整型 /
/出口参数:开方结果,整型 /
/
*/
unsigned int sqrt_16(unsigned long M)
{
unsigned int N, i;
unsigned