/ Check-in [6ba4be66]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhancements to the printf() logic in order to render a negative zero with a minus sign.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | negative-zero
Files: files | file ages | folders
SHA3-256: 6ba4be66be90799ab0e1edc08c5c09bea239a85027ad0ca1f42818fc2580af4d
User & Date: drh 2019-06-12 20:11:34
Context
2019-06-12
20:11
Enhancements to the printf() logic in order to render a negative zero with a minus sign. Leaf check-in: 6ba4be66 user: drh tags: negative-zero
13:49
Handle expressions like "expr IS TRUE COLLATE xyz" in the same way as "expr IS TRUE". Fix for [4d01eda8115b10d1]. check-in: 5c6146b5 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/printf.c.

   100    100   };
   101    101   
   102    102   /* Floating point constants used for rounding */
   103    103   static const double arRound[] = {
   104    104     5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
   105    105     5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10,
   106    106   };
          107  +
          108  +/* Return TRUE if a floating point number is negative, even a negative 0 */
          109  +static int realIsNeg(double r){
          110  +  i64 x;
          111  +  memcpy(&x,&r,sizeof(x));
          112  +  return x<0;
          113  +}
   107    114   
   108    115   /*
   109    116   ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
   110    117   ** conversions will work.
   111    118   */
   112    119   #ifndef SQLITE_OMIT_FLOATING_POINT
   113    120   /*
................................................................................
   511    518           }else{
   512    519             realvalue = va_arg(ap,double);
   513    520           }
   514    521   #ifdef SQLITE_OMIT_FLOATING_POINT
   515    522           length = 0;
   516    523   #else
   517    524           if( precision<0 ) precision = 6;         /* Set default precision */
   518         -        if( realvalue<0.0 ){
          525  +        if( realIsNeg(realvalue) ){
   519    526             realvalue = -realvalue;
   520    527             prefix = '-';
   521    528           }else{
   522    529             prefix = flag_prefix;
   523    530           }
   524    531           if( xtype==etGENERIC && precision>0 ) precision--;
   525    532           testcase( precision>0xfff );