| 01-26-2010, 04:01 PM | #1 |
Hi there, I just wasted a lot of time debugging one of my triggers to realize the following: Had something like this in my periodic trigger with a frequency of 40. time_variable_1 = 1 time_variable_2 = 1 JASS:if time_variable_1 >= time_variable_2 then //does not return true all the time if time_variable_1 == time_variable_2 then //does return true all the time Doesn't make much sense to me, or can someone of you explain? (In case it is NO bug :>) |
| 01-26-2010, 04:14 PM | #2 |
== only consider the three first numbers under the digit or so, when >= , or <= check for the whole number. (probably 9 numbers under the digit, make some tests if you really care about it) |
| 01-26-2010, 04:38 PM | #3 |
Ah okay thanks. So in the first case it could be possible that it is 0.999953123>=1 for example? |
| 01-26-2010, 04:52 PM | #4 | |
Quote:
But i you could wait someone with more knowledge to know how it exactly works. |
| 01-26-2010, 04:56 PM | #5 |
I just tested this some, and == seems to check if the difference between the arguments is less than or equal to 2^-10 (except for really high values), whereas <= checks with maximum precision. Interestingly enough, this means that you can compare two reals more precisely by doing (a <= b) && (b <= a) than by using ==. |
| 01-26-2010, 04:59 PM | #6 | |
Quote:
|
| 01-26-2010, 05:00 PM | #7 | |
Quote:
EDIT: You can change that margin too: Zinc:function biasedEquals(real a, real b, integer bias) -> boolean { // higher bias means easier matching return a / Pow(2.0, bias) == b / Pow(2.0, bias); } |
| 01-26-2010, 05:04 PM | #8 | |
Quote:
|
| 01-26-2010, 05:12 PM | #9 | |
Quote:
|
| 01-26-2010, 05:18 PM | #10 | |
Quote:
Btw, Pow would be much slower than simply use an epsilon margin value. Also using Pow on high real values would make absurd results. |
| 01-26-2010, 05:31 PM | #11 | ||
Quote:
I wasn't arguing whether or not it would be better to round in general. I was just saying it's interesting and that one could come up with uses for the precise one too. I'm not trying to sell you anything so please don't try to bash me just because you don't find it useful. Quote:
|
| 01-26-2010, 05:38 PM | #12 | |
Quote:
Simply how reals are handled in jass functions i don't see the usefulness of this. (highest precision possible i mean) Maybe i'm wrong, but you didn't gave me a concrete example. |
| 01-26-2010, 10:38 PM | #13 |
not(x!=y) != x==y The first is true if and only if the two have exactly the same bits, whereas the second is true if and only if x is within +/- a small amount of y. |
