D,

Thankyou..... That has appeared to do the trick!!!!

-- D

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of David Brennan
Sent: Thursday, 3 May 2001 14:03
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Real Number Strangeness....

>
> Gives 636 as expected. Then it starts getting confusing:
>
> Frac(AOverNotation) gives 0.2 (As expected)
> Frac(AOverNotation) * 10 gives 2 (As expected)
> Trunc(Frac(AOverNotation) * 10) gives 1 !!!!! Why is that?
>
> Can someone point me in the right direction here please?

Ah, the joys of floating point arithmetic. I think you will find that
Frac(AOverNotation) * 10 isn't actually giving 2. It will be returning
1.999999999784 for example. Your Trunc call then correctly notices that this
value is less than 2 and returns 1.

There are probably many ways you could solve this problem. One of the
simplest is to replace Trunc(Frac(AOverNotation) * 10)  with
Trunc(Frac(AOverNotation) * 10 + 0.000001). If your variables are
sufficiently high precision (double's work well) then this should be
sufficient to give you the correct result without any errors resulting from
adding the small offset of 0.000001).

David.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to