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

1 ULP rounding error in double addition

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-4323
    • Hide
      MSP430_18.1.0.LTS
      C2000_22.6.0.LTS
      MSP430_20.2.0.LTS
      MSP430_21.6.0.LTS
      C2000_21.6.0.LTS
      MSP430_18.12.0.LTS
      Show
      MSP430_18.1.0.LTS C2000_22.6.0.LTS MSP430_20.2.0.LTS MSP430_21.6.0.LTS C2000_21.6.0.LTS MSP430_18.12.0.LTS
    • Hide
      The following code prints '-0x1.d6f3457f35ba8p+26' for the value of high.
      Using the gcc or TI arm compiler, the value is '-0x1.d6f3457f35ba7p+26'.

      It appears to be a floating point rounding error caused by the addition (+) or subtraction (-) arithmetic operators.

      #include <cmath>
      #include <stdio.h>

      #define BOUND 0.00000001

      double _x9 = -123456789.987654321;
      double _y9 = 9.0;
      double ans9 = -123456789.987654321;
      int main()
      {
          double val = std::nextafter(_x9, _y9);
          double low = ans9 - BOUND;
          double high = ans9 + BOUND;
          printf("%a %a (%zu)\n", _x9, _y9, sizeof(double));
          printf("%a < %a < %a ?\n", low, val, high);
          if (val >= low && val <= high) printf("Yes!\n");
          else printf("No!\n");
      }
      Show
      The following code prints '-0x1.d6f3457f35ba8p+26' for the value of high. Using the gcc or TI arm compiler, the value is '-0x1.d6f3457f35ba7p+26'. It appears to be a floating point rounding error caused by the addition (+) or subtraction (-) arithmetic operators. #include <cmath> #include <stdio.h> #define BOUND 0.00000001 double _x9 = -123456789.987654321; double _y9 = 9.0; double ans9 = -123456789.987654321; int main() {     double val = std::nextafter(_x9, _y9);     double low = ans9 - BOUND;     double high = ans9 + BOUND;     printf("%a %a (%zu)\n", _x9, _y9, sizeof(double));     printf("%a < %a < %a ?\n", low, val, high);     if (val >= low && val <= high) printf("Yes!\n");     else printf("No!\n"); }

      1 ULP rounding error in double addition

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

              Created:
              Updated: