RSmith wrote:
> how can I accurately establish how many total-then-divide-by-2's a set
> of co-values in 64-bit FP guise can withstand before the difference is
> too small to make sense to the sorter in SQLite?

Internally, SQLite uses 64-bit IEEE floating-point numbers, which is the
same as "double" in your C program.

The IEEE spec says that division works as if it used infinite precision,
then rounds the result to the precision of the output variable.  (I do
not know of any CPU that claims IEEE conformance but gets this wrong.)

In practice, there is no easy way to predict when your (prev+next)/2
gets inaccurate because the number of mantissa bits depends on the
magnitude of the prev/next values.

The easiest way to check when you have run out of bits is like in
Scott's program; just compute the value and check if it is actually
different from the boundaries.  It is a good idea to use "volatile"
to force the values to memory; values in registers might have higher
precision:

  volatile double prev = ..., next = ...;
  volatile double middle = (prev + next) / 2;
  if (middle <= prev || middle >= next)
    // problem


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to