I tried yesterday to perform some easy algorythms and when I use parameters in trigger action for doing my calculations, I have many errors. I tried this : I multiply 86400 by 50000 and I divide it by 30 and it's fine, but if i have a parameter that is equal to 30 and I divide by it, it returns in bad answer. (86400 is the number of seconds in a 24 hours day)
Do somebody know why? Does it happen because of rounded numbers?
You may want to reformulate your question. If I understand you correctly, you are saying that if you simply do 86400 * 50000 / 30, it doesn't have any issues, but if you do 86400 * 50000 / psomevar, with psomevar equal to 30, it throws an error?
@ Funky, I wonder the same as well, SC2 uses fixed point data types, so it has 19 bits for non fractional parts. However, I do not know the max value for ints, I would presume they are simply signed ints, which gives us up to 2 billion to work with, which 50000 * 86400 = 4.32 billion goes right over, even for unsigned ints. So the error that is arising is sign overflow perhaps? Unless of course, the compiler is seeing 86400 * 50000 / 30 and doing the division first, to prevent overflow in the intermediary calculation. This would work perfectly fine, since the resulting division would be fixed point withing the correct bounds, and the subsequent multiplication would be in bounds.
TL:DR, doing a raw number calculation can work, because the game can do the calculation out of order, but with variables, it can not, so it causes an error.
Yes, thanks for the reply, I did the division first and it works fine. I just asked the question to avoid doing the same error twice. And when I do 86400 * 50000 / 30, it works, but if I replace 30 by an action parameter (example : lp_integer) who also have 30 as a value, it returns in an error.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I tried yesterday to perform some easy algorythms and when I use parameters in trigger action for doing my calculations, I have many errors. I tried this : I multiply 86400 by 50000 and I divide it by 30 and it's fine, but if i have a parameter that is equal to 30 and I divide by it, it returns in bad answer. (86400 is the number of seconds in a 24 hours day)
Do somebody know why? Does it happen because of rounded numbers?
what'S the result of "multiply 86400 by 50000" ? it's far bigger than the maximum int possible.
@tatatatate: Go
You may want to reformulate your question. If I understand you correctly, you are saying that if you simply do 86400 * 50000 / 30, it doesn't have any issues, but if you do 86400 * 50000 / psomevar, with psomevar equal to 30, it throws an error?
@ Funky, I wonder the same as well, SC2 uses fixed point data types, so it has 19 bits for non fractional parts. However, I do not know the max value for ints, I would presume they are simply signed ints, which gives us up to 2 billion to work with, which 50000 * 86400 = 4.32 billion goes right over, even for unsigned ints. So the error that is arising is sign overflow perhaps? Unless of course, the compiler is seeing 86400 * 50000 / 30 and doing the division first, to prevent overflow in the intermediary calculation. This would work perfectly fine, since the resulting division would be fixed point withing the correct bounds, and the subsequent multiplication would be in bounds.
TL:DR, doing a raw number calculation can work, because the game can do the calculation out of order, but with variables, it can not, so it causes an error.
@ArcaneDurandel: Go
Yes, thanks for the reply, I did the division first and it works fine. I just asked the question to avoid doing the same error twice. And when I do 86400 * 50000 / 30, it works, but if I replace 30 by an action parameter (example : lp_integer) who also have 30 as a value, it returns in an error.