>  A favorite interview question is, given this line and no other
>  information, how big must buf_size be to never clip the output?
>  You can assume the default 1.6 precision ("%1.6f").
>    snprintf( buf, buf_size, "%f", v );
>  The answer?  At least 318 characters.

This is very interesting. Jay, could you explain the answer? Doesn't
%1.6f limit number of digits to print?


Pavel

On Wed, Mar 2, 2011 at 10:58 AM, Jay A. Kreibich <j...@kreibi.ch> wrote:
> On Tue, Mar 01, 2011 at 03:21:58PM +0000, David Gilbert scratched on the wall:
>
>>      for(jj=0; jj<tree.nDim*2; jj++){
>>        sqlite3_snprintf(512-nCell,&zCell[nCell],"
>> %f",(double)cell.aCoord[jj].f);
>>
>> That's against 3.7.4 but it looks like it's the same in the trunk.
>>
>> With that change the test suite passes.  However, that %f looks a bit
>> odd a few lines below and is probably worth thinking about.
>
>  Due to the way the floating point registers work on a PDP-7, in C all
>  32-bit float values are promoted to 64-bit double values when used
>  in a var-arg.  Hence, for output, "%f" can be safely used for both
>  32-bit and 64-bit floating point values.  The tags "%f" and "%lf" are
>  the same.  (This isn't true for input functions such as scanf().)
>
>
>
>  A favorite interview question is, given this line and no other
>  information, how big must buf_size be to never clip the output?
>  You can assume the default 1.6 precision ("%1.6f").
>
>    snprintf( buf, buf_size, "%f", v );
>
>
>
>  The answer?  At least 318 characters.
>
>   -j
>
> --
> Jay A. Kreibich < J A Y  @  K R E I B I.C H >
>
> "Intelligence is like underwear: it is important that you have it,
>  but showing it to the wrong people has the tendency to make them
>  feel uncomfortable." -- Angela Johnson
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to