Is rsqrt the same as Fast inverse square root?

조회 수: 66(최근 30일)
Hongbo Zhu
Hongbo Zhu 2021년 9월 13일
댓글: Hongbo Zhu 2021년 9월 16일
Hello,
I would like to us sqrt() and run it on a embeded controller. I was wondering sqrt() is the same as Fast inverse square root (https://en.wikipedia.org/wiki/Fast_inverse_square_root). if not, is it efficent as Fast inverse square root. Does it support code generation? Can I use it in embeded control software?
Thanks,
Hongbo
  댓글 수: 4
Hongbo Zhu
Hongbo Zhu 2021년 9월 13일
@Rik Thank you very much for your quick response and explanation. It will be great if someone from MathWork can confirm rsqrt() is efficient for embeded control system.

댓글을 달려면 로그인하십시오.

채택된 답변

stozaki
stozaki 2021년 9월 13일
Hi,
The Simulink sqrt block supports rsqrt.
The algorithm is Newton-Raphson, so it can be considered the same as the one described on the wiki.
With that setting, C code generation is possible.
  댓글 수: 1
Hongbo Zhu
Hongbo Zhu 2021년 9월 16일
@stozaki Great! Thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Jan
Jan 2021년 9월 13일
i = * ( long * ) &y
This is equivalent to:
y = single(pi);
i = typecast(y, 'int32');
The shown code of Q_rsqrt is an approximation of 1/sqrt(x) for single precision floating point values. It might have a fair speed on CPUs without a floating point unit, but it is less accurate then the direct calculation.
  댓글 수: 1
Hongbo Zhu
Hongbo Zhu 2021년 9월 13일
Hi @Jan, Thank you very much. I noticed there is also a simulink block named Float Typecast. Does it supported by code generation for embeded controller?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by