removed useless _ folders
This commit is contained in:
3
Floats_to_Hex/Floats_to_Hex.sol
Normal file
3
Floats_to_Hex/Floats_to_Hex.sol
Normal file
@@ -0,0 +1,3 @@
|
||||
<Solution name="Floats_to_Hex">
|
||||
<Project name="Floats_to_Hex" path="Floats_to_Hex\Floats_to_Hex.prj" active="true"/>
|
||||
</Solution>
|
||||
14
Floats_to_Hex/Floats_to_Hex/Floats_to_Hex.prj
Normal file
14
Floats_to_Hex/Floats_to_Hex/Floats_to_Hex.prj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project name="Floats_to_Hex" guid="D7F37EE3-6C00-1014-B904-200204C60A89">
|
||||
<Object name="Object" guid="D7F37FD4-6C00-1014-B904-200204C60A89">
|
||||
<Script name="Floats_to_Hex_1.lsl" guid="D7F3A53F-6C00-1014-B904-200204C60A89">
|
||||
</Script>
|
||||
<Script name="Floats_to_Hex_2.lsl" guid="D7F3BF5B-6C00-1014-B904-200204C60A89">
|
||||
</Script>
|
||||
<Script name="Floats_to_Hex_3.lsl" guid="D7F3E75A-6C00-1014-B904-200204C60A89">
|
||||
</Script>
|
||||
<Script name="Floats_to_Hex_4.lsl" guid="D7F400F2-6C00-1014-B904-200204C60A89">
|
||||
</Script>
|
||||
<Script name="Floats_to_Hex_5.lsl" guid="D7F4143E-6C00-1014-B904-200204C60A89">
|
||||
</Script>
|
||||
</Object>
|
||||
</Project>
|
||||
43
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_1.lsl
Normal file
43
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_1.lsl
Normal file
@@ -0,0 +1,43 @@
|
||||
// :CATEGORY:Math
|
||||
// :NAME:Floats_to_Hex
|
||||
// :AUTHOR:StrifeOnizuka
|
||||
// :CREATED:2010-01-10 05:20:56.000
|
||||
// :EDITED:2013-09-18 15:38:53
|
||||
// :ID:326
|
||||
// :NUM:435
|
||||
// :REV:1.0
|
||||
// :WORLD:Second Life
|
||||
// :DESCRIPTION:
|
||||
// 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.
|
||||
// :CODE:
|
||||
string hexc="0123456789ABCDEF";//faster
|
||||
|
||||
|
||||
|
||||
string Float2Hex(float input)
|
||||
|
||||
{// Copyright Strife Onizuka, 2006, LGPL, http://www.gnu.org/copyleft/lesser.html
|
||||
|
||||
if((integer)input != input)//LL screwed up hex integers support in rotation & vector string typecasting
|
||||
|
||||
{//this also keeps zero from hanging the zero stripper.
|
||||
|
||||
float unsigned = llFabs(input);//logs don't work on negatives.
|
||||
|
||||
integer exponent = llFloor(llLog(unsigned) / 0.69314718055994530941723212145818);//floor(log2(b))
|
||||
|
||||
if(exponent > 127) exponent = 127;//catch fatal rounding error in exponent.
|
||||
|
||||
integer mantissa = (integer)((unsigned / (float)("0x1p"+(string)exponent)) * 0x1000000);//shift up into integer range
|
||||
|
||||
16
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_2.lsl
Normal file
16
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_2.lsl
Normal file
@@ -0,0 +1,16 @@
|
||||
// :CATEGORY:Math
|
||||
// :NAME:Floats_to_Hex
|
||||
// :AUTHOR:StrifeOnizuka
|
||||
// :CREATED:2010-01-10 05:20:56.000
|
||||
// :EDITED:2013-09-18 15:38:53
|
||||
// :ID:326
|
||||
// :NUM:436
|
||||
// :REV:1.0
|
||||
// :WORLD:Second Life
|
||||
// :DESCRIPTION:
|
||||
// Usage:
|
||||
// :CODE:
|
||||
string a = Float2Hex(100.000000); // a == 100
|
||||
|
||||
string b = Float2Hex(14353.344727); // b == 0xE04561p-10
|
||||
|
||||
47
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_3.lsl
Normal file
47
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_3.lsl
Normal file
@@ -0,0 +1,47 @@
|
||||
// :CATEGORY:Math
|
||||
// :NAME:Floats_to_Hex
|
||||
// :AUTHOR:StrifeOnizuka
|
||||
// :CREATED:2010-01-10 05:20:56.000
|
||||
// :EDITED:2013-09-18 15:38:53
|
||||
// :ID:326
|
||||
// :NUM:437
|
||||
// :REV:1.0
|
||||
// :WORLD:Second Life
|
||||
// :DESCRIPTION:
|
||||
// Helper Functions:
|
||||
// :CODE:
|
||||
string Rot2Hex(rotation a)
|
||||
|
||||
{
|
||||
|
||||
return "<"+Float2Hex(a.x)+","+Float2Hex(a.y)+","+Float2Hex(a.z)+","+Float2Hex(a.s)+">";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
string Vec2Hex(vector a)
|
||||
|
||||
{
|
||||
|
||||
return "<"+Float2Hex(a.x)+","+Float2Hex(a.y)+","+Float2Hex(a.z)+">";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
string DumpList2String(list input, string seperator)// for csv use ", " as the seperator.
|
||||
|
||||
{
|
||||
|
||||
integer b = (input != []);
|
||||
|
||||
string c;
|
||||
|
||||
string d;
|
||||
|
||||
integer e;
|
||||
|
||||
if(b)
|
||||
|
||||
{
|
||||
49
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_4.lsl
Normal file
49
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_4.lsl
Normal file
@@ -0,0 +1,49 @@
|
||||
// :CATEGORY:Math
|
||||
// :NAME:Floats_to_Hex
|
||||
// :AUTHOR:StrifeOnizuka
|
||||
// :CREATED:2010-01-10 05:20:56.000
|
||||
// :EDITED:2013-09-18 15:38:53
|
||||
// :ID:326
|
||||
// :NUM:438
|
||||
// :REV:1.0
|
||||
// :WORLD:Second Life
|
||||
// :DESCRIPTION:
|
||||
// How it works:
|
||||
// :CODE:
|
||||
string hexc="0123456789ABCDEF";//faster
|
||||
|
||||
|
||||
|
||||
string Float2Hex(float a)
|
||||
|
||||
{// Copyright Strife Onizuka, 2006, LGPL, http://www.gnu.org/copyleft/lesser.html
|
||||
|
||||
//If it's zero, the zero stripper will hang, lets avoid that
|
||||
|
||||
if(a)
|
||||
|
||||
{//we need to find the exponent, but to do that we need to take the log of the number (or run a while loop)
|
||||
|
||||
float b = llFabs(a);//logs don't work on negatives.
|
||||
|
||||
string f = "p";//This is a trade off, slightly slower (only slightly) for a couple bytes savings (10)
|
||||
|
||||
//To get the exponent we need to round the integer portion down or the log2(b)
|
||||
|
||||
// LSL doesn't have log2, so we use one of the laws of logs to get it from the natural log
|
||||
|
||||
integer c = llFloor(llLog(b) / 0.69314718055994530941723212145818);//floor(log2(b))
|
||||
|
||||
//There is a rounding error in the exponent that causes it to round up, this usualy isn't a problem as the
|
||||
|
||||
// exponent only is only used to shift the number. It becomes a problem when dealing with float max as
|
||||
|
||||
// it will round up to 128; which will crash llPow.
|
||||
|
||||
if(c > 127) c = 127;//catch fatal rounding error in exponent.
|
||||
|
||||
//Q: why not do (b * llPow(2,-c))? A: because the range of floats are different at the top and bottom
|
||||
|
||||
// at the top it's 2^127 at the bottom it's 2^-149; and if you tried to do this otherwise,
|
||||
|
||||
// llPow would crash with an overflow. Then we multiply it by 2 ^ 24, floats only use 23 bits for the mantisa,
|
||||
40
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_5.lsl
Normal file
40
Floats_to_Hex/Floats_to_Hex/Object/Floats_to_Hex_5.lsl
Normal file
@@ -0,0 +1,40 @@
|
||||
// :CATEGORY:Math
|
||||
// :NAME:Floats_to_Hex
|
||||
// :AUTHOR:StrifeOnizuka
|
||||
// :CREATED:2010-01-10 05:20:56.000
|
||||
// :EDITED:2013-09-18 15:38:53
|
||||
// :ID:326
|
||||
// :NUM:439
|
||||
// :REV:1.0
|
||||
// :WORLD:Second Life
|
||||
// :DESCRIPTION:
|
||||
// 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).
|
||||
// :CODE:
|
||||
string Float2Hex(float a)
|
||||
|
||||
{// Copyright Strife Onizuka, 2006, LGPL, http://www.gnu.org/copyleft/lesser.html
|
||||
|
||||
if(a)
|
||||
|
||||
{
|
||||
|
||||
float b = llFabs(a);
|
||||
|
||||
integer c = llFloor(llLog(b) / 0.69314718055994530941723212145818);//floor(log2(b))
|
||||
|
||||
string f = "";
|
||||
|
||||
if(c > 127) c = 127;
|
||||
|
||||
else if(c < -126) c = -126;
|
||||
|
||||
else c -= ((float)("0x1p"+(string)c) > b);
|
||||
|
||||
integer d = ((integer)(b / (float)("0x.000002p"+(string)c)) & 0x7FFFFF) << 1;
|
||||
|
||||
integer m = 6;
|
||||
|
||||
while(!(d & 0xf))
|
||||
|
||||
{//strip extra zeros off before converting or they break "p"
|
||||
|
||||
Reference in New Issue
Block a user