/ Check-in [cfcaa0ff]

Overview
Comment: Increase the precision of integer vs. floating-point comparisons. Candidate fix for ticket [38a97a87a6e4e8]. Tarball | ZIP archive | SQL archive family | ancestors | descendants | both | int-float-precision files | file ages | folders cfcaa0ff276b1936418abe72c7e0c99d90d37885 drh 2015-11-06 01:04:41
Context
 2015-11-06 03:37 Some simple test cases from the mailing list. (check-in: 1d642b73 user: drh tags: int-float-precision) 01:04 Increase the precision of integer vs. floating-point comparisons. Candidate fix for ticket [38a97a87a6e4e8]. (check-in: cfcaa0ff user: drh tags: int-float-precision) 2015-11-05 21:49 Fix typo in help information for an FTS5 script. (check-in: 777ae800 user: mistachkin tags: trunk)
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

3661   3661     }
3662   3662
3663   3663     /* If one value is a number and the other is not, the number is less.
3664   3664     ** If both are numbers, compare as reals if one is a real, or as integers
3665   3665     ** if both values are integers.
3666   3666     */
3667   3667     if( combined_flags&(MEM_Int|MEM_Real) ){
3668         -    double r1, r2;
3668  +    LONGDOUBLE_TYPE r1, r2;
3669   3669       if( (f1 & f2 & MEM_Int)!=0 ){
3670   3670         if( pMem1->u.i < pMem2->u.i ) return -1;
3671   3671         if( pMem1->u.i > pMem2->u.i ) return 1;
3672   3672         return 0;
3673   3673       }
3674   3674       if( (f1&MEM_Real)!=0 ){
3675   3675         r1 = pMem1->u.r;
3676   3676       }else if( (f1&MEM_Int)!=0 ){
3677         -      r1 = (double)pMem1->u.i;
3677  +      r1 = (LONGDOUBLE_TYPE)pMem1->u.i;
3678   3678       }else{
3679   3679         return 1;
3680   3680       }
3681   3681       if( (f2&MEM_Real)!=0 ){
3682   3682         r2 = pMem2->u.r;
3683   3683       }else if( (f2&MEM_Int)!=0 ){
3684         -      r2 = (double)pMem2->u.i;
3684  +      r2 = (LONGDOUBLE_TYPE)pMem2->u.i;
3685   3685       }else{
3686   3686         return -1;
3687   3687       }
3688   3688       if( r1<r2 ) return -1;
3689   3689       if( r1>r2 ) return 1;
3690   3690       return 0;
3691   3691     }
................................................................................
3834   3834         serial_type = aKey1[idx1];
3835   3835         testcase( serial_type==12 );
3836   3836         if( serial_type>=10 ){
3837   3837           rc = +1;
3838   3838         }else if( serial_type==0 ){
3839   3839           rc = -1;
3840   3840         }else if( serial_type==7 ){
3841         -        double rhs = (double)pRhs->u.i;
3841  +        LONGDOUBLE_TYPE rhs = (LONGDOUBLE_TYPE)pRhs->u.i;
3842   3842           sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
3843   3843           if( mem1.u.r<rhs ){
3844   3844             rc = -1;
3845   3845           }else if( mem1.u.r>rhs ){
3846   3846             rc = +1;
3847   3847           }
3848   3848         }else{
................................................................................
3864   3864           ** numbers). Types 10 and 11 are currently "reserved for future
3865   3865           ** use", so it doesn't really matter what the results of comparing
3866   3866           ** them to numberic values are.  */
3867   3867           rc = +1;
3868   3868         }else if( serial_type==0 ){
3869   3869           rc = -1;
3870   3870         }else{
3871         -        double rhs = pRhs->u.r;
3872         -        double lhs;
3871  +        LONGDOUBLE_TYPE rhs = pRhs->u.r;
3872  +        LONGDOUBLE_TYPE lhs;
3873   3873           sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
3874   3874           if( serial_type==7 ){
3875   3875             lhs = mem1.u.r;
3876   3876           }else{
3877         -          lhs = (double)mem1.u.i;
3877  +          lhs = (LONGDOUBLE_TYPE)mem1.u.i;
3878   3878           }
3879   3879           if( lhs<rhs ){
3880   3880             rc = -1;
3881   3881           }else if( lhs>rhs ){
3882   3882             rc = +1;
3883   3883           }
3884   3884         }