POV-Ray : Newsgroups : povray.general : Why does POV always evaluate both expressions with a '&'? : Re: Why does POV always evaluate both expressions with a '&'? Server Time
7 Aug 2024 17:23:25 EDT (-0400)
  Re: Why does POV always evaluate both expressions with a '&'?  
From: Micha Riser
Date: 27 Sep 2001 17:05:03
Message: <m340p9.6q5.ln@micha.riser>
Thorsten Froehlich wrote:

> In article <3bb37e54$1@news.povray.org> , "Thorsten Froehlich"
> <tho### [at] trfde> wrote:
> 
>> By using the original search direction and a third variable it might well
>> be that there is a more efficient solution so parsing is faster if the
>> above is done on huge arrays with only a very few zeros.
> 
> Actually, the code below should work (didn't bother to test it) and be
> much faster in most cases.
> 
> #macro findzero(a, n)
>  #local i = 0;
>  #while(i <= n)
>   #if(a[i] != 0)
>    #declare n = i;
>   #end
>   #declare i = i + 1;
>  #end
> #end

Nice idea to traverse the array from the end.. but as you already noticed 
it is less efficient. But you two variables all the same.. with my example 
'n' has been a constant and the result was returned in the only changed 
variable 'i'. And I still think that the variant with usage of 
short-circuit evaluation is nicer... it is shorter, more efficient, and if 
somebody looks at it he/she instantly sees what it does.

Where I got to this problem was some problem of sorting a special array 
with many same values and a special pre-order. It was only thought as an 
example why I prefered short-circ eval.

That still leaves the question open if other people are unhappy as well 
with the current evaulation type.

- Micha


Post a reply to this message

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