You are not logged in.
program project1;
uses
{$I SynDprUses.inc}
SynCommons,
SysUtils;
begin
WriteLn(DateTimeMSToString(NowUTC()));
sleep(1000);
WriteLn(DateTimeMSToString(NowUTC()));
readln;
end.
Both writeLn will output the same time truncated to nearest 5-minutes interval.
Seems problem is on line
result := (nano100-DateFileTimeDelta)/(10000000.0*SecsPerDay);
but I don't understand asm generated by FPC.. Can anybody help, please?
Offline
Ok, if I split a statement
result := (nano100-DateFileTimeDelta)/(10000000.0*SecsPerDay);
into two part
function NowUTC: TDateTime;
{$ifdef MSWINDOWS}
var ft: TFileTime;
{$ifdef CPU64}nano100: Int64; d: double;{$endif}
begin
GetSystemTimeAsFileTime(ft); // very fast, with 100 ns unit
{$ifdef CPU64}
FileTimeToInt64(ft,nano100);
// prev. result := (nano100-DateFileTimeDelta)/(10000000.0*SecsPerDay);
d := (nano100-DateFileTimeDelta) / 10000000;
result := d/SecsPerDay;
{$else} // use PInt64 to avoid URW699 with Delphi 6 / Kylix
dec(PInt64(@ft)^,DateFileTimeDelta);
result := PInt64(@ft)^/(10000000.0*SecsPerDay);
{$endif}
end;
all work as expected. But IMHO this is not a good solution. Still need a advice...
Offline
Sounds like a weird precision issue: FPC generates a conversion into single, which precision is not enough for the later division.
Whereas Delphi uses double precision for the computation.
Perhaps this commit sounds stable and fast enough: https://synopse.info/fossil/info/bb2e164423
(tested with FPC and Delphi)
Offline
Since it's a critical function I add the test case for this - [c4ca0170af]. It's failed before fix and passed after.
Offline
This PITA raise again. Current implementation shift time to ~ -70sec on FPC x64.
Having
d: double
inside procedure fix the problem.
Please, see pull request #140 with corresponding regression test
Offline