single precision mode and difference between Matlab and cortex-m

2 ビュー (過去 30 日間)
mohammad.H Bagherian
mohammad.H Bagherian 2021 年 5 月 31 日
コメント済み: Jan 2021 年 6 月 1 日
Hi,
I have a kallman function that it wrote in double precision and I want to convert it to single precision, is there a normal way?
I find out I have to use Single Fcn but I think if I wrote Single Fcn for every vector it's really weird.
But why I want to use single-precision!!! I should implement this filter on stm32f4 with DSP CMSIS and compare data!
another question is that why there is a difference between float in stm32f4 and single in Matlab?
let's assume a variable
>>a=0.06;
>>x=single(a);
single
0.0600
but in microcontroller
float a=0.06;
when I watch a:
0.0599999986

採用された回答

Jan
Jan 2021 年 5 月 31 日
編集済み: Jan 2021 年 5 月 31 日
This is the expected behaviour.
There is not exact representation of 0.06 in IEEE 754 32 bit floating point numbers, neither in Matlab nor in C. See:
a = single(0.06)
fprintf('%.16g', a)
>> 0.05999999865889549
% 0.0599999986 % From your output
The 0.06 displayed my Matlab is a rounded output.
"is there a normal way?" - It is hard to guess, what you call "normal". Matlab's default type is double, so if you want single precision, you have to include the corresponding command.
  2 件のコメント
mohammad.H Bagherian
mohammad.H Bagherian 2021 年 6 月 1 日
thanks for your share,
i think a normal ways is one line command to change precision. for example write
precision single
or somthing simlar to it... is there any command?
Jan
Jan 2021 年 6 月 1 日
No, not in Matlab.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by