How to use coder.unroll in a while loop
1 view (last 30 days)
Life is Wonderful on 16 Aug 2022
I'm looking for a sample code of how to use "coder. unroll" in a while loop. I intend to perform a division operation and want to unroll the loop if I achieve the required accuracy level.
format long g
a = (4);
b = (6);
T = numerictype('Signed', true,...
quotient = divide(T,a,b)
and I want to stop the division process when a certain fractional bit accuracy, say 0.6667, is reached.
Walter Roberson on 16 Aug 2022
coder.unroll() by itself cannot do that. coder,unroll() always unrolls the number of times given in the for loop. The loop limits do not need to be constant inside the function being unrolled, but if not then during the code generation phase, the limit must be given as a numeric constant. If you had two different limits that you wanted to unroll to, then you would have to generate code twice, once for each limit.