| 01-05-2009, 03:08 PM | #1 |
Copy this to new trigger. Then run map and press ESC. JASS:function B2Sx takes boolean Boolean returns nothing if Boolean then call BJDebugMsg("|cffccffccTrue|r") else call BJDebugMsg("|cffffccccFalse|r") endif endfunction function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing call B2Sx(not (0.999 != 1.000)) //Return FALSE call B2Sx((0.999 == 1.000)) //Return TRUE call B2Sx(not (1.0 != 2.0)) //Return FALSE call B2Sx((1.0 == 2.0)) //Return FALSE endfunction //=========================================================================== function InitTrig_Untitled_Trigger_001 takes nothing returns nothing set gg_trg_Untitled_Trigger_001 = CreateTrigger( ) call TriggerRegisterPlayerEventEndCinematic( gg_trg_Untitled_Trigger_001, Player(0) ) call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions ) endfunction |
| 01-05-2009, 03:36 PM | #2 |
what you put in comments there, is that the actual output ? if yes, it is everything alright and functions as intended |
| 01-05-2009, 03:40 PM | #3 |
rounding errors happens with real's. Direct comparison between reals is usually not good. I use RAbsBJ(r1-r2) < tolerance in cases like this. |
| 01-05-2009, 03:49 PM | #4 | |
Isn't that associated with how warcraft handles reals? EDIT: Quote:
|
| 01-05-2009, 03:57 PM | #5 |
Equal check uses real rounding. Not Equal - dont round reals. |
| 01-05-2009, 04:03 PM | #6 |
call B2Sx(not (0.999 != 1.000)) //Return FALSE
Oh! I didn't know that lol, great find Diod! |
| 01-05-2009, 04:11 PM | #7 |
Can anyone benchmark: JASS:function One takes nothing returns nothing local boolean A = (not (0.999 != 1.000)) endfunction vs function One takes nothing returns nothing local boolean A = ((0.999 - 1.000) == 0.0) endfunction |
| 01-05-2009, 04:42 PM | #8 |
JASS:function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing local integer sw = StopWatchCreate() local real array r local integer i local boolean A set i = 0 set r[0] = StopWatchMark(sw) loop exitwhen i == 12000 set A = (not (0.999 != 1.000)) set i = i + 1 endloop set r[1] = StopWatchMark(sw) set i = 0 call TriggerSleepAction(0.0) set r[2] = StopWatchMark(sw) loop exitwhen i == 12000 set A = ((0.999 - 1.000) == 0.0) set i = i + 1 endloop set r[3] = StopWatchMark(sw) call BJDebugMsg(R2S(r[1]-r[0])) call BJDebugMsg(R2S(r[3]-r[2])) endfunction //=========================================================================== function InitTrig_Untitled_Trigger_001 takes nothing returns nothing set gg_trg_Untitled_Trigger_001 = CreateTrigger( ) call TriggerRegisterPlayerEventEndCinematic( gg_trg_Untitled_Trigger_001, Player(0) ) call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions ) endfunction first 0.019-0.023 secound 0.023 I tried it 7 times. (JNGP 5.1; japi; Wc3 1.21b) Maybe it changed with the new patch/compiler. |
| 01-05-2009, 04:58 PM | #9 |
Looks like i have nothing to fix, both ways equal. Thx for benchmark. Sadly i cant rep+ you again today. |
| 01-05-2009, 05:18 PM | #10 |
EDIT : I said the order of the real in the comparison does matter sometimes but it's false, i miss read the displayed strings ... Here is a test map anyway : JASS:scope JustAnOtherJassBug initializer init globals private real R1 = 0.999 private real R2 = 1.0 endglobals function B2Sx takes boolean Boolean returns string if Boolean then return "|cffccffccTrue|r" else return "|cffffccccFalse|r" endif endfunction //! textmacro t_operator takes OP call BJDebugMsg(" ") call BJDebugMsg( "not (" + R2S(R1) + "$OP$" + R2S(R2) + ")" + " == " + B2Sx(not (R1 $OP$ R2)) ) call BJDebugMsg( "(" + R2S(R1) + "$OP$" + R2S(R2) + ")" + " == " + B2Sx((R1 $OP$ R2)) ) call BJDebugMsg( "not (" + R2S(R2) + "$OP$" + R2S(R1) + ")" + " == " + B2Sx(not (R2 $OP$ R1)) ) call BJDebugMsg( "(" + R2S(R2) + "$OP$" + R2S(R1) + ")" + " == " + B2Sx((R2 $OP$ R1)) ) call BJDebugMsg(" ") //! endtextmacro private function Display takes nothing returns nothing local string s = StringCase(GetEventPlayerChatString(),false) local real r if GetTriggerEventId() != EVENT_PLAYER_END_CINEMATIC then if s == "reverse" then set r = R1 set R1 = R2 set R2 = r return endif if SubStringBJ(s,1,3) == "r1 " then set R1 = S2R(SubStringBJ(s,4,StringLength(s))) return elseif SubStringBJ(s,1,3) == "r2 " then set R2 = S2R(SubStringBJ(s,4,StringLength(s))) return endif return endif //! runtextmacro t_operator("==") //! runtextmacro t_operator("<=") //! runtextmacro t_operator(">=") //! runtextmacro t_operator("<") //! runtextmacro t_operator(">") //! runtextmacro t_operator("!=") endfunction //=========================================================================== private function init takes nothing returns nothing local trigger trig = CreateTrigger( ) call TriggerRegisterPlayerEventEndCinematic( trig, Player(0) ) call TriggerAddAction( trig, function Display ) call TriggerRegisterPlayerChatEvent(trig,Player(0),"r1 ",false) call TriggerRegisterPlayerChatEvent(trig,Player(0),"r2 ",false) call TriggerRegisterPlayerChatEvent(trig,Player(0),"reverse",false) endfunction endscope If you can't use Jasshelper, i have attached a demo map, don't try to save it, just start it with war3 Commands : Code:
- press the escape key to display results - type "reverse" will set R1 to R2 and R2 to R1 (not case sensitive) - "R1 X" will set R1 to X (not case sensitive) - "R2 X" will set R2 to X (not case sensitive) |
| 01-06-2009, 03:31 AM | #11 |
Bug of total real comparison ownage. (0.999 == 1.000) == (0.999 != 1.000) TRUE!!! |
| 01-06-2009, 07:15 PM | #12 |
masda70 posted this ~1.5+ years before =) w8 i may find the thread... http://www.google.com.ua/search?hl=ru&q=masda70&meta= :P http://wc3campaigns.net/showthread.php?t=93006 well it's not 100% the same as in this thread told but i think in whole it's the same stuff. and btw imo it's IEEE issue... |
| 01-06-2009, 07:15 PM | #13 |
IEEE means ? |
| 01-06-2009, 07:48 PM | #14 |
IEEE gives out standards, on how technology has to handle certain things ...blablah ... maybe he means the IEEE 754 Standard or something similar ...it tells how floating point numbers (floats,doubles,longs) are saved in memory and stuff ...dunno excactly what this has to do with this "problem" here. Anyway its surely more of a "feature" then an issue -.-' |
