| 08-17-2007, 04:51 PM | #1 |
Am i blind or is this a bug?: JASS:function l2r takes location l returns real return l return 0. endfunction function i2r takes integer i returns real return i return 0. endfunction function r2i takes real r returns integer return r return 0 endfunction function Trig_a_Actions takes nothing returns nothing local location l = Location(0,0) local integer i = 0 call BJDebugMsg("addr: "+I2S(r2i(l2r(l)))) set i = r2i(l2r(l)) if i==0 then call BJDebugMsg("error 1: "+I2S(i)+"; addr: "+I2S(r2i(l2r(l)))) elseif r2i(l2r(l))==0 then call BJDebugMsg("error 2: "+I2S(i)+"; addr: "+I2S(r2i(l2r(l)))) endif endfunction //=========================================================================== function InitTrig_a takes nothing returns nothing set gg_trg_a = CreateTrigger( ) call TriggerRegisterTimerEventSingle( gg_trg_a, 0.20 ) call TriggerAddAction( gg_trg_a, function Trig_a_Actions ) endfunction The local i is set to the value r2i(l2r(l)) returns. The expression returns the address of the location created at the start of the function. So i expected both tests to show the same result: false But: call BJDebugMsg("addr: "+I2S(r2i(l2r(l)))) shows a value not equal to 0 r2i(l2r(l))==0 it returns true i==0 returns false Did i make a mistake? If so i must be blind atm. |
| 08-17-2007, 05:10 PM | #2 |
r2i and i2r are soooooo bad idea Not all real numbers are valid. |
| 08-17-2007, 05:34 PM | #3 | |
Quote:
What does this have to do with the code? How does it explaint the behaviour of the script? |
| 08-17-2007, 05:49 PM | #4 |
Ok a lesson in floating-point arithmetic. integers: 45, -5, 78, 456 real numbers: 1.0, -0.0001, 0.45e-3 See that last one? All real are made from 2 parts: mantissa and exponent 0.45e-3 == 0.45 * 10^-3 (0.45 mantissa, -3 exponent) in reals -0e-4 <> 0e-4 (negative zero exists) real numbers also have special values that represent -infinity and +infinity The problem is that mantissa and exponent can have invalid values and that kind of number is NaN (not a number) This is a messy stuff, you can learn more about it if you type "IEEE floating" in google Bottom line: DON'T use I2R and R2I |
| 08-17-2007, 06:30 PM | #5 |
@cohadar: And how does it affect this (i know floating point representation btw): JASS:set i = r2i(l2r(l)) if i==0 then call BJDebugMsg("i==0") else call BJDebugMsg("i!=0") endif if r2i(l2r(l))==0 then call BJDebugMsg("r2i(l2r(l))==0") else call BJDebugMsg("r2i(l2r(l))!=0") endif if i==r2i(l2r(l)) then call BJDebugMsg("i==r2i(l2r(l))") else call BJDebugMsg("r2i(l2r(l))!=0") endif if r2i(l2r(l))==r2i(l2r(l)) then call BJDebugMsg("r2i(l2r(l))==r2i(l2r(l))") else call BJDebugMsg("r2i(l2r(l))!=r2i(l2r(l))") endif It prints: "i!=0" "r2i(l2r(l))==0" "i==r2i(l2r(l))" "r2i(l2r(l))==r2i(l2r(l))" So i is not 0. But r2i(l2r(l)) returns 0. But both should have the same value since I set i = r2i(l2r(l)) And in addition do i and r2i(l2r(l)) have the same value when i compare them. And i is an integer and r2i(l2r(l)) returns an integer. |
| 08-17-2007, 06:47 PM | #6 |
Look I don't want to bother why exactly it does not work in your trigger, it simply does not because handle casting ALWAYS makes problems and especially when you do i2r and r2i. So here is what: You tell me what is exactly that you want to do and I will tell you how to do it without i2r and r2i. |
| 08-17-2007, 07:12 PM | #7 | ||
Quote:
But there is a problem when using the values in the way i do it in the example. (But when you store the value in the integer it seems to work correctly) Quote:
I want to get the address of a location. Then i want to assign the address of that location to the x coordinate of a different location. But i have a solution for that. |
| 08-17-2007, 07:23 PM | #8 |
If you are trying to make linked lists than DON'T DO IT Vexorian already made linked list system with locations like 1000 years ago, but it is deprecated now, there are much better systems now. (like the ones from my signature if I may notice...) |
| 08-17-2007, 07:46 PM | #9 |
@ Deckname, there is a bug with type-casting reals/integers while working with handles. Storing the value to a global fixes this (at least thats what I remember). @ Cohadar, it really depends on what you need the list for. |
| 08-17-2007, 08:03 PM | #10 | |
Quote:
Well people usually need lists when they have variable number of data and they want to add/remove data arbitrarily from the list. Collections do that so I don't see why he should not use them. |
| 08-19-2007, 01:30 PM | #11 |
iNfraNe made the Location Linked Lists, not Vexorian. |
| 08-19-2007, 01:58 PM | #12 |
Oh pardon me, I saw them in an earlier version of CS_ system so I assumed... |
