Alguien puede decirme que operación es exactamente esta??
x**2
Pertenece a este código:
[code]# x**2 - a = 0
# calcula la raiz cuadrada y se le puede especificar la precision, es decir
# la cota superior del error del resultado
def Math.my_sqrt(a, precision)
x = 1
oldx=1
iter = 0
# newton raphson
while 1
oldx = x
x = x - ( x**2 - a ) / ( 2 * x)
break if (oldx-x).abs < precision
end
x
end
def show( code )
print "#{code} => #{eval(code)}\n"
end
show "Math.my_sqrt(2.0, 0.5)"
show "Math.my_sqrt(2.0, 0.05)"
show "Math.my_sqrt(2.0, 0.005)"
show "Math.my_sqrt(2.0, 0.0005)"
show "Math.sqrt(2.0)"[/code]
Alguien entiende algo de RUBY?
- erkosone
- Posts: 10656
- Joined: Tue Feb 24, 2009 2:13 pm
- Location: Barcelona.
- Contact:
- necro_vampire
- Posts: 1372
- Joined: Fri Oct 10, 2008 12:38 am
- Location: Death Soul city???
- Contact:
Re: Alguien entiende algo de RUBY?
es una potencia
x**2 = x*x = pow(x,2)
x**3 = x*x*x = pow(x,3)
x**2 = x*x = pow(x,2)
x**3 = x*x*x = pow(x,3)

Rein (K´)ah Al-Ghul
Infected with the Krieger strain of the Human-MetaHuman Vampiric Virus.
- erkosone
- Posts: 10656
- Joined: Tue Feb 24, 2009 2:13 pm
- Location: Barcelona.
- Contact:
Re: Alguien entiende algo de RUBY?
Muchas gracias necro.
http://iphonegamesdev.com/
[GEMIX - VIDEO TUTORIALES] http://www.youtube.com/user/fasetconasa
http://gurugameprogramming.blogspot.com.es/
[GEMIX - VIDEO TUTORIALES] http://www.youtube.com/user/fasetconasa
http://gurugameprogramming.blogspot.com.es/