|
![](/i/fill.gif) |
In article <3901AA4C.28062CFA@peak.edu.ee> , Margus Ramst
<mar### [at] peak edu ee> wrote:
> Yes, those conditions should be equivalent.
The are equivalent mathematically, but not in terms of floating-point
arithmetic.
> It seems to be a precision-related issue, since the correct result is achieved
> by adding some very small value to D in the condition (X <= D). Also, when the
> loop is shorter, e.g. D=1, the result is correct for X = X + 0.1
> The second version works because for some reason the condition (X = D)
> evaluates correctly. However, the conditions like (X != D) (X <= D) etc do
> not. I tested this under official 3.1g (Windows & Linux) and Megapov 0.4g
> (Windows) and due to the inconsistency regarding conditional operators, it
> looks like a bug to me. Comments?
Technically it is not a bug but a limit in floating-point precision. The
reason why the first one works is rather simple: POV-Ray already contains a
workaround for "is equal" comparisons as well as "is not equal" ones, but
not for smaller/greater (or equal) than ones. In reality POV-Ray fixes the
problem for the equal and not equal cases with this method:
condition: f1 = f2
POV-Ray: if (fabs(f1 - f2) > EPSILON) then false else true
condition: f1 != f2
POV-Ray: if (fabs(f1 - f2) > EPSILON) then true else false
The other comparison operators do not take EPSILON into account. So
practically POV-Ray should contain a workaround for these cases as well.
However, you can also do something like #while (X <= D+0.0001) and it will
work.
Further, the documentation should make clear that floating-point math is
_not_ precise. Especially in long operations the error will build up: There
are some more exact specs for this, but you can safely assume about one
digit per operation. Thus, the example above will accumulate a reasonable
error after its twenty iterations.
Thorsten
____________________________________________________
Thorsten Froehlich
e-mail: mac### [at] povray org
I am a member of the POV-Ray Team.
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
![](/i/fill.gif) |