本帖最后由 非凡378159128 于 2016-6-12 09:55 编辑
请教关于2个32位变量软件实现64位变量的算法
static uint32_t bmp280_compensate_pressure_int64(struct bmp280 *bmp280, int32_t adc_P)
{
int64_t var1, var2, pressure;
var1 = ((int64_t)bmp280->t_fine) - 128000;
var2 = var1 * var1 * (int64_t)dig_P6;
var2 = var2 + ((var1*(int64_t)dig_P5)<<17);
var2 = var2 + (((int64_t)dig_P4)<<35);
var1 = ((var1 * var1 * (int64_t)dig_P3)>>8) + ((var1 * (int64_t)dig_P2)<<12);
var1 = (((((int64_t)1)<<47)+var1))*((int64_t)dig_P1)>>33;
if (var1 == 0)
{
return 0; // avoid exception caused by division by zero
}
pressure = 1048576-adc_P;
pressure = (((pressure<<31)-var2)*3125)/var1;
var1 = (((int64_t)dig_P9) * (pressure>>13) * (pressure>>13)) >> 25;
var2 = (((int64_t)dig_P8) * pressure) >> 19;
pressure = ((pressure + var1 + var2) >> 8) + (((int64_t)dig_P7)<<4);
return (uint32_t)pressure;
}
以上程序在iar stm32上运行正常,但是在iar stm8上不支持64位的变量
看到下面这个帖子说可以用两个32位变量软件实现64位的计算,但是不知道具体实现方法,望知道的大神告知一下,不胜感激
https://bbs.21ic.com/icview-1390432-1-1.html
|