Michael, Thanks for the very thorough analysis.
Yes, sorry, I forgot to state I was running on Windows. The results I got came from running the command window (the precompiled Windows binary sqlite-3_7_3.zip). I also got the same results from compiling the amalgamation (sqlite-amalgamation-3_7_3.zip) using Visual Studio Express 2010. I took that piece of code you highlighted and compiled and ran it standalone under both Windows and Linux (gcc 4.4.3). I got the SAME results for each: realvalue = 8.9484710000000049 and 8.9484710000000103 at the two points you mentioned. I didn't compile the amalgamation on Linux, nor did I use optimizations -- maybe the difference lies in there? BTW, when I traced the amalgamation on Windows for my example, this line of code for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){} has precision = 14, which suggests that the code is taking into account only the part after the decimal point. Here's the standalone code I tested (I hardcoded the values for my example, plus added some printfs; one thing I wanted to check was that Windows and gcc were converting the decimal literals to the same values): #include <stdio.h> int main(void) { double realvalue = 8.948471e15; int exp = 0, idx; double rounder; printf ("1e32 = %.13a\n",1e32); printf ("1e-32 = %.13a\n",1e-32); printf ("1e8 = %.13a\n",1e8); printf ("1e-8 = %.13a\n",1e-8); while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; } while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; } while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; } while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; } while( realvalue<1.0 ){ realvalue *= 10.0; exp--; } printf ("Realvalue = %.17g = %.13a\n",realvalue,realvalue); for(idx=14, rounder=0.5; idx>0; idx--, rounder*=0.1){} printf ("Rounder = %.17g = %.13a\n",rounder,rounder); realvalue += rounder; if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; } printf ("Realvalue = %.17g = %.13a\n",realvalue,realvalue); } _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users