Quote:
Originally Posted by shades13
so e.g. 1 become 1.0 to make sure it is calculated as a double, even when the variable type is specified as a double?
|
Yes, this can be a potential issue.
For example :
Code:
int x = 10;
int y = 11;
double z = x/y; // this is *not* going be 0.909090 or so, it will be 0
C++ calculates the expressions on the right of the = first, using the types those variables have. It doesn't first look what is the type of the variable you are assigning the result to. In the above example, the division is done as integers, resulting in 0 and then that is assigned to the double.
You can use a cast like this to force the calculation to happen as floating point :
Code:
int x = 10;
int y = 11;
double z = (double)x/y;
Or of course, by just using floating point variables to begin with. (If you are using numeric literals, then yes, you should use 1.0 instead of 1 and so on.)
Other possible issue when converting EEl/JesuSonic code to C++ could be that errors might be handled differently when calling the numerical functions or doing arithmetic. Eel might for example return 0.0 for calculations that in C++ will cause the result to be inf(inity) or nan (not-a-number). Justin could probably explain if there are any possible issues like that. (But if such cases exist, then the original JesuSonic plugin code was kind of wrong to begin with...)