POV-Ray : Newsgroups : povray.advanced-users : Stepped loop values and mod() : Re: Stepped loop values and mod() Server Time
13 Jun 2024 18:48:02 EDT (-0400)
  Re: Stepped loop values and mod()  
From: Alain
Date: 3 Aug 2018 10:54:11
Message: <5b646c93$1@news.povray.org>
Le 18-08-03 à 08:33, Bald Eagle a écrit :
> clipka <ano### [at] anonymousorg> wrote:
> 
> 
>> In the binary system typically used in computers, this imples that the
>> problem arises whenever M is not a power of 2.
> 
> So, POV-Ray reinforces the patriarchal stranglehold that the Old Boy's Club  has
> on implementing a non-binary system, eh?
> 
>> Note that 0.1 represents a /decimal fraction/, namely 1/10. Since 10 has
>> 5 as one of its prime factors, which isn't a power of 2, the problem
>> applies here.
> 
> 
> I thought it was something like that - just wanted to be sure.
> 
> 
>> In for loops, the problem can be avoided altogether by always using an
>> integer loop variable, and from that "technical" loop variable compute
>> an "effective" loop variable via multiplication or division, e.g.:
>>
>>      #for (I, 0, 1000, 1)
>>          #local T = I * 0.1;
>>          ....
>>      #end
> 
> Well, this is interesting:
> (a) it works - thanks!  :)
> 
> (b) my #debug output still shows a "remainder" in the 14th or 15th decimal place
> - is that just an artifact showing up _after_ mod() is made happy?
> 
> 
> 
An error at the 14+th decimal place can be expected due to the limits of 
the FP processor. It only have a finite mantissa length.
You'd need a triple or quadruple precision capable floating point unit.


Post a reply to this message

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