gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > type transformation

#5158 - twillinx - Tue Apr 22, 2003 1:57 pm

Code:

float temp = 0;
temp = ((-4/2)-((4/2)^2-7)^0.5);
ypos = (int)temp;


And here comes the error message:
invalid operands of types 'int' and 'double' to binary 'operator^'

It doesn't work using static_cast either.

To make things clear: "s16 ypos = 130;", I'm using the gba.h-register, and the s16 is defined as an int.

I'm using GCC.

I would appreciate to know how to get around this problem.

#5159 - niltsair - Tue Apr 22, 2003 2:29 pm

There's no floating point on the GBA.

You'll have to use another technique, like creating a special class storing the decimals and the full number as 2 integers, and do you calculating in accordance.

#5160 - Touchstone - Tue Apr 22, 2003 2:31 pm

I take it you're not familiar with the bitwise exclusive OR operator, "^". Are you trying to calculate a value raised to the power of another value? In that case use the pow() function.
Code:
temp = pow(2, 32);
instead of
Code:
temp = 2^32;

But maybe there are other ways to do what ever you are trying to do?
_________________
You can't beat our meat