Alguien entiende algo de RUBY?

Todo aquello que no está relacionado con Gemix Studio ni con la programación DIV en general.

Alguien entiende algo de RUBY?

Postby erkosone » Sun Dec 09, 2012 5:05 pm

Alguien puede decirme que operación es exactamente esta??
x**2

Pertenece a este código:

Source Code (Ruby) [ Download ] [ Hide ]
  • # 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)"
User avatar
erkosone
 
Posts: 10654
Joined: Tue Feb 24, 2009 2:13 pm
Location: Barcelona.

Re: Alguien entiende algo de RUBY?

Postby necro_vampire » Sun Dec 09, 2012 5:16 pm

es una potencia
x**2 = x*x = pow(x,2)
x**3 = x*x*x = pow(x,3)
Image
Rein (K´)ah Al-Ghul
Infected with the Krieger strain of the Human-MetaHuman Vampiric Virus.
User avatar
necro_vampire
 
Posts: 1372
Joined: Fri Oct 10, 2008 12:38 am
Location: Death Soul city???

Re: Alguien entiende algo de RUBY?

Postby erkosone » Sun Dec 09, 2012 5:20 pm

Muchas gracias necro.
User avatar
erkosone
 
Posts: 10654
Joined: Tue Feb 24, 2009 2:13 pm
Location: Barcelona.


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 1 guest

cron