# Cordic nutiplicar e dividir: esquema simples

x=34567.5895
y=0

z=7324567.2511234

psmult<-function(x,z){
y=0
ix=0
while (2^ix<abs(x)){ix=ix+1}
iz=0
while (2^iz<abs(z)){iz=iz+1}
for ( i in (-max(abs(ix),abs(iz))+1):40){ # Multiplica x*z
d=sign(z)
y=y+d*x/(2^i)
print(y,digits=22)
z=z-d/(2^i)
if ( abs(z)<2^(-20)){ break}
}
return(y)}
print("x="); x 
print("z");z 
print("Multiplicando x*z");p=psmult(x,z); print("Resultado"); p



#---- Observe a magnitude dos números. Note que 2^8=256.
x=34567.5895

z=0

y=7324567.2511234

psdiv<-function(x,y){
z=0
ix=0
while (2^ix<abs(x)){ix=ix+1}
iz=0
while (2^iz<abs(z)){iz=iz+1}
for ( i in (-(ix+iz)):40){ # Divide y por x

d=-sign(x)*sign(y)
y=y+d*x/(2^i)
z=z-d/(2^i)
}
return(z)}
print("x=");x 
print("y="); y 
print("Dividindo y/x");q=psdiv(x,y);print("Resultado"); q 

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: