Convert an integer (r12) to float (f12) in a sane, efficent way? - Printable Version +- Mario Kart Wii Gecko Codes, Cheats, & Hacks (https://mariokartwii.com) +-- Forum: Hacks/Modding (https://mariokartwii.com/forumdisplay.php?fid=14) +--- Forum: Code Support / Help / Requests (https://mariokartwii.com/forumdisplay.php?fid=61) +--- Thread: Convert an integer (r12) to float (f12) in a sane, efficent way? (/showthread.php?tid=1908) |
Convert an integer (r12) to float (f12) in a sane, efficent way? - jawa - 11-06-2021 lets say r12=0000 0006 and i would want to convert it to 0x40c0 0000 (float value of 6) how would i do that? i read the Conversion from integer to float in the Working with floats thread, but i didnt get it RE: Convert an integer (r12) to float (f12) in a sane, efficent way? - Vega - 11-06-2021 Code: #r3 holds your integer value to convert, result will be placed into f1. Since you're using r12 as your 'input' you need to substitute all instances of r3 in the above source to r12. Then you need to select another safe register to use to substitute for using r4. Not only that, you need to use two safe float registers to substitute for f1 and f2. f12 and f13 should be good to go. Replace f1 with f12, replace f2 with f13. Thus, f12 will contain the resulting float value. One issue I do see is that the result is in double precision, no point for that since a whole hex integer number will NEVER need to be in double precision when converted to float value. Plus if you happen to store your float result as single precision with the above snippet of code operated in double precision, this will cause issues on Real Hardware. So let's convert the float result to single precision (32-bit). Then finally store it to memory and load it back to r12. Code: frsp f12, f12 Try that out. This should make r12 be 0x40C00000 |