Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 20, 2005, 6:18:14 PM (18 years ago)
Author:
bwuest
Message:

converter.h and converter.cc changed: Conversion float to byte* and byte* to float works now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/subprojects/network/network_unit_test.cc

    r6139 r6197  
    284284}
    285285
    286 
     286void testFloatConverter(float f)
     287{
     288  char* s = Converter::floatToBinString(f);
     289  printf("%f = ", f);
     290  printf(s); printf("\n");
     291 
     292  byte* res = Converter::floatToByteArray(f);
     293  printf("Byte Array: ");
     294  for (int i = 0; i < 4; i++)
     295    printf("%i  ", res[i]);
     296  printf("\n");
     297 
     298  float b = Converter::byteArrayToFloat(res);
     299  printf("ReConvert: %f \n", b);
     300}
     301
     302void testFloatConverter2(float f)
     303{
     304  char* s = Converter::floatToBinString(f);
     305  printf("### %f = ", f);
     306  printf(s); printf("\n");
     307 
     308  byte* res = Converter::_floatToByteArray(f);
     309  printf("Byte Array: ");
     310  for (int i = 0; i < 4; i++)
     311    printf("%i  ", res[i]);
     312  printf("\n");
     313 
     314  float b = Converter::_byteArrayToFloat(res);
     315  printf("ReConvert: %f \n", b);
     316}
    287317int converter(int argc, char** argv)
    288318{
     319  /*
    289320  int x = 200564786;
    290321  printf("To convert: %i\n", x);
     
    305336  printf("\n");
    306337 
     338  */
     339  /*
    307340  float y;
    308341  char* s;
     
    328361  printf(s); printf("\n");
    329362 
    330  
     363  y = -4.7824f;
     364  s = Converter::floatToBinString(y);
     365  printf("%f = ", y);
     366  printf(s); printf("\n");
     367 
     368  y = -14.35e14f;
     369  s = Converter::floatToBinString(y);
     370  printf("%f = ", y);
     371  printf(s); printf("\n");
     372                                                            */
     373 
     374 
     375  /*
     376  float a = 12.3f;
     377 
     378  char* s = Converter::floatToBinString(a);
     379  printf("%f = ", a);
     380  printf(s); printf("\n");
     381 
     382  byte* res = Converter::floatToByteArray(a);
     383  printf("Byte Array: \n");
     384  for (int i = 0; i < 4; i++)
     385    printf("%i  ", res[i]);
     386  printf("\n");
     387 
     388  float b = Converter::byteArrayToFloat(res);
     389  printf("ReConvert: %f \n", b);
     390  */
     391  testFloatConverter2(12.3f); printf("\n");
     392  testFloatConverter2(134.25f); printf("\n");
     393  testFloatConverter2(35.67e14f); printf("\n");
    331394 
    332395  return 0;
Note: See TracChangeset for help on using the changeset viewer.