This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Floating Point

How can I deny a number floating point without utilizat some mathematical operation?

How can I take the first 8 bits of the number floating point, those but significant (MSB) or the bit but significant of the number type floating point?

Parents
  • Here is a routine to print the parts of a normalized float ( except for 0.0 or -0.0 ).

    #include <stdio.h>
    #include "AT89X55.H" // to define TI
    
    typedef unsigned char BYTE;
    typedef unsigned int  WORD;
    typedef unsigned long DWORD;
    
    void PrintFloat( float TheFloat )
    {
      union
      {
        struct
        {
          float Float;
        } Whole;
    
        struct
        {
          //@Float+0
          BYTE Exp1         :7; //bits 6-0
          BYTE Sign         :1; //bit 7
    
          //@Float+1
          BYTE Significand2 :7; //bits 6-0
          BYTE Exp0         :1; //bits 7
    
          //@Float+2
          BYTE Significand1 :8; //bits 7-0
    
          //@Float+3
          BYTE Significand0 :8; //bits 7-0
        } Parts;
        
      } Float;
    
      Float.Whole.Float = TheFloat;
    
      printf( "Float             = %#e\n",  (double)TheFloat );
      printf( "Sign              = %#i\n",  (int)Float.Parts.Sign );
      printf( "Exp Base 2        = %#i\n" , ( (int)Float.Parts.Exp1<<1 | (int)Float.Parts.Exp0 )  - 127);
      printf( "Mantissa Base 2   = %#lX\n" , 0x800000 | ( (DWORD)Float.Parts.Significand2 ) << 16
                                                      | ( (DWORD)Float.Parts.Significand1 ) << 8
                                                      | ( (DWORD)Float.Parts.Significand0 ) );
      printf( "\n" );
    }
    
    
    void main(void)
    {
      TI = 1;  //to get debugger to print to serial window
    
      PrintFloat( -2.3456E10 );
      PrintFloat( 0.0 );  //note!! 0.0 is all zeros plus a sign bit
    
      while( 1 )
        ;
    }
    

Reply
  • Here is a routine to print the parts of a normalized float ( except for 0.0 or -0.0 ).

    #include <stdio.h>
    #include "AT89X55.H" // to define TI
    
    typedef unsigned char BYTE;
    typedef unsigned int  WORD;
    typedef unsigned long DWORD;
    
    void PrintFloat( float TheFloat )
    {
      union
      {
        struct
        {
          float Float;
        } Whole;
    
        struct
        {
          //@Float+0
          BYTE Exp1         :7; //bits 6-0
          BYTE Sign         :1; //bit 7
    
          //@Float+1
          BYTE Significand2 :7; //bits 6-0
          BYTE Exp0         :1; //bits 7
    
          //@Float+2
          BYTE Significand1 :8; //bits 7-0
    
          //@Float+3
          BYTE Significand0 :8; //bits 7-0
        } Parts;
        
      } Float;
    
      Float.Whole.Float = TheFloat;
    
      printf( "Float             = %#e\n",  (double)TheFloat );
      printf( "Sign              = %#i\n",  (int)Float.Parts.Sign );
      printf( "Exp Base 2        = %#i\n" , ( (int)Float.Parts.Exp1<<1 | (int)Float.Parts.Exp0 )  - 127);
      printf( "Mantissa Base 2   = %#lX\n" , 0x800000 | ( (DWORD)Float.Parts.Significand2 ) << 16
                                                      | ( (DWORD)Float.Parts.Significand1 ) << 8
                                                      | ( (DWORD)Float.Parts.Significand0 ) );
      printf( "\n" );
    }
    
    
    void main(void)
    {
      TI = 1;  //to get debugger to print to serial window
    
      PrintFloat( -2.3456E10 );
      PrintFloat( 0.0 );  //note!! 0.0 is all zeros plus a sign bit
    
      while( 1 )
        ;
    }
    

Children
No data