Assistance Needed: Variable type used in ambiguous code.

Hello,

I am going through a book concerning physics simulation and gradually porting
is to AS3.

My problem is that the variable type is being called in the code, and I have no
idea what it does:

Function:

1
2
3
4
5
6
7
8
9
/** Turns a non-zero vector into a vector of unit length. */
void normalize()
{
real l = magnitude();
if (l > 0)
{
(*this)*=((real)1)/l;
}
}


Line in question:

(*this)*=((real)1)/l;

I know that 'real' is simply the data type (it's defined as a float elsewhere
in the code,) but how C++ treats it, I have no idea.

Any help would be much appreciated.

On a side note, I am currently trying to learn C++ as well but AS3 has been
giving me a good grasp on OOP basics for now, memory management and
pointers are a large headache right now and I figured developing flash games
in the meantime would expand my general knowledge.

Great community and site you got here, archaic looking, but wonderful in it's
simplicity.

-DGM
Last edited on

If real is defined as a float than real will also act like a float. Also, the class and the 'this' pointer will also be acting like a real number which looks from the code.
Lets say magnitude will return 3.14, so this is going to assign 1/3.14 to the 'this' pointer. There must be a '*=' operator written in the class to handle this and surely it will multiply the data in the this pointer with 1/3.14.

I don't know if this is what you question is!!
Thanks for the reply, and sorry about not being clearer, what would just 'real' by itself do?

As it reads to me: this = this * (??? * 1) / l;

No idea on the ??? part. Does (real) have a numerical equivalent?

--Edit

Sorry I'm not able to put two and two together right now...

Wait, is '(real)1' simply defining '1' as a 'real'-type number?
Last edited on

real when defined as a float will act as a datatype like int, char, double etc.

(real)1 is actually typecasting 1 to act like a real (or float). But this is not necessary as even if you don't typecast, it will implicitly be type casted into a float.
Thank you very much!

Now I wonder why all my Googling was fruitless... Nonetheless, that answers my question.
Take a book on C like "The C programming language" and start reading and all this will be clear.
Exercises are important.
Topic archived. No new replies allowed.