• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
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