double/float + binary math

I’m trying to create a library that i can use to send simple packets back and forth between my host and my firmware. part of that is using an overloaded add() function to allow me to simply call packet->add(data) and then have it put it into the buffer to be sent later.

i’m pretty sure i figured out how to do it for all the ‘normal’ datatypes, but i’m confused when it comes to floats and doubles. here is a snipped of the code i’m using:

full version here: http://reprap.svn.sourceforge.net/viewvc/reprap/trunk/users/hoeken/arduino/library/PackIt/

boolean PackIt::add(byte b)
{
      //do we have room left?
      if (this->size < MAX_PACKET_SIZE-1)
      {
            //add it in!
            this->packets[this->size] = b;
            this->size++;
            
            //calculate our crc
            this->crc = this->crc ^ b;
            
            return true;
      }
      else
            return false;
}


boolean PackIt::add(double d)
{
      byte i, b;
      bool result;
      
      for (i=0; i<8; i++)
      {
            b = d & B11111111;
            result = this->add(b);
            d >>= 8;
      }
      
      return result;
}

boolean PackIt::add(long l)
{
      byte i, b;
      bool result;
      
      for (i=0; i<4; i++)
      {
            b = l & B11111111;
            result = this->add(b);
            l >>= 8;
      }
      
      return result;
}

what do you guys think?