POV-Ray : Newsgroups : povray.general : Arrays: integer in subscript? Server Time
20 Nov 2024 12:32:22 EST (-0500)
  Arrays: integer in subscript? (Message 1 to 8 of 8)  
From: Greg M  Johnson
Subject: Arrays: integer in subscript?
Date: 15 Aug 2001 22:12:35
Message: <3b7b2c13$1@news.povray.org>
What is allowed in the subscript of an array?  I often do math and then
put some things into the array.  What is allowed?

MyArray[3.1][n/2][int(n*3.1)]    etc......


Post a reply to this message

From: Bob H 
Subject: Re: Arrays: integer in subscript?
Date: 15 Aug 2001 22:40:11
Message: <3b7b328b@news.povray.org>
They will become whole number positive integers 1 to N, at least from what I
understand.  I was just looking into them once again and realized they are
initialized as 1 to N yet are accessed as 0 to N-1.  I thought I recalled a
discussion about that before and whether it should be changed.  Not sure.

Bob H.

"Greg M. Johnson" <"gregj;-)56590\""@aol.c;-)om> wrote in message
news:3b7b2c13$1@news.povray.org...
> What is allowed in the subscript of an array?  I often do math and then
> put some things into the array.  What is allowed?
>
> MyArray[3.1][n/2][int(n*3.1)]    etc......
>


Post a reply to this message

From: Ron Parker
Subject: Re: Arrays: integer in subscript?
Date: 15 Aug 2001 22:43:50
Message: <slrn9nmcr9.c0t.ron.parker@fwi.com>
On Wed, 15 Aug 2001 21:40:14 -0500, Bob H. wrote:
>They will become whole number positive integers 1 to N, at least from what I
>understand.  I was just looking into them once again and realized they are
>initialized as 1 to N yet are accessed as 0 to N-1.  I thought I recalled a
>discussion about that before and whether it should be changed.  Not sure.

I don't recall seeing any subscripts in the initializer.  What do you mean
by "initialized as 1 to N"?

-- 
#local R=<7084844682857967,0787982,826975826580>;#macro L(P)concat(#while(P)chr(
mod(P,100)),#local P=P/100;#end"")#end background{rgb 1}text{ttf L(R.x)L(R.y)0,0
translate<-.8,0,-1>}text{ttf L(R.x)L(R.z)0,0translate<-1.6,-.75,-1>}sphere{z/9e3
4/26/2001finish{reflection 1}}//ron.parker@povray.org My opinions, nobody else's


Post a reply to this message

From: Ron Parker
Subject: Re: Arrays: integer in subscript?
Date: 15 Aug 2001 22:57:34
Message: <slrn9nmdl2.c0t.ron.parker@fwi.com>
On Wed, 15 Aug 2001 22:13:39 -0400, Greg M. Johnson wrote:
>What is allowed in the subscript of an array?  I often do math and then
>put some things into the array.  What is allowed?
>
>MyArray[3.1][n/2][int(n*3.1)]    etc......

Anything that evaluates as a float.  That is, any expression that's not 
a vector or a colour.

The value is rounded down before use, except when it's with 1e-8 of the
next higher integer, in which case it's rounded up (this accounts for 
rounding error in the calculation.)  Negative subscripts are not allowed.

There's a bug that keeps you from using -.000000000001 as a subscript, 
too, even though it should be rounded to zero.  That'll be fixed in 3.5.

-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end 
Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}


Post a reply to this message

From: Bob H 
Subject: Re: Arrays: integer in subscript?
Date: 15 Aug 2001 23:11:43
Message: <3b7b39ef@news.povray.org>
"Ron Parker" <ron### [at] povrayorg> wrote in message
news:slr### [at] fwicom...
> On Wed, 15 Aug 2001 21:40:14 -0500, Bob H. wrote:
> >They will become whole number positive integers 1 to N, at least from
what I
> >understand.  I was just looking into them once again and realized they
are
> >initialized as 1 to N yet are accessed as 0 to N-1.  I thought I recalled
a
> >discussion about that before and whether it should be changed.  Not sure.
>
> I don't recall seeing any subscripts in the initializer.  What do you mean
> by "initialized as 1 to N"?

Sorry, I don't know the terminology at all but I meant array[subscript]
where subscript is initialized using 1 to N and then becomes 0 to N-1 when
later accessed.
Or do I have that all wrong?

Bob H.


Post a reply to this message

From: Ron Parker
Subject: Re: Arrays: integer in subscript?
Date: 15 Aug 2001 23:16:51
Message: <slrn9nmep6.c2d.ron.parker@fwi.com>
On Wed, 15 Aug 2001 22:13:21 -0500, Bob H. wrote:
>"Ron Parker" <ron### [at] povrayorg> wrote in message
>news:slr### [at] fwicom...
>> On Wed, 15 Aug 2001 21:40:14 -0500, Bob H. wrote:
>> >They will become whole number positive integers 1 to N, at least from
>what I
>> >understand.  I was just looking into them once again and realized they
>are
>> >initialized as 1 to N yet are accessed as 0 to N-1.  I thought I recalled
>a
>> >discussion about that before and whether it should be changed.  Not sure.
>>
>> I don't recall seeing any subscripts in the initializer.  What do you mean
>> by "initialized as 1 to N"?
>
>Sorry, I don't know the terminology at all but I meant array[subscript]
>where subscript is initialized using 1 to N and then becomes 0 to N-1 when
>later accessed.
>Or do I have that all wrong?

I think you do.  When you initialize it, you say

#declare foo=array[size] {...}

Notice that that thing there is the size, not the last index, so it's not 
actually a contradiction.

Zero-based arrays are something that most programmers would be familiar 
with.  I think the assumption was that anyone using arrays probably either
has experience in another language or soon will, so they were kept zero-based
for the familiarity factor.  I can think of only a few obsolete dialects of
BASIC that use 1-based arrays.

-- 
#local R=<7084844682857967,0787982,826975826580>;#macro L(P)concat(#while(P)chr(
mod(P,100)),#local P=P/100;#end"")#end background{rgb 1}text{ttf L(R.x)L(R.y)0,0
translate<-.8,0,-1>}text{ttf L(R.x)L(R.z)0,0translate<-1.6,-.75,-1>}sphere{z/9e3
4/26/2001finish{reflection 1}}//ron.parker@povray.org My opinions, nobody else's


Post a reply to this message

From: Tom Melly
Subject: Re: Arrays: integer in subscript?
Date: 16 Aug 2001 04:44:11
Message: <3b7b87db$1@news.povray.org>
"Ron Parker" <ron### [at] povrayorg> wrote in message
news:slr### [at] fwicom...
>
> Zero-based arrays are something that most programmers would be familiar
> with.  I think the assumption was that anyone using arrays probably either
> has experience in another language or soon will, so they were kept zero-based
> for the familiarity factor.  I can think of only a few obsolete dialects of
> BASIC that use 1-based arrays.
>

Heh - the built in scripting in lang. in the db our company sells uses 1-based
arrays. I'm always coming a cropper when I switch to other langs.


Post a reply to this message

From: David Fontaine
Subject: Re: Arrays: integer in subscript?
Date: 18 Aug 2001 01:28:54
Message: <3B7DFADC.60F5397F@faricy.net>
Ron Parker wrote:
> Zero-based arrays are something that most programmers would be familiar
> with.  I think the assumption was that anyone using arrays probably either
> has experience in another language or soon will, so they were kept zero-based
> for the familiarity factor.  I can think of only a few obsolete dialects of
> BASIC that use 1-based arrays.

Hehe, like the BASIC on TI calcs.  Gets annoying...

-- 
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

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