Board index » delphi » Invalid Floating Point ... Notes

Invalid Floating Point ... Notes

Hi,

I've been getting a runtime error "Invalid floating point operation".
The program worked fine if I did a build all, otherwise it would
fail.

The errors occured trying to exeute formatDateTime, or
writeln(fh, a_double). The writeln failed when the a_double was
assigned to from a TDateTime,
eg.
   a_double := my_datetime;
   writeln(fh, a_double);

I looked around Dejanews for a solution. Others seemed to have had
the problem, but I couldn't find a solutions.

Maybe people already know the solution but I thought I'd post what
I learned, just in case.

Eventually (after many hours) I resolved my problem. For some reason
when my code contained a comparison between a double and a TDateTime
the error was raised, remove the comparison and all is fine.
Unusual?

Eg.
        if my_date <> my_double then
                do_stuff;

In my case I had a const defined:
        PA_BLANK_DATE = 0.0;

I changed this to:
        PA_BLANK_DATE: TDateTime = 0.0;

This removed all double to TDateTime comparisons in my code.

So basically, get rid of all the comparisons between double and
TDateTime! There may be more cases, but I've got other things to
carry on with.

Hopefully this will help someone else.

Max

 

Re:Invalid Floating Point ... Notes


Quote
Max Douglas wrote:

> Hi,

> I've been getting a runtime error "Invalid floating point operation".
> The program worked fine if I did a build all, otherwise it would
> fail.

> The errors occured trying to exeute formatDateTime, or
> writeln(fh, a_double). The writeln failed when the a_double was
> assigned to from a TDateTime,
> eg.
>    a_double := my_datetime;
>    writeln(fh, a_double);

> I looked around Dejanews for a solution. Others seemed to have had
> the problem, but I couldn't find a solutions.

> Maybe people already know the solution but I thought I'd post what
> I learned, just in case.

> Eventually (after many hours) I resolved my problem. For some reason
> when my code contained a comparison between a double and a TDateTime
> the error was raised, remove the comparison and all is fine.
> Unusual?

> Eg.
>         if my_date <> my_double then
>                 do_stuff;

> In my case I had a const defined:
>         PA_BLANK_DATE = 0.0;

> I changed this to:
>         PA_BLANK_DATE: TDateTime = 0.0;

> This removed all double to TDateTime comparisons in my code.

> So basically, get rid of all the comparisons between double and
> TDateTime! There may be more cases, but I've got other things to
> carry on with.

        I've had strange Invalid FLoating Point Operation errors
that I fixed by always explicitly initializing floats to 0. I have
a _guess_: Certainly not every pattern of SizeOf(double) bytes
represents a valid value. My guess is that Delphi is not even
willing to look at one of the invalid values and report that it's
<> 0.0 - when it sees the bad value it complains.

        What you say seems at least possibly consistent with this
guess - could be Delphi _is_ willing to look at a TDateTime and
compare it to another regardless of whether it contains a valid
value or not.

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Other Threads