I've recently been looking into AngelScript for use in an upcoming project. I have found what appears to be an integer overflow issue during certain math operation in the script. Consider the following:uint64 mynum;
mynum = 2147483647 + 1;
print("mynum = " + mynum);
This results in the ouput:mynum = 18446744071562067968
If I set mynum with a simple assignment mynum = 2147483648;
, the behaviour is what I would expect:mynum = 2147483648
The issue appears to happen when only literal numbers are used in a math operation and they are interpreted as int32 regardless of the type being assigned. If a uint64 variable is part of the math or at least one of the values is cast to uint64, then the problem goes away. Here are a few variants I tried:mynum = uint64(2147483647) + 1;
- Works
mynum = 0;
mynum = mynum + 2147483647 + 1;
- Works
mynum = 0;
mynum += 2147483647 + 1;
- Overflow
Didn't test it out, but floating point math may have a similar issue. While I can easily work around the overflow issue now that I know about it, I would argue that this should be considered a bug. The overflow condition is not obvious and I could see bizarre/hard to diagnose problems emerging if you do not write your script in a way to avoid the overflow.
Other than that, I do want to say that I'm really liking the language and I am finding a lot of things are easier to do than in other embeddable languages I've used. Thus far I've been able to locate code examples in the add_ons and samples source to get me over any difficulties I've encountered trying to understand the API. Overall, it's been real solid.