“Why do arrays start at 0?"
https://buttondown.email/hillelwayne/archive/why-do-arrays-start-at-0/
"It's not the reason you think. No, it's not that reason either.”
My Fortran starts at one. My C++ starts at zero. This has made my
life hell.
“Why do arrays start at 0?"
https://buttondown.email/hillelwayne/archive/why-do-arrays-start-at-0/
"It's not the reason you think. No, it's not that reason either.”
My Fortran starts at one. My C++ starts at zero. This has made my life hell.
On Saturday, August 27, 2022 at 1:48:15 AM UTC-7, fiz...@gmail.com wrote:
On Saturday, August 27, 2022 at 5:31:37 AM UTC+2, Robin Vowels wrote:
On Saturday, August 27, 2022 at 6:49:55 AM UTC+10, Lynn McGuire wrote:Nope. Just as the linked article mentions, in Mathematics, starting an index >> from 0 or 1 are both often used, e.g., for elements of sequences and series, >> 0 seems to be most often used, for vector and matrix indices, 1.
FORTRAN followed centuries-old mathematical convention.
Yes, so array indexing is 1. Series sums start at zero, but are not indexed.
If a convergence of a sequence is considered, you often don't care about >>"early" elements, so, if that yields a simple formula, you start from any
number convenient.
Now for this case, you want a DO loop to start at zero, which Fortran 66 didn't allow.
On Saturday, August 27, 2022 at 2:30:15 AM UTC-7, Thomas Koenig wrote:
(snip)
Now for this case, you want a DO loop to start at zero, which Fortran 66 >> > didn't allow.
Really? You mean that
DO 10 I=0,1
would not be allowed?
Yes, not allowed.
On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, Thomas Koenig wrote:
gah4 <ga...@u.washington.edu> schrieb:(snip)
On Saturday, August 27, 2022 at 2:30:15 AM UTC-7, Thomas Koenig wrote:
Really? You mean that
DO 10 I=0,1
would not be allowed?
Yes, not allowed.
I have the Fortran 66 standard before me, and I find no such
restriction in 7.1.2.8 (nor would it make sense at all).
Which part of the standard are you referring to?
Yes 7.1.2.8.
"At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."
On 8/28/2022 12:26 AM, gah4 wrote:
On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, Thomas Koenig wrote:
gah4 <ga...@u.washington.edu> schrieb:(snip)
On Saturday, August 27, 2022 at 2:30:15 AM UTC-7, Thomas Koenig wrote:
Really? You mean that
DO 10 I=0,1
would not be allowed?
Yes, not allowed.
I have the Fortran 66 standard before me, and I find no such
restriction in 7.1.2.8 (nor would it make sense at all).
Which part of the standard are you referring to?
Yes 7.1.2.8.
"At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."
What ? Our code has negative indexes dating back to F66 days. I am
assuming that this is:
DO 10 I = ncp, 1, -1
On 8/28/22 9:28 AM, Charlie Roberts wrote:
[...]
The authors of "Numerical Recipes" started out with F77 and so all the
code in their first book has arrays starting at 1. When they brought
out the C version, they resorted to just this trick!
If I remember correctly, the code in the chapters was written in Pascal,
and there was an appendix that had fortran code. Or maybe it was the
other way around?
I don't remember what version of fortran they used, bu
the book was published before there were any f77 compilers available,
so
I'm guessing that it was f66+extensions. Then they wrote the f77 version
a year or two later.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 159 |
Nodes: | 16 (0 / 16) |
Uptime: | 98:35:57 |
Calls: | 3,209 |
Files: | 10,563 |
Messages: | 3,009,579 |