Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • N/A
    • None
    • None

    Description

      Even after all these years there is a steady stream of bugs in decimal math.
      We need a proactive approach instead, to try to find as many decimal bugs as
      possible.

      Suggestion: RQG testing of the expression

      ABS(CAST(a + b AS DOUBLE)/(CAST(a AS DOUBLE) + CAST(b AS DOUBLE)) - 1) < 0.0001

      where RQG randomly generates a and b, and the operation is one of +,
      -, *, /, mod.

      One should try also very small numbers (0.00...{~50 times}...01) as well as
      large ones.

      Attachments

        Issue Links

          Activity

            This query works okay in 5.5.40 candidate, but wrong in MySQL 5.5 (apparently that's the same problem as the one serg solved in the post-merge fix).

            MySQL [test]> select 0.0000000001 % 1;
            +------------------+
            | 0.0000000001 % 1 |
            +------------------+
            |     0.1000000000 |
            +------------------+
            1 row in set (0.00 sec)

            elenst Elena Stepanova added a comment - This query works okay in 5.5.40 candidate, but wrong in MySQL 5.5 (apparently that's the same problem as the one serg solved in the post-merge fix). MySQL [test]> select 0.0000000001 % 1; + ------------------+ | 0.0000000001 % 1 | + ------------------+ | 0.1000000000 | + ------------------+ 1 row in set (0.00 sec)

            Correction

            0.0001 error margin is rather arbitrary. It should depend on operands and on the operation itself. Here, revised queries:

            ABS(CAST(a + b AS DOUBLE)/(CAST(a AS DOUBLE) + CAST(b AS DOUBLE)) - 1) < POW(0.1, GREATEST(LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*')), LENGTH(REGEXP_SUBSTR(b, '(?<=[.]).*'))))
            ABS(CAST(a - b AS DOUBLE)/(CAST(a AS DOUBLE) - CAST(b AS DOUBLE)) - 1) < POW(0.1, GREATEST(LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*')), LENGTH(REGEXP_SUBSTR(b, '(?<=[.]).*'))))
            ABS(CAST(a * b AS DOUBLE)/(CAST(a AS DOUBLE) * CAST(b AS DOUBLE)) - 1) < POW(0.1, LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*')) + LENGTH(REGEXP_SUBSTR(b, '(?<=[.]).*')))
            ABS(CAST(a / b AS DOUBLE)/(CAST(a AS DOUBLE) / CAST(b AS DOUBLE)) - 1) < POW(0.1, LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*')) + @@div_precision_increment)
            

            serg Sergei Golubchik added a comment - Correction 0.0001 error margin is rather arbitrary. It should depend on operands and on the operation itself. Here, revised queries: ABS ( CAST (a + b AS DOUBLE )/( CAST (a AS DOUBLE ) + CAST (b AS DOUBLE )) - 1) < POW(0.1, GREATEST(LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*' )), LENGTH(REGEXP_SUBSTR(b, '(?<=[.]).*' )))) ABS ( CAST (a - b AS DOUBLE )/( CAST (a AS DOUBLE ) - CAST (b AS DOUBLE )) - 1) < POW(0.1, GREATEST(LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*' )), LENGTH(REGEXP_SUBSTR(b, '(?<=[.]).*' )))) ABS ( CAST (a * b AS DOUBLE )/( CAST (a AS DOUBLE ) * CAST (b AS DOUBLE )) - 1) < POW(0.1, LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*' )) + LENGTH(REGEXP_SUBSTR(b, '(?<=[.]).*' ))) ABS ( CAST (a / b AS DOUBLE )/( CAST (a AS DOUBLE ) / CAST (b AS DOUBLE )) - 1) < POW(0.1, LENGTH(REGEXP_SUBSTR(a, '(?<=[.]).*' )) + @@div_precision_increment)

            People

              elenst Elena Stepanova
              serg Sergei Golubchik
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.