1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| function grdrfin=arrondouf(grdr,pas,offset)
quotient=fix(grdr/abs(pas));
surplus=grdr-quotient*abs(pas);
boucle=0;
surplusprim=surplus;
if surplusprim<10 && surplusprim>=1;
elseif surplusprim>10; while surplusprim>10; surplusprim=surplusprim/10; boucle=boucle+1; end
elseif surplusprim<1; while surplusprim~=fix(surplusprim); surplusprim=surplusprim*10; boucle=boucle-1; end
end
['boucle ' num2str(boucle,3)]
['quotient ' num2str(quotient,20)]
['surplus ' num2str(surplus,20)]
['surplusprim ' num2str(surplusprim,20)]
['R(surplus) ' num2str(roundn(surplus,log10(10^boucle)))]
['(pas/2) ' num2str(pas/2,20)]
['R(pas/2) ' num2str(roundn(pas/2,log10(10^(boucle-sign(boucle)))),20)]
if abs(roundn(surplus,log10(10^boucle)))>=roundn(laylaylay,log10(10^boucle)); grdr=quotient*abs(pas)+sign(grdr)*abs(pas);
else grdr=quotient*abs(pas);
end
grdrfin=grdr+offset; |