Decimal to binary conversion in strtof and snprintf loses precision

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: Low

      The attached try1.c has these lines ...

       

          printf("2 strtof tests\n");
      
          fval = strtof("15.000", NULL);
          printf("expect 15.000, get %f\n", (double) fval);
      
          fval = strtof("15.000000000000000", NULL);
          printf("expect 15.000000000000000, get %f\n", (double) fval);    
      
          printf("\n1 snprintf test\n");
      
      snprintf(buffer, LENGTH, "%.6f", 123456790519087104.0f);
          printf("expect 123456790519087104, get %s\n", buffer);

      Build it ...

      % armcl -@options.txt try1.c -z -o try1.out -l lnk.cmd
      <Linking>
      

      Execute it to see this output ...

      2 strtof tests
      expect 15.000, get 15.000000
      expect 15.000000000000000, get 15.000003
      
      1 snprintf test
      expect 123456790519087104, get 123456790519087076.187
      

      The first strof test is good.  The second is bad.  The snprintf test is bad.

      Please see the related forum thread for more context.

       

       

       

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Connection: Intermediate to External PROD System
                EXTSYNC-2567 - Decimal to binary conversion in str...
                SYNCHRONIZED
                • Last Sync Date: