Index: branches/network/src/lib/network/converter.cc
===================================================================
--- branches/network/src/lib/network/converter.cc	(revision 6558)
+++ branches/network/src/lib/network/converter.cc	(revision 6564)
@@ -22,4 +22,9 @@
 /* include your own header */
 #include "converter.h"
+#include "shell_command.h"
+
+#include <limits>
+
+SHELL_COMMAND_STATIC(debug, Converter, Converter::debug);
 
 
@@ -182,4 +187,13 @@
 const int expmult = 8388608; //2^23
 
+float Converter::getDenormConst()
+{
+  const int exp = 126;
+  float result = 1.0f;
+  for (int i = 0; i < exp; i++)
+    result /= 2.0f;
+  return result;
+}
+
 /*!
  * Converts a float value into a byte-array
@@ -189,4 +203,8 @@
 byte* Converter::floatToByteArray(float x)
 {
+  byte* result = new byte[4];
+  floatToByteArray(x, result, 4);
+  return result;
+  /*
   int mantisse = 0;
   int exponent = 128;
@@ -201,34 +219,54 @@
     sgn = 1;
 
-  float sub = 1;
-  while (sub < x)
-  {
-    sub *= 2;
+  if (x == 0)
+  {
+    exponent = 255;
+    mantisse = 0;
+  }
+  else
+  {
+    //if (x < getDenormConst())
+    //  printf("Denormalisiert!\n");
+    //printf("DenormConst = %e", getDenormConst());
+    
+    float sub = 1;
+    while (sub < x)
+    {
+      sub *= 2;
+      exponent++;
+    }
+
+    while (x > 0)
+    {
+      if (x >= sub)
+      {
+        mantisse += 1;
+        x -= sub;
+      }
+
+      mantisse *= 2;
+      exponent--;
+      sub /= 2;
+    }
     exponent++;
-  }
-
-  while (x > 0)
-  {
-    if (x >= sub)
-    {
-      mantisse += 1;
-      x -= sub;
-    }
-
-    mantisse *= 2;
-    exponent--;
-    sub /= 2;
-  }
-  exponent++;
-  mantisse /= 2;
-  while (mantisse < expmult)
-  {
-    mantisse *= 2;
-    exponent--;
-  }
-
-  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
-
-  mantisse -= expmult;
+    mantisse /= 2;
+    
+    printf("Conv:        mantisse = %i exponent = %i \n", mantisse, exponent);
+
+    
+    if (mantisse != 0)
+    {
+      while (mantisse < expmult)
+      {
+        mantisse *= 2;
+        exponent--;
+      }
+    
+      mantisse -= expmult;
+    }
+  }
+
+  printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent);
+
 
   int hx = mantisse + expmult * exponent;
@@ -238,4 +276,5 @@
 
   return result;
+  */
 }
 
@@ -248,10 +287,20 @@
 float Converter::byteArrayToFloat(byte* a)
 {
+  byte* h = new byte[4];
+  float result = 0.0f;
+  byteArrayToFloat(a, &result);
+  return result;
+  /*
+  int hexp = a[2] + a[3] * 256;
+  int exponent = (hexp / 128) % 256;
+  
   int hmant = a[0] + a[1] * 256 + a[2] * 65536;
   int mantisse = hmant % expmult;
+  if (mantisse == 0 && exponent == 255)
+    return 0;
+  
   mantisse += expmult;
-
-  int hexp = a[2] + a[3] * 256;
-  int exponent = (hexp / 128) % 256 - 128;
+  exponent -= 128;
+
 
   int sgn;
@@ -261,5 +310,5 @@
     sgn = 1;
 
-  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
+  printf("ReConv: mantisse = %i exponent = %i \n", mantisse, exponent);
 
   float emult = 1;
@@ -276,31 +325,5 @@
 
   return result;
-}
-
-/*!
- * Converts a float value into a byte-array
- * @param x: The float which is to convert
- * @return: A byte-array which accords the given float
- */
-byte* Converter::_floatToByteArray(float x)
-{
-  byte* p = (byte*)&x;
-  byte* result = new byte[4];
-  for (int i = 0; i < 4; i++)
-    result[i] = p[i];
-  return result;
-}
-
-
-/*!
- * Converts a byte-array into a float value
- * @param a: The byte-array which is to convert
- * @return: A float value which accords the given byte-array
- */
-float Converter::_byteArrayToFloat(byte* a)
-{
-  float* p = (float*)a;
-  float result = *p;
-  return result;
+  */
 }
 
@@ -319,10 +342,10 @@
 
   //handle 0 else function will loop for ever
-  if ( x == 0 )
+  /*if ( x == 0 )
   {
     for ( int i = 0; i<FLOATSIZE; i++)
       a[i] = 0;
     return FLOATSIZE;
-  }
+}*/
 
   int mantisse = 0;
@@ -338,35 +361,56 @@
     sgn = 1;
 
-  float sub = 1;
-  while (sub < x)
-  {
-    sub *= 2;
+  if (x == 0)
+  {
+    exponent = 255;
+    mantisse = 0;
+  }
+  else
+  {
+    //if (x < getDenormConst())
+    //  printf("Denormalisiert!\n");
+    //printf("DenormConst = %e", getDenormConst());
+    
+    float sub = 1;
+    while (sub < x)
+    {
+      sub *= 2;
+      exponent++;
+    }
+
+    while (x > 0)
+    {
+      if (x >= sub)
+      {
+        mantisse += 1;
+        x -= sub;
+      }
+
+      mantisse *= 2;
+      exponent--;
+      sub /= 2;
+    }
     exponent++;
-  }
-
-  while (x > 0)
-  {
-    if (x >= sub)
-    {
-      mantisse += 1;
-      x -= sub;
-    }
-
-    mantisse *= 2;
-    exponent--;
-    sub /= 2;
-  }
-  exponent++;
-  mantisse /= 2;
-  while (mantisse < expmult)
-  {
-    mantisse *= 2;
-    exponent--;
-  }
-
-  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
-
-  mantisse -= expmult;
-
+    mantisse /= 2;
+    
+
+///    printf("Conv:        mantisse = %i exponent = %i \n", mantisse, exponent);
+
+    
+    if (mantisse != 0)
+    {
+      while (mantisse < expmult)
+      {
+        mantisse *= 2;
+        exponent--;
+      }
+    
+      mantisse -= expmult;
+    }
+  }
+
+///  printf("Conv: mantisse = %i exponent = %i \n", mantisse, exponent);
+
+  
   int hx = mantisse + expmult * exponent;
   int result = intToByteArray(hx, a, length);
@@ -374,4 +418,10 @@
     a[3] += sgnadd;
 
+
+//  int hx = mantisse + expmult * exponent;
+//  byte* result = intToByteArray(hx);
+//  if (sgn == -1)
+//    result[3] += sgnadd;
+
   return result;
 }
@@ -385,6 +435,6 @@
 int Converter::byteArrayToFloat(const byte* a, float* x)
 {
-  //handle 0
-  for (int i = 0; i<FLOATSIZE; i++)
+    //handle 0
+  /*for (int i = 0; i<FLOATSIZE; i++)
   {
     if (a[i]!=0)
@@ -395,13 +445,19 @@
       return FLOATSIZE;
     }
-  }
-
-
+}*/
+
+  int hexp = a[2] + a[3] * 256;
+  int exponent = (hexp / 128) % 256;
+  
   int hmant = a[0] + a[1] * 256 + a[2] * 65536;
   int mantisse = hmant % expmult;
+  
+  //handle 0
+  if (mantisse == 0 && exponent == 255)
+    return 0;
+  
   mantisse += expmult;
-
-  int hexp = a[2] + a[3] * 256;
-  int exponent = (hexp / 128) % 256 - 128;
+  exponent -= 128;
+
 
   int sgn;
@@ -411,5 +467,5 @@
     sgn = 1;
 
-  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
+///  printf("ReConv: mantisse = %i exponent = %i \n", mantisse, exponent);
 
   float emult = 1;
@@ -421,4 +477,12 @@
       emult /= 2;
 
+  /*
+  float result = mantisse * emult;
+  if (sgn == -1)
+    result = -result;
+
+  return result;
+  */
+
   *x = mantisse * emult;
   if (sgn == -1)
@@ -426,4 +490,31 @@
 
   return FLOATSIZE;
+}
+
+/*!
+ * Converts a float value into a byte-array
+ * @param x: The float which is to convert
+ * @return: A byte-array which accords the given float
+ */
+byte* Converter::_floatToByteArray(float x)
+{
+  byte* p = (byte*)&x;
+  byte* result = new byte[4];
+  for (int i = 0; i < 4; i++)
+    result[i] = p[i];
+  return result;
+}
+
+
+/*!
+ * Converts a byte-array into a float value
+ * @param a: The byte-array which is to convert
+ * @return: A float value which accords the given byte-array
+ */
+float Converter::_byteArrayToFloat(byte* a)
+{
+  float* p = (float*)a;
+  float result = *p;
+  return result;
 }
 
@@ -504,2 +595,52 @@
 }
 
+
+
+
+void Converter::floatTest(float x)
+{
+  //float x = 8.0f;
+  //float x = numeric_limits<float>::infinity();
+  
+  printf("To Convert: %e\n", x);
+  
+  byte* res = floatToByteArray(x);
+  for (int i = 0; i < 4; i++)
+    printf("%i ", res[i]);
+  printf("\n");
+  
+  float y = byteArrayToFloat(res);
+  printf("ReConvert: %e\n", y);
+  
+  if (x == y)
+    printf("equal\n");
+  else
+    printf("different\n");
+}
+
+void Converter::debug()
+{
+  printf("We rulez\n");
+  
+  //Denormalized?
+  //floatTest(-9.87624e-38f);
+  //floatTest(-9.87624e-37f);
+  //floatTest(-9.87624e-36f);
+  //floatTest(-9.87624e-35f);
+  
+  /*
+  floatTest(14.7f);
+  floatTest(12.07e15f);
+  floatTest(0.0f);
+  floatTest(5.67e-15f);
+  */
+  
+  //floatTest(-18.0098f);
+  //floatTest(-24.07e23f);
+  //floatTest(-0.0f);
+  //floatTest(-5.67e-29f);
+  floatTest(-45.7e-32f);
+  floatTest(45.7e-33f);
+  floatTest(-45.7e-34f);
+  floatTest(45.7e-35f);
+}
Index: branches/network/src/lib/network/converter.h
===================================================================
--- branches/network/src/lib/network/converter.h	(revision 6558)
+++ branches/network/src/lib/network/converter.h	(revision 6564)
@@ -9,4 +9,5 @@
 /* include this file, it contains some default definitions */
 #include "netdefs.h"
+
 
 /* include base_object.h since all classes are derived from this one */
@@ -21,5 +22,5 @@
  * a class that can convert int to byte-array and vice versa
  */
-class Converter: public BaseObject
+class Converter : public BaseObject
 {
   public:
@@ -45,4 +46,11 @@
     static byte* _floatToByteArray(float x);
     static float _byteArrayToFloat(byte* a);
+    
+    
+    static void debug();
+    static void floatTest(float x);
+    static float getDenormConst();
+ 
+    
   private:
     Converter();
@@ -50,3 +58,5 @@
 };
 
+#undef byte
+
 #endif /*_CONVERTER*/
