Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-11014

32-bit floating point divide mishandles inputs that should return negative infinity, and division by zero

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Low Low

      The attached C file has this small program ...

      #include <stdio.h>
      
      int main(void)
      {
          float f1, f2;
      
          f1 =  1.75e+34f;
          f2 = -1.96e-07f;
          printf("expect negative infinity, get %g\n", f1/f2);
      
          f1 = 1.0f;
          f2 = 0.0f;
          printf("expect 0x7f7fffff, get 0x%lx\n",  __f32_bits_as_u32(f1/f2));
      
          f1 = -1.0f;
          f2 = 0.0f;
          printf("expect 0xff7fffff, get 0x%lx\n",  __f32_bits_as_u32(f1/f2));
      
      	return 0;
      }
      

      Build with no optimization, so the RTS function for 32-bit floating point divide is called.
      When it runs, this is the output ...

      expect negative infinity, get 2.35099e-38
      expect 0x7f7fffff, get 0x7f7f0000
      expect 0xff7fffff, get 0xff7f0000
      

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: