powers in code? like 2^X - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: powers in code? like 2^X (
/showthread.php?tid=65364)
powers in code? like 2^X -
fredl - 11.02.2009
i want to know how to make a "power"(math.)(internet translation) with 2 variables
is it possible?
Re: powers in code? like 2^X -
[RP]Rav - 11.02.2009
Код:
// base^power
// for example
if (2^3 == 8)
// always true
new base = 2, power = 3;
if (base^power == 8)
// also, always true
a function.. not really needed but oh well
Код:
stock pow(base,power) // works for positive powers only
{
for (power; power > 1; power--)
base *= base;
return base;
}
Re: powers in code? like 2^X -
fredl - 11.02.2009
i need no if sentences i need something like
var[playerid] = 3000 ^ lvl[playerid]
Re: powers in code? like 2^X -
fredl - 11.02.2009
and a 3000^0.2 says something like 12747292 or so and that cant be true!
Re: powers in code? like 2^X -
Simon - 11.02.2009
The symbol ^ is XOR (exclusive or). You'll have to use the function floatpower (float.inc) or the pow function posted above (there's an alternative function named 'power' on page 70 of pawn-lang.pdf).
Re: powers in code? like 2^X -
[RP]Rav - 11.02.2009
hmm, my bad (sorry)
Re: powers in code? like 2^X -
fredl - 12.02.2009
a floatpower(2,3( = 8 istn it! i need something like floatpower(50,0.2) but that doesnt work
Re: powers in code? like 2^X -
[RP]Rav - 12.02.2009
floatpower Raise a floating point number to a power
Syntax: Float: floatpower(Float: value, Float: exponent)
Returns: The result: value; this is a floating point value.
http://www.compuphase.com/pawn/amxfloat.pdf
make sure that you do this though
Код:
new Float:result;
result = floatpower(50, 0.2);
Re: powers in code? like 2^X -
fredl - 12.02.2009
Код:
new float:hm;
hm = floatpower(50.0, 0.2);
printf("%d",hm);
console says: 1074525002
and maybe i am wrong but i dont think that 50^0.2 is that result!!!!
Re: powers in code? like 2^X -
[RP]Rav - 12.02.2009
use
that'll fix your problem