Re: Why does this occasionally fail?




"gandalf" <gandalf@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3lhiqkF11fm6lU1@xxxxxxxxxxxxxxxxx
> Hi,
>
> I'm using Delphi 2005 (Update 3) and am struggling over something simple.
> And that is; why does the following statement function properly for a
> while and then suddenly function incorrectly and continue to function
> incorrectly until I rewrite it - and even then maybe not work any more?
>
> if StrToFloat(Edit2.Text)>Temp then
> whatever code
>
> Temp is of type : Real
>
> when, say, Edit2.Text is '3.05' and Temp is 3.05 it will evaluate as
> though Edit2 > Temp, which it isn't. (the 3.05 is not a relevant number,
> any number will do) Yet it will run quite correctly for ages and then fail
> and continue to fail whatever the values. I run the debugger and check the
> values and sure enough they are the same but it still executes the
> 'whatever code'.

Computers store an approximation of a real number, not an exact
value. This is a necessity. There are an infinite number of real
numbers. An infinite number cannot be accurately stored in a finite
space. Because of this comparing real numbers is problematic.

If you only need two decimal places, you could multiply the input
value be 100, truncate the result and compare to the integer 305.

--
Charles Appel
"A generation which ignores history has no past - and no future."
Robert Anson Heinlein



.



Relevant Pages

  • Re: Attempt to Refute the Halting Problems Refutation
    ... but I can certainly show you how any halt analyzer ... the same way that LoopIfHalts1 used WillHalt1. ... and WillHalt1 will fail on ALL of the inputs ... solve the halting problem) will fail on an infinite set of inputs. ...
    (comp.theory)
  • Re: Attempt to Refute the Halting Problems Refutation
    ... but I can certainly show you how any halt analyzer ... the same way that LoopIfHalts1 used WillHalt1. ... and WillHalt1 will fail on ALL of the inputs ... solve the halting problem) will fail on an infinite set of inputs. ...
    (sci.logic)
  • Re: Poor Noah and tree ring dating
    ... All finite series fail to diverge. ... You specified that the switch could stand the strain, ... Didn't I mention it was an LED bulb? ... that could turn on and off an infinite number of times with no problems. ...
    (talk.origins)
  • Re: Orlow cardinality question
    ... I did not fail calculus. ... The set is infinite. ... difference between any two successive members. ... Picute your naturals on the number line, ...
    (sci.math)
  • Re: Central Limit Theorem?
    ... I know you know what "infinite" means. ... >>>No, the distribution result CANNOT be exact, when some of the ... > That's the difference, Herman. ... > Show us how you would generate that discrete distribution EXACTLY, ...
    (sci.stat.math)