SA-MP Forums Archive
Integer square root? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Integer square root? (/showthread.php?tid=493182)



Integer square root? - kristo - 07.02.2014

Hi, I just need a define that gets the square root of an integer.


What i've already tried:
pawn Код:
#define sqrt(%0) _:(floatsqroot(Float:%0)) // returned random huge numbers

#define sqrt(%0) floatround(floatsqroot(Float:%0)) // always returns 0
Thanks!


Re: Integer square root? - Konstantinos - 07.02.2014

Just use:
pawn Код:
floatsqroot(number);
and the output is a float.


Re: Integer square root? - kristo - 07.02.2014

But I need it to return an integer, too. Wait, got an idea...


Re: Integer square root? - Konstantinos - 07.02.2014

https://sampwiki.blast.hk/wiki/Floats#Float_-.3E_Integer


Re: Integer square root? - kristo - 07.02.2014

Got it working. Simpler than it seemed to be. Thanks!

pawn Код:
#define sqrt(%0) floatround(floatsqroot(%0))



Re: Integer square root? - ACI - 07.02.2014

EDIT: Didn't noticed that it was solved.