[fpc-pascal] <time_fraction>Between bug?

Jonas Maebe jonas.maebe at elis.ugent.be
Sun May 30 14:47:22 CEST 2010


On 30 May 2010, at 14:38, Bee Jay wrote:

>  2010, at 19:28, Jonas Maebe wrote:
> 
>> Then it shouldn't use floating point. Ever.
> 
> Well... then it shouldn't be using FPC? ;)

They should not be using any FPC functionality relying on floating point. Any person who uses floating point should know that by definition it is inexact (ranging from "a little" to "enormously", depending on what you do).

> Ok, forget about the rocket launcher. The important note that I think need to be addressed is the bug only occurs if the milisecond part of a or b is 0. Other than 0, then those functions work correctly.

At least in the cases that you tested. There are almost certainly more cases where problems occur.

> I believe most of us rarely write a program that need precision to milisecond, usually we simply put 0 on the milisecond part. The worst thing is, the other similar functions e.g. HoursBetween etc. which commonly used are also affected by the bug. So, the simple thing could lead to a serious problem.

That last sentence is a fundamental principle of any algorithm that uses floating point.

> Should I report this to mantis?

No. If you need exact date/time calculations, you cannot use TDateTime. In fact, several of the TDateTime helpers are literally defined as only offering approximations (e.g. http://www.freepascal.org/docs-html/rtl/dateutils/monthspan.html).

You have to implement a separate unit that is written from the start to offer the precision that you require if you need more than what TDateTime offers.


Jonas


More information about the fpc-pascal mailing list