Potęgowanie do Gothic 2 NK (możliwe, że w G1 też podziała) 2798 1

O temacie

Autor Bogdan Zwei

Zaczęty 6.03.2015 roku

Wyświetleń 2798

Odpowiedzi 1

Bogdan Zwei

Bogdan Zwei

Użytkownicy
Wulgarny skurwiel pierdolony.
posty1864
Propsy541
Profesjabrak
  • Użytkownicy
  • Wulgarny skurwiel pierdolony.
Ostatnio mi się strasznie nudziło, tak więc zrobiłem sobie funkcję potęgowania.
Wszystko jest opisane (po angielsku, ponieważ ludzie zza granicy także tutaj uczęszczają), tak więc nie powinno być pytań. A z resztą, funkcja działa, była testowana liczbami 2^3 oraz 40^5, wszystko działa rewelacyjnie.

X = liczba do wymnożenia
Y = potęga

UWAGA!!!: Gothic nie pokaże wam poprawnego wyniku, jeśli wynosi on więcej niż 999 999 999 (to chyba wiecie).
Jeśli czegoś nie zrozumiecie z mojego słabego inglisza, to można pytać. :P

func int e^ (var int x, var int y) // Why the name is "e^"? Simple, exponentiation is for example 2^2
{
var int PotatoRotations; PotatoRotations = 0;
var int EndCount;

if (x == 0) { return false; }; // 0*0 = 0...
if (x == 1) { return true; }; // 1*1*1*1*1*1*1*1*1*1*1*1*1*1 = 1...

if (y == 1)
{
return x;
}
else if (y == 0)
{
return false;
}
else
{
EndCount = x * x;
};

var int stckpos; stckpos = MEM_StackPos.position;

if ((PotatoRotations) < (y-2)) /*NOTE: EndCount is soon x*x, and if it'd be y-1, the EndCount would be x^(y+1)
if x would be 2, and y 3, this'd be: EndCount = 4; and then if (0 < 1) [PotatoRotations < y] { EndCount = EndCount*x }
and now y == PotatoRotations, so the EndCount is now 8 (2^3) :)*/
{
EndCount = EndCount * x;
PotatoRotations += 1;
MEM_StackPos.position = stckpos;
};

return EndCount;
};
 
:ok: zachęca do dalszej pomocy. Nie zapominaj o tym!

Prywatne wiadomości typu "Ej, pomocy" kasuję od razu. Od tego jest forum, a nie PW.

To me, defeat in anything is merely temporary, and its punishment is but an urge for me to greater effort to achieve my goal. Defeat simply tells me that something is wrong in my doing; it is a path leading to success and truth.

In order to realize our true self we must be willing to live without being dependent upon the opinion of others.

chicken

chicken

RaveN Studio
posty1230
Propsy559
ProfesjaNierób
  • RaveN Studio
Mało przydatne i słabo przejrzysty kod.
Nazwy zmiennych nie mające sensu oraz nazwa funkcji nieadekwatna.
func int pow(var int val, var int count)
{
   const int counter = count;

   if (val == 1) { return 1; };
   if (val == 0) { return 0; };

   if (count == 1) { return val; };
   if (count == 0) { return 1; };

   while(!counter);
      val *= val;
      counter -= 1;
   end;
   return val;
};

Mniej więcej.


0 użytkowników i 2 gości przegląda ten wątek.
0 użytkowników
Do góry