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,
David Ranieri :
Using some macro chicanery:\n\n#include <stdio.h>\n\n#define DIV * 1.0 / \n\nint main(void)\n{\n double x = 1 DIV 2;\n\n printf(\"%f\\n\", x);\n return 0;\n}\n\n\nDIV can also be defined as:\n\n#define DIV / (double)\n",
2013-09-03T08:51:58
verbose :
When you divide an int by an int, the result is an int. The quotient is the result, the remainder is discarded. Here, 1 / 2 yields a quotient of zero and a remainder of 1. If you need a double, try 1.0 / 2.\n\nNo, there is no way to get a double by dividing two ints without casting the result. ",
2013-09-03T08:22:29