[yunqa.de] Re: Rounding of REAL and DISQLite3Api.DateTimeToJulianDate

  • From: Edwin Yip <edwin.yip@xxxxxxxxxxxxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Fri, 27 Feb 2009 14:58:41 +0800

Hi Ralf,

I apologize! The error is neither from DISQLITE nor
DateTimeToJulianDate /JulianDateToDateTime,
it's from another part of the program, so your following assumption is
correct I think:

The DateTimeToJulianDate function is implemented as a simple addition of two
floats. I tend to believe that this should contribute very little only to
precision loss. My testing shows that 12 digits of precision are well
preserved.

Just to post this update here to avoid any misunderstand on DISQLITE, it's a
great database system :)


Best Regards,
Edwin Yip

Mind Mapping is as Effortless as Typing
http://www.InnovationGear.com


On Wed, Feb 25, 2009 at 11:44 PM, Delphi Inspiration <delphi@xxxxxxxx>wrote:

> Edwin Yip wrote:
>
> >But when the program gets the TDateTime values the precision is not only 4
> digits, but I can only use ROUND(X, 4) to compare the values after saving
> into the database in the way described in my original email...
>
> The DateTimeToJulianDate function is implemented as a simple addition of
> two floats. I tend to believe that this should contribute very little only
> to precision loss. My testing shows that 12 digits of precision are well
> preserved. The small loss is certainly not due to the code but to the CPU's
> floating point unit. Not much can be done about this.
>
> Various floating math libraries include dedicated functions to check for
> float equality. Here is one which allows to pass the precision as a 3rd
> parameter, i.e. 1e-6):
>
> function FloatsEqual(const x, y, Delta: Extended): Boolean;
> begin
>  Result := x = y;
>  if not Result then
>    try
>      if y = 0 then
>        Result := Abs(1 - y / x) <= Delta
>      else
>        Result := Abs(1 - x / y) <= Delta;
>    except
>      Result := False; // catch real rare overflow e.g.  1.0e3000/1.0e-3000
>    end
> end;
>
> If you need an 100% exact date and time representation with a guaranteed
> accuracy down to the very second, you must use a separate date format like
> ISO date (http://en.wikipedia.org/wiki/ISO_8601) or a Unix time (
> http://en.wikipedia.org/wiki/Unix_time). Both formats are supported by the
> DISQLite3 date and time functions.
>
> Ralf
>
> _______________________________________________
> Delphi Inspiration mailing list
> yunqa@xxxxxxxxxxxxx
> //www.freelists.org/list/yunqa
>
>
>
>

Other related posts: