Re: [sqlite] Thoughts about the sqlite3IntFloatCompare function from the vdbeaux.c file.

2018-05-18 Thread Richard Hipp
Thanks for the observations.  Changes have been checked in.

On 5/18/18, Abroży Nieprzełoży  wrote:
> 
>  1: static int sqlite3IntFloatCompare(i64 i, double r){
>  2:   if( sizeof(LONGDOUBLE_TYPE)>8 ){
>  3: LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
>  4: if( x  5: if( x>r ) return +1;
>  6: return 0;
>  7:   }else{
>  8: i64 y;
>  9: double s;
> 10: if( r<-9223372036854775808.0 ) return +1;
> 11: if( r>9223372036854775807.0 ) return -1;
> 12: y = (i64)r;
> 13: if( i 14: if( i>y ){
> 15:   if( y==SMALLEST_INT64 && r>0.0 ) return -1;
> 16:   return +1;
> 17: }
> 18: s = (double)i;
> 19: if( s 20: if( s>r ) return +1;
> 21: return 0;
> 22:   }
> 23: }
> 
>
> Line 11: the value 9223372036854775807.0 is unrepresentable as a double.
> The compiler uses the approximation 9223372036854775808.0,
> so the condition is in fact 'if( r>9223372036854775808.0 )'.
> Line 12: when r=9223372036854775808.0 then y=SMALLEST_INT64
> and this special case is handled by the condition on line 15.
>
> But if the condition in line 11 were 'if( r>=9223372036854775808.0 )'
> then for r=9223372036854775808.0 the function would return -1
> before assigning r to y, so the condition on line 15 would be unnecessary.
> ___
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Thoughts about the sqlite3IntFloatCompare function from the vdbeaux.c file.

2018-05-18 Thread Abroży Nieprzełoży
Some test: https://ideone.com/zkHHty


2018-05-18 13:36 GMT+02:00, Abroży Nieprzełoży
:
> 
>  1: static int sqlite3IntFloatCompare(i64 i, double r){
>  2:   if( sizeof(LONGDOUBLE_TYPE)>8 ){
>  3: LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
>  4: if( x  5: if( x>r ) return +1;
>  6: return 0;
>  7:   }else{
>  8: i64 y;
>  9: double s;
> 10: if( r<-9223372036854775808.0 ) return +1;
> 11: if( r>9223372036854775807.0 ) return -1;
> 12: y = (i64)r;
> 13: if( i 14: if( i>y ){
> 15:   if( y==SMALLEST_INT64 && r>0.0 ) return -1;
> 16:   return +1;
> 17: }
> 18: s = (double)i;
> 19: if( s 20: if( s>r ) return +1;
> 21: return 0;
> 22:   }
> 23: }
> 
>
> Line 11: the value 9223372036854775807.0 is unrepresentable as a double.
> The compiler uses the approximation 9223372036854775808.0,
> so the condition is in fact 'if( r>9223372036854775808.0 )'.
> Line 12: when r=9223372036854775808.0 then y=SMALLEST_INT64
> and this special case is handled by the condition on line 15.
>
> But if the condition in line 11 were 'if( r>=9223372036854775808.0 )'
> then for r=9223372036854775808.0 the function would return -1
> before assigning r to y, so the condition on line 15 would be unnecessary.
>
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Thoughts about the sqlite3IntFloatCompare function from the vdbeaux.c file.

2018-05-18 Thread Abroży Nieprzełoży

 1: static int sqlite3IntFloatCompare(i64 i, double r){
 2:   if( sizeof(LONGDOUBLE_TYPE)>8 ){
 3: LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i;
 4: if( xr ) return +1;
 6: return 0;
 7:   }else{
 8: i64 y;
 9: double s;
10: if( r<-9223372036854775808.0 ) return +1;
11: if( r>9223372036854775807.0 ) return -1;
12: y = (i64)r;
13: if( iy ){
15:   if( y==SMALLEST_INT64 && r>0.0 ) return -1;
16:   return +1;
17: }
18: s = (double)i;
19: if( sr ) return +1;
21: return 0;
22:   }
23: }


Line 11: the value 9223372036854775807.0 is unrepresentable as a double.
The compiler uses the approximation 9223372036854775808.0,
so the condition is in fact 'if( r>9223372036854775808.0 )'.
Line 12: when r=9223372036854775808.0 then y=SMALLEST_INT64
and this special case is handled by the condition on line 15.

But if the condition in line 11 were 'if( r>=9223372036854775808.0 )'
then for r=9223372036854775808.0 the function would return -1
before assigning r to y, so the condition on line 15 would be unnecessary.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users