• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

S2R vs JassParser.S2R (so much for code reuse...)

Status
Not open for further replies.
JASS:
library foo initializer init

//# +nosemanticerror
private function int_to_real takes integer i returns real
    return i
endfunction

//# +nosemanticerror
private function real_to_int takes real r returns integer
    return r
endfunction

private function clean_real takes real r returns real
    return r
    return 0.0 // prevent jasshelper from inlining
endfunction

private function clean_int takes integer i returns integer
    return i
    return 0 // prevent jasshelper from inlining
endfunction

private function i2r takes integer i returns real
    return clean_real(int_to_real(i))
endfunction

private function r2i takes real i returns integer
    return clean_int(real_to_int(i))
endfunction

function init takes nothing returns nothing
    local real r1 = 6.28
    local real r2 = S2R("6.28")
    
    call BJDebugMsg(I2S(r2i(r1))) // 1086911938 (0x40C8F5C2) (6.2799997)
    call BJDebugMsg(I2S(r2i(r2))) // 1086911939 (0x40C8F5C3) (6.28)
endfunction

endlibrary

My guess is that the parser's version is faster but less accurate...
 
Status
Not open for further replies.
Top