|
我在某個(gè).c文件中定義了一個(gè)float函數(shù),在函數(shù)內(nèi)設(shè)置斷點(diǎn)查看return運(yùn)算結(jié)果是正確的,但我在另一個(gè).c文件中引用這個(gè)函數(shù)給某個(gè)變量賦值時(shí),變量的值就錯(cuò)誤了。感覺像是cubeide的浮點(diǎn)運(yùn)算設(shè)置問題,已經(jīng)開啟了cubeide的支持浮點(diǎn)運(yùn)算和sprintf的選項(xiàng)。
這個(gè)是浮點(diǎn)函數(shù)的運(yùn)行結(jié)果,我在函數(shù)內(nèi)設(shè)置斷點(diǎn)查看,計(jì)算運(yùn)行是正確的 Name : value Details:4.37491322 Default:4.37491322 Decimal:1082916682 Hex:0x408bff4a Binary:1000000100010111111111101001010 Octal:010042777512 這個(gè)是引用函數(shù)賦值后得到的錯(cuò)誤結(jié)果,通過引用函數(shù)賦值之后得到的變量直接飛了,引用函數(shù)后得到的結(jié)果是錯(cuò)誤的 Name : mid_angle Details:1.08291674e+009 Default:1.08291674e+009 Decimal:1317083135 Hex:0x4e8117ff Binary:1001110100000010001011111111111 Octal:011640213777 我確保函數(shù)類型和賦值的類型一致,都是float,且代碼在keil中編譯運(yùn)行沒問題,在cubeide中未改動(dòng)代碼,但函數(shù)傳遞值時(shí)就錯(cuò)了,不知道咋解決 floatgetAngle11(void)
{
float angle_data,d_angle,value;angle_data = I2C_getRawCount();// tracking the number of rotations // in order to expand angle range form [0,2PI] to basically infinityd_angle = angle_data - angle_data_prev;// if overflow happened track it as full rotationif(fabs(d_angle) > (0.8*cpr) ) full_rotation_offset += d_angle > 0 ? -_2PI : _2PI; // save the current angle value for the next steps// in order to know if overflow happenedangle_data_prev = angle_data;// return the full angle // (number of full rotations)*2PI + current sensor angle value=(full_rotation_offset + ( angle_data / (float)cpr) * _2PI);return value ;
} 引用時(shí)是這樣的 volatilefloat mid_angle,end_angle; mid_angle=getAngle11(); 感覺是cubeide的浮點(diǎn)設(shè)置問題,我之前開啟了支持浮點(diǎn)數(shù)編譯和打印的設(shè)置,不知道還有啥浮點(diǎn)數(shù)問題
|
|