Join us in Outworldz at www.outworldz.com:9000 or follow us:
Want to add a script or a project? Upload it and a half million people will see it and your name here this year.
|Math||Use to encode floats in hex notation, minimal overhead, does not introduce errors. No special decoder needed. Try it. // // Use this instead of (string) when converting floats to strings. // // LSL (float) typecast supports C99 hex floats. This is good because with hex you can store floats without the need for a special decoder (just use (float)) and since hex is a power of 2 format, floats can be stored without any loss or rounding errors. // // A similar function (also by me) Float to Scientific Notation, works much the same way (except it uses base 10). The trouble is it has to emulates higher precision math, in a scripting language this is a bad solution. Because of the base conversion using logs would introduce a huge accumulated error (read as: floats suck). Resulting in the need to do the shifting with a while loop. This wasn't good enough, even with 32 bits small numbers would still be corrupted by the shifting. An integer and a float (or in one rewrite two integers) were used, one to store the integer portion, and the other the float. This worked, but was slow as all get out for large and small numbers (2 seconds). Finaly some optical approches were used to do the conversion which sped up large numbers. While accurate, the function was slow and used alot of memory. // // This function is much faster, it requires about 900 instructions with little deviation from that number. In the sceme of things it's not too costly (on a not too lagged sim that is about 0.12 seconds). There isn't much that can be done to reduce the number of instructions executed, unless LL wants to give us an llInteger2HexString or an llFloat2HexString. // // UPDATE: // There was a small bug that would cause the script to crash on numbers that were greater then 0x1.FFFFF8p127. Please update to fix the script crash issue. As a result of the fix, it will be just a bit slower.|
|Math||How it works:|
|Math||This version is perfect, it is slightly slower. It properly handles the exponent bug. It's included for curiosities sake (and a bunch of work went into it and i didn't want to throw it away).|
Back to the Best Free Tools in Second Life and OpenSim.