POV-Ray : Newsgroups : povray.bugreports : Unexpected select () results in both 3 and 4 arguments versions Server Time
24 May 2024 12:16:47 EDT (-0400)
  Unexpected select () results in both 3 and 4 arguments versions (Message 1 to 5 of 5)  
From: Bald Eagle
Subject: Unexpected select () results in both 3 and 4 arguments versions
Date: 8 Nov 2023 18:40:00
Message: <web.654c1b56f53b6bed1f9dae3025979125@news.povray.org>
So, I did some more testing, wrote a simple, standalone sample scene, and found
yet another curious set of circumstances.

And it looks like probably what's happening is another case of floating point
math error, similar to what I experienced way back when trying to use fractional
loop iterators.

Sometimes the 4-value version works (as expected), and sometimes it doesn't.

Always a headache, with the simplest things.

- BW



#version 3.8;
global_settings {assumed_gamma 1}
default {finish {diffuse 1}}


#declare E = 0.001;

#declare Zoom = 700;
camera {
 orthographic
 location <0.5, 0.5, -50>
 right x*image_width/Zoom
 up y*image_height/Zoom
 look_at <0.5, 0.5, 0>
 rotate y*0
}

sky_sphere {pigment {rgb 0}}

light_source {<1, 1, -10> rgb 1}

#declare LW = 0.01;
#declare f_XLines = function {pigment {gradient y scale 0.1}}
#declare XLines = function {select (f_XLines (x, y, z).red-LW, 1, 0)}
#declare f_YLines = function {pigment {gradient x scale 0.1}}
#declare YLines = function {select (f_YLines (x, y, z).red-LW, 1, 0)}
#declare Grid = function {XLines (x, y, z) + YLines (x, y, z)}

box {0, 1+E pigment {function {Grid (x, y, z)}} }



#declare Select3 = function (N) {
 select (N*10-2, 0.1,
  select (N*10-5, 0.4,
   select (N*10-7, 0.6,
    0.9
   )
  )
 )
}

// In this version, when N-Val = 0 --- when N=Val,
// then the repeated value, argument B, should get returned.
#declare Select4 = function (N) {
 select (N-0.2, 0.1, 0.1,
  select (N-0.5, 0.4, 0.4,
   select (N-0.7, 0.6, 0.6,
    0.9
   )
  )
 )
}

#declare Line = 0.0015;

#declare Step = 0.05;
union {
  #for (X, 0, 1, Step)

   #local Y = Select3 (X);

   #debug concat( "X = ", str(X, 0, 3),  " Y = ", str(Y, 0, 3), "\n")

   #local Current = <X, Y, 0>;
   sphere {Current Line}
   #if (X > 0)
    cylinder {Last, Current, Line}
   #end
   #local Last = Current;
  #end

 pigment {rgb x}
}

#debug "\n===========================================\n"

union {
  #for (X, 0, 1, Step)

   #local Y = Select4 (X);

   #debug concat( "X = ", str(X, 0, 3),  " Y = ", str(Y, 0, 3), "\n")

   #local Current = <X, Y, 0>;
   sphere {Current Line}
   #if (X > 0)
    cylinder {Last, Current, Line}
   #end
   #local Last = Current;
  #end

 pigment {rgb z}
}


Post a reply to this message


Attachments:
Download 'selecttest.png' (28 KB)

Preview of image 'selecttest.png'
selecttest.png


 

From: Tor Olav Kristensen
Subject: Re: Unexpected select () results in both 3 and 4 arguments versions
Date: 29 Dec 2023 20:35:00
Message: <web.658f734c5832731ec342de0989db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I did some more testing, wrote a simple, standalone sample scene, and found
> yet another curious set of circumstances.
>
> And it looks like probably what's happening is another case of floating point
> math error, similar to what I experienced way back when trying to use fractional
> loop iterators.
>...

But, but, but - you are using a "fractional loop iterator" also here.
You are incrementing by a number; 0.05 = 5/100, that's not possible to write
as a binary number with a finite length.

0.05 =
0*10^0+0*10^-1+5*10^-2 =
0*2^0+0*2^-1+0*2^-2+0*2^-3+0*2^-4+1*2^-5+1*2^-6*+0*2^-7+0*2^-8+1*2^-9+1*2^-10+...

Try to use this step length instead:

#declare Step = 0.0498046875; // = 1/2^-5 + 2^-6 + 2^-9 + 2^-10

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Unexpected select () results in both 3 and 4 arguments versions
Date: 29 Dec 2023 21:10:00
Message: <web.658f7af15832731ec342de0989db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > So, I did some more testing, wrote a simple, standalone sample scene, and found
> > yet another curious set of circumstances.
> >
> > And it looks like probably what's happening is another case of floating point
> > math error, similar to what I experienced way back when trying to use fractional
> > loop iterators.
> >...
>
> But, but, but - you are using a "fractional loop iterator" also here.
> You are incrementing by a number; 0.05 = 5/100, that's not possible to write
> as a binary number with a finite length.
>
> 0.05 =
> 0*10^0+0*10^-1+5*10^-2 =
> 0*2^0+0*2^-1+0*2^-2+0*2^-3+0*2^-4+1*2^-5+1*2^-6*+0*2^-7+0*2^-8+1*2^-9+1*2^-10+...
>
> Try to use this step length instead:
>
> #declare Step = 0.0498046875; // = 1/2^-5 + 2^-6 + 2^-9 + 2^-10


Sorry. I meant to write this:

//  = 2^-5 + 2^-6 + 2^-9 + 2^-10


--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Bald Eagle
Subject: Re: Unexpected select () results in both 3 and 4 arguments versions
Date: 29 Dec 2023 22:10:00
Message: <web.658f89405832731e1f9dae3025979125@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

> But, but, but - you are using a "fractional loop iterator" also here.

UGGGGGGGGGGGGGGGGGGGGgggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhh.

And I was just explaining floating point woes to the stepson the other day.

I think I need a plaque on my monitor that reads:

"THOU SHALT NOT USE FRACTIONS"

:(

I'll just multiply everything by 1/Step and hopefully that will get everything
to work out.  What a PITA.

Thanks, Tor.


- BW


Post a reply to this message

From: Cousin Ricky
Subject: Re: Unexpected select () results in both 3 and 4 arguments versions
Date: 30 Dec 2023 14:08:22
Message: <65906aa6$1@news.povray.org>
On 2023-12/29 23:06 (-4), Bald Eagle wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> 
>> But, but, but - you are using a "fractional loop iterator" also here.
> 
> UGGGGGGGGGGGGGGGGGGGGgggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhh.
> 
> And I was just explaining floating point woes to the stepson the other day.
> 
> I think I need a plaque on my monitor that reads:
> 
> "THOU SHALT NOT USE FRACTIONS"
> 
> :(
> 
> I'll just multiply everything by 1/Step and hopefully that will get everything
> to work out.  What a PITA.

I see these FP glitches often enough that I will always endure that
PITA.  See for example macro ILight__Integrate() in:

https://github.com/CousinRicky/POV-IntegrateLight/blob/main/integratelight.inc

I view it as just a part of the game, like tuning a guitar, or
collimating a reflector telescope, or using my turn signal.


Post a reply to this message

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