Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

(no subject)

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Seth Grover

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/objpas/dateutil.inc?view=diff&r1=12957&r2=12958 shows that a change was recently made which replaces "Trunc" with "Round" in the *Between routines in dateutil.inc (DaysBetween, HoursBetween, etc.).

So this program:
---------------------------------

program Project1;
{$mode objfpc}{$H+}
uses
  Classes,SysUtils,DateUtils;
var
  val1, val2 : TDateTime;
begin
  val1 := 39939.0;
  val2 := 39939.796069305557;
  writeln(DaysBetween(val1, val2));
end.
---------------------------------

Will now print result in a "1" instead of a "0" which is what I would have gotten before.

Now I know I can just use trunc(DaySpan(val1, val2)) to achieve the same result, but I was just curious as to why this change was made which so drastically changes the functionality of these calls.

Thanks,

-SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com

Reply by email

Jonas Maebe
to Seth Grover
Seth Grover wrote
Now I know I can just use trunc(DaySpan(val1, val2)) to achieve the same result, but I was just curious as to why this change was made which so drastically changes the functionality of these calls.

Because with trunc you also get rounding errors in certain cases, but in the other direction. I've now fixed it using a custom epsilon and trunc.

Jonas

Reply by email