POV-Ray : Newsgroups : povray.beta-test : Clock precision wrong? : Re: Clock precision wrong? Server Time
24 Jun 2024 07:44:39 EDT (-0400)
  Re: Clock precision wrong?  
From: Warp
Date: 27 Jun 2011 02:14:45
Message: <4e081fd4@news.povray.org>
Thorsten Froehlich <tho### [at] trfde> wrote:
> Because it is an explanation for non-programmers. Notice how he does *not* 
> say that errors of the addition add up - because there is no addition, it is 
> of course a multiplication.

  A multiplication is the same thing as the series of additions, just done
in one single step. The end result will have the same accumulated rounding
error.

  Although these are mathematically the same, programmatically they are not:

    double timeDelta = (finalClock - initialClock) / totalFrames;
    double currentClock = initialClock + currentFrame * timeDelta;

vs:

    double currentClock = initialClock +
        currentFrame * (finalClock - initialClock) / totalFrames;

  The difference is subtle, but exists. The crucial difference is the
order in which the multiplication and the division are done. The problem
is that with a fixed amount of mantissa bits, the division loses more
information than the multiplication, hence if the division is done first,
it will cause a larger rounding error than if the multiplication is done
first. (Basically doing the division first and then the multiplication is
the same thing as iteratively adding the delta value as many times as the
current amount of frames, with the ensuing accumulated rounding error.)

  This is also the reason why compilers won't make that kind of optimization
(eg. taking a division out of a loop), because the results may be different
(unless you specifically allow for such optimizations in some compilers).

  And please don't read more to this post than there is. I know that many
programmers detest their work being criticized, but that's not what I'm
doing here (and in fact I haven't even checked how exactly is it that
povray is doing this). I'm just chatting. This might be interesting
information to someone.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.