powers in code? like 2^X
#1

i want to know how to make a "power"(math.)(internet translation) with 2 variables
is it possible?
Reply
#2

Код:
// 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;
}
Reply
#3

i need no if sentences i need something like

var[playerid] = 3000 ^ lvl[playerid]
Reply
#4

and a 3000^0.2 says something like 12747292 or so and that cant be true!
Reply
#5

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).
Reply
#6

hmm, my bad (sorry)
Reply
#7

a floatpower(2,3( = 8 istn it! i need something like floatpower(50,0.2) but that doesnt work
Reply
#8

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);
Reply
#9

Код:
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!!!!
Reply
#10

use

Код:
printf("%f", hm);
that'll fix your problem
Reply


Forum Jump:


Users browsing this thread: