I'm currently trying to use angelscript with a simple code, following the official website's examples.
But when i try to initialise a double variable like below in my script :
double x=1/2;
the variable x appears to be initialised with the value 0.
It only works when i write double x=1/2.0; or double x=1.0/2;
Does it exist a way to make angelscript work in double precision when i type double x=1/2 without adding any more code in the script ?
Thank you,
That's because
1and2are integers, and:Would be 0. If
xis actually a double, you get an implicit cast conversion:Which means
1/2 = 0becomes0.0. Notice that is not the same as:Which will do what you want.
Numbers with decimals are doubles, and dividing an int by a double produces a double. You can also do this with casting each number:
Which is handy if
1and2are actually int variables -- by casting this way, their value will be converted to a double before the division, so the product will be a double.