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

Rounding error in floating point division of constant values

XMLWordPrintable

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

      The attached file contains this line ...

         if (delay  >= ( (unsigned short) (20e-3/(1e-3)) ) )

      Thus, you would expect the variable delay to be compared with the value 20.

      Build it ...

      % cl2000 -s try1.c

      Then inspect the resulting assembly file to see these lines ...

      ;----------------------------------------------------------------------
      ;   5 | if (delay  >= ( (unsigned short) (20e-3/(1e-3)) ) )
      ;----------------------------------------------------------------------
              MOVW      DP,#_delay            ; [CPU_ARAU]
              MOV       AL,@_delay            ; [CPU_ALU] |5|
              CMPB      AL,#19                ; [CPU_ALU] |5|
              B         $C$L1,LO              ; [CPU_ALU] |5|

      It is not compared again 20, but 19.

       

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

              Created:
              Updated: